forked from ivanhk/fastText_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestDictionary.java
More file actions
41 lines (33 loc) · 1.05 KB
/
Copy pathTestDictionary.java
File metadata and controls
41 lines (33 loc) · 1.05 KB
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
package fasttext;
import static org.junit.Assert.*;
import java.util.Map;
import org.junit.Test;
public class TestDictionary {
Dictionary dictionary = new Dictionary(new Args());
@Test
public void testHash() {
assertEquals(dictionary.hash(","), 688690635l);
assertEquals(dictionary.hash("is"), 1312329493l);
assertEquals(dictionary.hash("</s>"), 3617362777l);
}
@Test
public void testFind() {
assertEquals(dictionary.find(","), 28690635l);
assertEquals(dictionary.find("is"), 22329493l);
assertEquals(dictionary.find("</s>"), 17362777l);
}
@Test
public void testAdd() {
dictionary.add(",");
dictionary.add("is");
dictionary.add("is");
String w = "";
dictionary.add(w);
dictionary.add(w);
dictionary.add(w);
Map<Long, Integer> word2int = dictionary.getWord2int();
assertEquals(3, dictionary.getWords().get(word2int.get(dictionary.find(w))).count);
assertEquals(2, dictionary.getWords().get(word2int.get(dictionary.find("is"))).count);
assertEquals(1, dictionary.getWords().get(word2int.get(dictionary.find(","))).count);
}
}