Debian Codegraph @

morfologik-fsa-builders/src/test/java/morfologik/fsa/builders/FSABuilderTest.java

raw
1 package morfologik.fsa.builders;
2
3 import static morfologik.fsa.builders.FSATestUtils.*;
4 import static org.junit.Assert.assertEquals;
5
6 import java.io.IOException;
7 import java.util.Arrays;
8
9 import morfologik.fsa.FSA;
10
11 import org.junit.BeforeClass;
12 import org.junit.Test;
13
14 public class FSABuilderTest extends TestBase {
15 private static byte[][] input;
16 private static byte[][] input2;
17
18 @BeforeClass
19 public static void prepareByteInput() {
20 input = generateRandom(25000, new MinMax(1, 20), new MinMax(0, 255));
21 input2 = generateRandom(40, new MinMax(1, 20), new MinMax(0, 3));
22 }
23
24 @Test
25 public void testEmptyInput() {
26 byte[][] input = {};
27 checkCorrect(input, FSABuilder.build(input));
28 }
29
30 @Test
31 public void testHashResizeBug() throws Exception {
32 byte[][] input = { { 0, 1 }, { 0, 2 }, { 1, 1 }, { 2, 1 }, };
33
34 FSA fsa = FSABuilder.build(input);
35 checkCorrect(input, FSABuilder.build(input));
36 checkMinimal(fsa);
37 }
38
39 @Test
40 public void testSmallInput() throws Exception {
41 byte[][] input = { "abc".getBytes("UTF-8"), "bbc".getBytes("UTF-8"), "d".getBytes("UTF-8"), };
42 checkCorrect(input, FSABuilder.build(input));
43 }
44
45 @Test
46 public void testLexicographicOrder() throws IOException {
47 byte[][] input = { { 0 }, { 1 }, { (byte) 0xff }, };
48 Arrays.sort(input, FSABuilder.LEXICAL_ORDERING);
49
50 // Check if lexical ordering is consistent with absolute byte value.
51 assertEquals(0, input[0][0]);
52 assertEquals(1, input[1][0]);
53 assertEquals((byte) 0xff, input[2][0]);
54
55 final FSA fsa;
56 checkCorrect(input, fsa = FSABuilder.build(input));
57
58 int arc = fsa.getFirstArc(fsa.getRootNode());
59 assertEquals(0, fsa.getArcLabel(arc));
60 arc = fsa.getNextArc(arc);
61 assertEquals(1, fsa.getArcLabel(arc));
62 arc = fsa.getNextArc(arc);
63 assertEquals((byte) 0xff, fsa.getArcLabel(arc));
64 }
65
66 @Test
67 public void testRandom25000_largerAlphabet() {
68 FSA fsa = FSABuilder.build(input);
69 checkCorrect(input, fsa);
70 checkMinimal(fsa);
71 }
72
73 @Test
74 public void testRandom25000_smallAlphabet() throws IOException {
75 FSA fsa = FSABuilder.build(input2);
76 checkCorrect(input2, fsa);
77 checkMinimal(fsa);
78 }
79 }