Skip to content

Commit 6856a3f

Browse files
Simon FlachsSimon Flachs
authored andcommitted
finished testing similar words
1 parent 27054f9 commit 6856a3f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/main/java/Setup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static LinkedHashMap getInstance() {
8181
* Adds the word as the key and the url as the value of the hashmap. Checks for duplicates inside each UrlList and only appends
8282
* new urls to the end.
8383
*/
84-
private static void addEntryToHashMap(LinkedHashMap hashMap, String word, String url) {
84+
protected static void addEntryToHashMap(LinkedHashMap hashMap, String word, String url) {
8585

8686
HashSet<String> urlHashMap = (HashSet) hashMap.get(word);
8787

tests/SimilarWordsTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
import org.junit.Test;
22

33
import java.lang.reflect.Method;
4+
import java.util.HashMap;
5+
import java.util.HashSet;
6+
import java.util.LinkedHashMap;
47

58
import static org.junit.Assert.*;
69

7-
/**
8-
* Created by Simon on 07/12/15.
9-
*/
1010
public class SimilarWordsTest {
1111

1212
@Test
13-
public void test_that_retrieves_words_with_distance_one() throws Exception {
14-
13+
public void it_retrieves_words_with_distance_one() throws Exception {
14+
LinkedHashMap<String, HashSet> hashMap = new LinkedHashMap<String, HashSet>();
15+
Setup.addEntryToHashMap(hashMap, "wordX", "testUrl");
16+
HashSet<String> similarWords = SimilarWords.retrieveSimilarWords(hashMap, "word");
17+
assertTrue(similarWords.contains("wordX"));
1518
}
1619

1720
@Test
18-
public void test_that_if_no__words_with_distance_one_it_retrieves_with_distance_two() throws Exception {
19-
21+
public void it_retrieves_words_with_distance_two_if_no_words_with_distance_one() throws Exception {
22+
LinkedHashMap<String, HashSet> hashMap = new LinkedHashMap<String, HashSet>();
23+
Setup.addEntryToHashMap(hashMap, "wordXX", "testUrl");
24+
HashSet<String> similarWords = SimilarWords.retrieveSimilarWords(hashMap, "word");
25+
assertTrue(similarWords.contains("wordXX"));
2026
}
2127

2228
@Test
2329
public void test_distance_algorithm() throws Exception {
2430
// two words that can be made identical by changing one letter will have a distance of 1
2531
assertTrue(SimilarWords.distance("testX", "testY") == 1);
26-
// two words that can be made identical by adding or removing one letter will have a distance of 1
32+
// two words that can be made identical by adding or removing one letter will have a distance of 1
2733
assertTrue(SimilarWords.distance("testX", "test") == 1);
2834
}
29-
30-
31-
32-
3335
}

0 commit comments

Comments
 (0)