-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrefixCodeTableTest.java
More file actions
42 lines (35 loc) · 1.38 KB
/
PrefixCodeTableTest.java
File metadata and controls
42 lines (35 loc) · 1.38 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
42
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class PrefixCodeTableTest {
@Test
public void oneCharacterTest() {
FrequencyTable ft = new FrequencyTable("a");
HuffmanBinaryTree hbt = new HuffmanBinaryTree(ft);
PrefixCodeTable pct = new PrefixCodeTable(hbt);
assertThrows(IllegalArgumentException.class,
() -> pct.getCode(' '));
assertEquals("0", pct.getCode('a'));
}
@Test
public void twoCharacterTest() {
FrequencyTable ft = new FrequencyTable("AbAbb");
HuffmanBinaryTree hbt = new HuffmanBinaryTree(ft);
PrefixCodeTable pct = new PrefixCodeTable(hbt);
assertThrows(IllegalArgumentException.class,
() -> pct.getCode('a'));
assertEquals("0", pct.getCode('A'));
assertEquals("1", pct.getCode('b'));
}
@Test
public void manyCharacterTest() {
FrequencyTable ft = new FrequencyTable("dCACbdbCdd");
HuffmanBinaryTree hbt = new HuffmanBinaryTree(ft);
PrefixCodeTable pct = new PrefixCodeTable(hbt);
assertThrows(IllegalArgumentException.class,
() -> pct.getCode('\"'));
assertEquals("0", pct.getCode('d'));
assertEquals("110", pct.getCode('A'));
assertEquals("111", pct.getCode('b'));
assertEquals("10", pct.getCode('C'));
}
}