11import org .junit .Test ;
22
33import java .lang .reflect .Method ;
4+ import java .util .HashMap ;
5+ import java .util .HashSet ;
6+ import java .util .LinkedHashMap ;
47
58import static org .junit .Assert .*;
69
7- /**
8- * Created by Simon on 07/12/15.
9- */
1010public 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