-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDictionaryTest.java
73 lines (58 loc) · 3.22 KB
/
DictionaryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import org.junit.Test;
import org.junit.runners.JUnit4;
import static org.junit.Assert.assertEquals;
public class DictionaryTest {
@Test
public void testCustom() {
System.out.println("Testing");
// assertEquals("a", Dictionary.replaceChar("b", 0, 'a'));
// assertEquals("bbcd", Dictionary.replaceChar("abcd", 0, 'b'));
// assertEquals("abbd", Dictionary.replaceChar("abcd", 2, 'b'));
assertEquals(0, Dictionary.editDistanceBU("", ""));
assertEquals(0, Dictionary.editDistanceBU("a", "a"));
assertEquals(0, Dictionary.editDistanceBU("abcd", "abcd"));
assertEquals(1, Dictionary.editDistanceBU("a", "ba"));
assertEquals(1, Dictionary.editDistanceBU("java", "aava"));
assertEquals(1, Dictionary.editDistanceBU("aava", "java"));
assertEquals(2, Dictionary.editDistanceBU("java", "aaaa"));
assertEquals(2, Dictionary.editDistanceBU("aaaa", "java"));
assertEquals(1, Dictionary.editDistanceBU("java", "ajava"));
assertEquals(1, Dictionary.editDistanceBU("ajava", "java"));
assertEquals(1, Dictionary.editDistanceBU("java", "javaa"));
assertEquals(1, Dictionary.editDistanceBU("javaa", "java"));
assertEquals(2, Dictionary.editDistanceBU("java", "ajavaa"));
assertEquals(2, Dictionary.editDistanceBU("ajavaa", "java"));
assertEquals(4, Dictionary.editDistanceBU("java", "heaven"));
assertEquals(6, Dictionary.editDistanceBU("cherry", "strawberry"));
assertEquals(6, Dictionary.editDistanceBU("strawberry", "cherry"));
assertEquals(4, Dictionary.editDistanceBU("scrawherry", "cherry"));
assertEquals(4, Dictionary.editDistanceBU("cherry", "scrawherry"));
assertEquals(4, Dictionary.editDistanceBU("scrawherry", "cherry"));
assertEquals(1, Dictionary.editDistanceBU("strawberry", "strawbery"));
assertEquals(1, Dictionary.editDistanceBU("strawbery", "strawberry"));
// Specifics from the provided tests
assertEquals(7, Dictionary.editDistanceBU("cherry", "strawbery"));
assertEquals(7, Dictionary.editDistanceBU("strawbery", "cherry"));
assertEquals(2, Dictionary.editDistanceBU("cherry", "berry"));
assertEquals(5, Dictionary.editDistanceBU("raspberry", "strawbery"));
assertEquals(5, Dictionary.editDistanceBU("strawbery", "raspberry"));
assertEquals(2, Dictionary.editDistanceBU("cherry", "berry"));
// this is why this alg doesn't work
assertEquals(2, Dictionary.editDistanceBU("61234567890", "12345667890"));
assertEquals(4, Dictionary.editDistanceBU("661234567890", "123456667890"));
assertEquals(2, Dictionary.editDistanceBU("2121333", "1212333"));
assertEquals(4, Dictionary.editDistanceBU("661234567890", "123456667890"));
}
@Test
public void testBerries() {
Dictionary dictionary = new Dictionary(new String[]{"cherry", "pineapple", "melon", "strawberry", "raspberry"});
assertEquals("strawberry", dictionary.findMostSimilar("strawbery"));
assertEquals("cherry", dictionary.findMostSimilar("berry"));
}
@Test
public void testLanguages() {
Dictionary dictionary = new Dictionary(new String[]{"javascript", "java", "ruby", "php", "python", "coffeescript"});
assertEquals("java", dictionary.findMostSimilar("heaven"));
assertEquals("javascript", dictionary.findMostSimilar("javascript"));
}
}