Commit 20aa18e35e8188dc33956a6ebb247055ef5847f6
1 parent
5b90d1cb
- dodanie brakującego testu C API
git-svn-id: svn://svn.nlp.ipipan.waw.pl/morfeusz/morfeusz@235 ff4e3ee1-f430-4e82-ade0-24591c43f1fd
Showing
2 changed files
with
206 additions
and
0 deletions
morfeusz/tests/test_c_api.cpp
0 → 100644
1 | +/* | |
2 | + * File: test_c_api.cpp | |
3 | + * Author: lennyn | |
4 | + * | |
5 | + * Created on June 25, 2014, 7:43 PM | |
6 | + */ | |
7 | + | |
8 | +#include <cstdlib> | |
9 | +#include <string> | |
10 | +#include <iostream> | |
11 | +#include "morfeusz2_c.h" | |
12 | +#include "validate.hpp" | |
13 | + | |
14 | +using namespace std; | |
15 | + | |
16 | +void testTwoSimpleInvocations() { | |
17 | + char* text = const_cast<char*>(string("AAaaBBbbCCcc DDDD.").c_str()); | |
18 | + InterpMorf* results = morfeusz_analyse(text); | |
19 | + validateEquals(0, results[0].p); | |
20 | + validateEquals(1, results[0].k); | |
21 | + validateEquals(string("AAaaBBbbCCcc"), string(results[0].forma)); | |
22 | + validateEquals(string("AAaaBBbbCCcc"), string(results[0].haslo)); | |
23 | + validateEquals(string("ign"), string(results[0].interp)); | |
24 | + | |
25 | + validateEquals(1, results[1].p); | |
26 | + validateEquals(2, results[1].k); | |
27 | + validateEquals(string("DDDD"), string(results[1].forma)); | |
28 | + validateEquals(string("DDDD"), string(results[1].haslo)); | |
29 | + validateEquals(string("ign"), string(results[1].interp)); | |
30 | + | |
31 | + validateEquals(2, results[2].p); | |
32 | + validateEquals(3, results[2].k); | |
33 | + validateEquals(string("."), string(results[2].forma)); | |
34 | + validateEquals(string("."), string(results[2].haslo)); | |
35 | +// validateEquals(string("ign"), string(results[2].interp)); | |
36 | + validateEquals(-1, results[3].p); | |
37 | + | |
38 | + char* text1 = const_cast<char*>(string("EEeeFFff").c_str()); | |
39 | + results = morfeusz_analyse(text1); | |
40 | + validateEquals(0, results[0].p); | |
41 | + validateEquals(1, results[0].k); | |
42 | + validateEquals(string("EEeeFFff"), string(results[0].forma)); | |
43 | + validateEquals(string("EEeeFFff"), string(results[0].haslo)); | |
44 | + validateEquals(string("ign"), string(results[0].interp)); | |
45 | + | |
46 | + validateEquals(-1, results[1].p); | |
47 | +} | |
48 | + | |
49 | +void testWhitespaceKEEP() { | |
50 | + | |
51 | + validateEquals(1, morfeusz_set_option(MORFOPT_WHITESPACE, MORFEUSZ_KEEP_WHITESPACE)); | |
52 | + | |
53 | + char* text = const_cast<char*>(string("AAaaBBbbCCcc .").c_str()); | |
54 | + InterpMorf* results = morfeusz_analyse(text); | |
55 | + validateEquals(0, results[0].p); | |
56 | + validateEquals(1, results[0].k); | |
57 | + validateEquals(string("AAaaBBbbCCcc"), string(results[0].forma)); | |
58 | + validateEquals(string("AAaaBBbbCCcc"), string(results[0].haslo)); | |
59 | + validateEquals(string("ign"), string(results[0].interp)); | |
60 | + | |
61 | + validateEquals(1, results[1].p); | |
62 | + validateEquals(2, results[1].k); | |
63 | + validateEquals(string(" "), string(results[1].forma)); | |
64 | + validateEquals(string(" "), string(results[1].haslo)); | |
65 | +// validateEquals(string("ign"), string(results[2].interp)); | |
66 | + | |
67 | + validateEquals(2, results[2].p); | |
68 | + validateEquals(3, results[2].k); | |
69 | + validateEquals(string("."), string(results[2].forma)); | |
70 | + validateEquals(string("."), string(results[2].haslo)); | |
71 | +// validateEquals(string("ign"), string(results[2].interp)); | |
72 | + | |
73 | + validateEquals(-1, results[3].p); | |
74 | +} | |
75 | + | |
76 | +void testWhitespaceAPPEND() { | |
77 | + validateEquals(1, morfeusz_set_option(MORFOPT_WHITESPACE, MORFEUSZ_APPEND_WHITESPACE)); | |
78 | + | |
79 | + char* text = const_cast<char*>(string("AAaaBBbbCCcc .").c_str()); | |
80 | + InterpMorf* results = morfeusz_analyse(text); | |
81 | + validateEquals(0, results[0].p); | |
82 | + validateEquals(1, results[0].k); | |
83 | + validateEquals(string("AAaaBBbbCCcc "), string(results[0].forma)); | |
84 | + validateEquals(string("AAaaBBbbCCcc "), string(results[0].haslo)); | |
85 | + validateEquals(string("ign"), string(results[0].interp)); | |
86 | + | |
87 | + validateEquals(1, results[1].p); | |
88 | + validateEquals(2, results[1].k); | |
89 | + validateEquals(string("."), string(results[1].forma)); | |
90 | + validateEquals(string("."), string(results[1].haslo)); | |
91 | +// validateEquals(string("ign"), string(results[2].interp)); | |
92 | + | |
93 | + validateEquals(-1, results[2].p); | |
94 | +} | |
95 | + | |
96 | +void testEncodingUTF8() { | |
97 | + unsigned char text[] = {'z', 'a', /* ż */ 197, 188, /* ó */ 195, 179, '\0'}; | |
98 | + char* actualText = (char*) text; | |
99 | + validateEquals(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_CP1250)); | |
100 | + InterpMorf* results = morfeusz_analyse(actualText); | |
101 | + validateEquals(0, results[0].p); | |
102 | + validateEquals(1, results[0].k); | |
103 | + validateEquals(string(actualText), string(results[0].forma)); | |
104 | + validateEquals(string(actualText), string(results[0].haslo)); | |
105 | + validateEquals(string("ign"), string(results[0].interp)); | |
106 | + validateEquals(-1, results[2].p); | |
107 | +} | |
108 | + | |
109 | +void testTokenNumberingCONTINUOUS() { | |
110 | + | |
111 | + morfeusz_set_option(MORFOPT_WHITESPACE, MORFEUSZ_SKIP_WHITESPACE); | |
112 | + validateEquals(1, morfeusz_set_option(MORFOPT_TOKEN_NUMBERING, MORFEUSZ_CONTINUOUS_TOKEN_NUMBERING)); | |
113 | + | |
114 | + char* text = const_cast<char*>(string("a b.").c_str()); | |
115 | + InterpMorf* results = morfeusz_analyse(text); | |
116 | + validateEquals(0, results[0].p); | |
117 | + validateEquals(1, results[0].k); | |
118 | + validateEquals(string("a"), string(results[0].forma)); | |
119 | + | |
120 | + validateEquals(1, results[1].p); | |
121 | + validateEquals(2, results[1].k); | |
122 | + validateEquals(string("b"), string(results[1].forma)); | |
123 | + | |
124 | + validateEquals(2, results[2].p); | |
125 | + validateEquals(3, results[2].k); | |
126 | + validateEquals(string("."), string(results[2].forma)); | |
127 | + | |
128 | + validateEquals(-1, results[3].p); | |
129 | + | |
130 | + char* text1 = const_cast<char*>(string("c").c_str()); | |
131 | + results = morfeusz_analyse(text1); | |
132 | + validateEquals(3, results[0].p); | |
133 | + validateEquals(4, results[0].k); | |
134 | + validateEquals(string("c"), string(results[0].forma)); | |
135 | + | |
136 | + validateEquals(-1, results[1].p); | |
137 | +} | |
138 | + | |
139 | +void testEncodingISO8859_2() { | |
140 | + validateEquals(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_ISO8859_2)); | |
141 | +} | |
142 | + | |
143 | +void testEncodingCP1250() { | |
144 | + validateEquals(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_CP1250)); | |
145 | +} | |
146 | + | |
147 | +void testEncodingCP852() { | |
148 | + validateEquals(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_CP852)); | |
149 | +} | |
150 | + | |
151 | +void testWrongWhitespaceOption() { | |
152 | + validateEquals(0, morfeusz_set_option(MORFOPT_WHITESPACE, 666777)); | |
153 | +} | |
154 | + | |
155 | +void testWrongEncodingOption() { | |
156 | + validateEquals(0, morfeusz_set_option(MORFOPT_ENCODING, 666777)); | |
157 | +} | |
158 | + | |
159 | +void testWrongCaseOption() { | |
160 | + validateEquals(0, morfeusz_set_option(MORFOPT_CASE, 666777)); | |
161 | +} | |
162 | + | |
163 | +void testWrongTokenNumberingOption() { | |
164 | + validateEquals(0, morfeusz_set_option(MORFOPT_TOKEN_NUMBERING, 666777)); | |
165 | +} | |
166 | + | |
167 | +int main() { | |
168 | + testTwoSimpleInvocations(); | |
169 | + testWhitespaceKEEP(); | |
170 | + testWhitespaceAPPEND(); | |
171 | + testEncodingUTF8(); | |
172 | + testEncodingISO8859_2(); | |
173 | + testEncodingCP1250(); | |
174 | + testEncodingCP852(); | |
175 | + testWrongWhitespaceOption(); | |
176 | + testWrongEncodingOption(); | |
177 | + testWrongCaseOption(); | |
178 | + testWrongTokenNumberingOption(); | |
179 | + testTokenNumberingCONTINUOUS(); | |
180 | + return 0; | |
181 | +} | |
182 | + | |
... | ... |
morfeusz/tests/validate.hpp
0 → 100644
1 | +/* | |
2 | + * File: validate.hpp | |
3 | + * Author: lennyn | |
4 | + * | |
5 | + * Created on June 25, 2014, 10:11 PM | |
6 | + */ | |
7 | + | |
8 | +#ifndef VALIDATE_HPP | |
9 | +#define VALIDATE_HPP | |
10 | + | |
11 | +#include <string> | |
12 | +#include <iostream> | |
13 | + | |
14 | +template <typename T> | |
15 | +inline void validateEquals(const T required, const T got) { | |
16 | + bool ok = required == got; | |
17 | + if (!ok) { | |
18 | + std::cerr << "ERROR: '" << required << "' != '" << got << "'" << std::endl; | |
19 | + throw "FAILED"; | |
20 | + } | |
21 | +} | |
22 | + | |
23 | +#endif /* VALIDATE_HPP */ | |
24 | + | |
... | ... |