JMorfeuszTest.java
2.91 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
import java.util.NoSuchElementException;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import pl.waw.ipipan.morfeusz.Morfeusz;
import pl.waw.ipipan.morfeusz.MorfeuszUsage;
import pl.waw.ipipan.morfeusz.MorfeuszException;
import pl.waw.ipipan.morfeusz.MorphInterpretation;
import pl.waw.ipipan.morfeusz.ResultsIterator;
/**
*
* @author mlenart
*/
public class JMorfeuszTest {
private Morfeusz morfeusz;
public JMorfeuszTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
morfeusz = Morfeusz.createInstance(MorfeuszUsage.BOTH_ANALYSE_AND_GENERATE);
}
@After
public void tearDown() {
}
@Test
public void testAnalyzeAsList() {
List<MorphInterpretation> res = morfeusz.analyseAsList("Aaaa żżżż");
assertEquals(2, res.size());
assertEquals("Aaaa", res.get(0).getOrth());
assertEquals("żżżż", res.get(1).getOrth());
try {
res.get(2);
fail();
} catch (IndexOutOfBoundsException ex) {
}
}
@Test
public void testAnalyzeAsIterator() {
ResultsIterator it = morfeusz.analyseAsIterator("Aaaa żżżż");
assertTrue(it.hasNext());
assertEquals("Aaaa", it.next().getOrth());
assertTrue(it.hasNext());
assertEquals("żżżż", it.next().getOrth());
try {
it.next();
fail();
} catch (NoSuchElementException ex) {
}
}
@Test(expected = MorfeuszException.class)
public void testInvalidAgglOption() {
morfeusz.setAggl("XXXXYYYYZZZZ");
}
@Test(expected = MorfeuszException.class)
public void testInvalidPraetOption() {
morfeusz.setPraet("XXXXYYYYZZZZ");
}
@Test(expected = MorfeuszException.class)
public void testInvalidGenerate() {
morfeusz.generate("AAAA BBBB");
}
@Test(expected = NullPointerException.class)
public void testNullCaseHandling() {
morfeusz.setCaseHandling(null);
}
@Test(expected = MorfeuszException.class)
public void testNonExistingDictionary() throws IOException {
morfeusz.setDictionary("ee2rmtsq");
}
@Test(expected = IOException.class)
public void testInvalidDictionary() throws Exception {
String dictName = "6J1vMiqY";
File tmpFile = new File(dictName + "-a.dict");
assertTrue(tmpFile.createNewFile());
tmpFile.deleteOnExit();
try (PrintStream out = new PrintStream(tmpFile)) {
out.print("IzEne9FXuc");
}
morfeusz.getDictionarySearchPaths().add(0, ".");
morfeusz.setDictionary(dictName);
}
}