LEFT | RIGHT |
(no file at all) | |
1 // © 2016 and later: Unicode, Inc. and others. | 1 // © 2016 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 /* | 3 /* |
4 ******************************************************************************* | 4 ******************************************************************************* |
5 * Copyright (C) 2007, International Business Machines Corporation and * | 5 * Copyright (C) 2007, International Business Machines Corporation and * |
6 * others. All Rights Reserved. * | 6 * others. All Rights Reserved. * |
7 ******************************************************************************* | 7 ******************************************************************************* |
8 */ | 8 */ |
9 package com.ibm.icu.dev.test.util; | 9 package com.ibm.icu.dev.test.util; |
10 | 10 |
11 import java.util.Arrays; | 11 import java.util.Arrays; |
12 import java.util.Iterator; | 12 import java.util.Iterator; |
13 | 13 |
14 import org.junit.Test; | 14 import org.junit.Test; |
15 import org.junit.runner.RunWith; | 15 import org.junit.runner.RunWith; |
16 import org.junit.runners.JUnit4; | 16 import org.junit.runners.JUnit4; |
17 | 17 |
18 import com.ibm.icu.dev.test.TestFmwk; | 18 import com.ibm.icu.dev.test.TestFmwk; |
19 import com.ibm.icu.impl.TextTrieMap; | 19 import com.ibm.icu.impl.TextTrieMap; |
| 20 import com.ibm.icu.text.UnicodeSet; |
20 | 21 |
21 @RunWith(JUnit4.class) | 22 @RunWith(JUnit4.class) |
22 public class TextTrieMapTest extends TestFmwk { | 23 public class TextTrieMapTest extends TestFmwk { |
23 | 24 |
24 private static final Integer SUN = new Integer(1); | 25 private static final Integer SUN = new Integer(1); |
25 private static final Integer MON = new Integer(2); | 26 private static final Integer MON = new Integer(2); |
26 private static final Integer TUE = new Integer(3); | 27 private static final Integer TUE = new Integer(3); |
27 private static final Integer WED = new Integer(4); | 28 private static final Integer WED = new Integer(4); |
28 private static final Integer THU = new Integer(5); | 29 private static final Integer THU = new Integer(5); |
29 private static final Integer FRI = new Integer(6); | 30 private static final Integer FRI = new Integer(6); |
30 private static final Integer SAT = new Integer(7); | 31 private static final Integer SAT = new Integer(7); |
31 | 32 |
32 private static final Integer SUP1 = new Integer(8); | 33 private static final Integer SUP1 = new Integer(8); |
33 private static final Integer SUP2 = new Integer(9); | 34 private static final Integer SUP2 = new Integer(9); |
34 private static final Integer SUP3 = new Integer(10); | 35 private static final Integer SUP3 = new Integer(10); |
35 private static final Integer SUP4 = new Integer(11); | 36 private static final Integer SUP4 = new Integer(11); |
| 37 private static final Integer SUP5 = new Integer(12); |
36 | 38 |
37 private static final Integer FOO = new Integer(-1); | 39 private static final Integer FOO = new Integer(-1); |
38 private static final Integer BAR = new Integer(-2); | 40 private static final Integer BAR = new Integer(-2); |
39 | 41 |
40 private static final Object[][] TESTDATA = { | 42 private static final Object[][] TESTDATA = { |
41 {"Sunday", SUN}, | 43 {"Sunday", SUN}, |
42 {"Monday", MON}, | 44 {"Monday", MON}, |
43 {"Tuesday", TUE}, | 45 {"Tuesday", TUE}, |
44 {"Wednesday", WED}, | 46 {"Wednesday", WED}, |
45 {"Thursday", THU}, | 47 {"Thursday", THU}, |
(...skipping 10 matching lines...) Expand all Loading... |
56 {"M", MON}, | 58 {"M", MON}, |
57 {"T", TUE}, | 59 {"T", TUE}, |
58 {"W", WED}, | 60 {"W", WED}, |
59 {"T", THU}, | 61 {"T", THU}, |
60 {"F", FRI}, | 62 {"F", FRI}, |
61 {"S", SAT}, | 63 {"S", SAT}, |
62 {"L📺", SUP1}, // L, 0xD83D, 0xDCFA | 64 {"L📺", SUP1}, // L, 0xD83D, 0xDCFA |
63 {"L📺1", SUP2}, // L, 0xD83D, 0xDCFA, 1 | 65 {"L📺1", SUP2}, // L, 0xD83D, 0xDCFA, 1 |
64 {"L📻", SUP3}, // L, 0xD83D, 0xDCFB | 66 {"L📻", SUP3}, // L, 0xD83D, 0xDCFB |
65 {"L🃏", SUP4}, // L, 0xD83C, 0xDCCF | 67 {"L🃏", SUP4}, // L, 0xD83C, 0xDCCF |
| 68 {"📺", SUP5}, // 0xD83D, 0xDCFA |
| 69 {"📻", SUP5}, // 0xD83D, 0xDCFB |
| 70 {"🃏", SUP5}, // 0xD83C, 0xDCCF |
66 }; | 71 }; |
67 | 72 |
68 private static final Object[][] TESTCASES = { | 73 private static final Object[][] TESTCASES = { |
69 {"Sunday", SUN, SUN}, | 74 {"Sunday", SUN, SUN}, |
70 {"sunday", null, SUN}, | 75 {"sunday", null, SUN}, |
71 {"Mo", MON, MON}, | 76 {"Mo", MON, MON}, |
72 {"mo", null, MON}, | 77 {"mo", null, MON}, |
73 {"Thursday Friday", THU, THU}, | 78 {"Thursday Friday", THU, THU}, |
74 {"T", new Object[]{TUE, THU}, new Object[]{TUE, THU}}, | 79 {"T", new Object[]{TUE, THU}, new Object[]{TUE, THU}}, |
75 {"TEST", new Object[]{TUE, THU}, new Object[]{TUE, THU}}, | 80 {"TEST", new Object[]{TUE, THU}, new Object[]{TUE, THU}}, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 checkResult("get(String, int) case " + i, itr, TESTCASES[i][1]); | 172 checkResult("get(String, int) case " + i, itr, TESTCASES[i][1]); |
168 } | 173 } |
169 | 174 |
170 logln("Test for ParseState"); | 175 logln("Test for ParseState"); |
171 for (int i = 0; i < TESTCASES_PARSE.length; i++) { | 176 for (int i = 0; i < TESTCASES_PARSE.length; i++) { |
172 String test = (String) TESTCASES_PARSE[i][0]; | 177 String test = (String) TESTCASES_PARSE[i][0]; |
173 Object[] expecteds = (Object[]) TESTCASES_PARSE[i][1]; | 178 Object[] expecteds = (Object[]) TESTCASES_PARSE[i][1]; |
174 checkParse(map, test, expecteds, true); | 179 checkParse(map, test, expecteds, true); |
175 } | 180 } |
176 | 181 |
| 182 logln("Test for partial match"); |
| 183 for (Object[] cas : TESTDATA) { |
| 184 String str = (String) cas[0]; |
| 185 for (int i = 0; i < str.length() - 1; i++) { |
| 186 TextTrieMap.Output output = new TextTrieMap.Output(); |
| 187 map.get(str.substring(0, i), 0, output); |
| 188 assertTrue("Partial string means partial match", output.partialM
atch); |
| 189 } |
| 190 String bad = str + "x"; |
| 191 TextTrieMap.Output output = new TextTrieMap.Output(); |
| 192 map.get(bad, 0, output); |
| 193 assertFalse("No partial match on bad string", output.partialMatch); |
| 194 } |
| 195 TextTrieMap.Output output = new TextTrieMap.Output(); |
| 196 map.get("Sunday", 0, output); |
| 197 assertFalse("No partial match on string with no continuation", output.pa
rtialMatch); |
| 198 |
| 199 logln("Test for LeadCodePoints"); |
| 200 // Note: The 📺 and 📻 have the same lead surrogate |
| 201 UnicodeSet expectedLeadCodePoints = new UnicodeSet("[SMTWFL📺📻🃏]"); |
| 202 UnicodeSet actualLeadCodePoints = new UnicodeSet(); |
| 203 map.putLeadCodePoints(actualLeadCodePoints); |
| 204 assertEquals("leadCodePoints", expectedLeadCodePoints, actualLeadCodePoi
nts); |
| 205 |
177 // Add duplicated entry | 206 // Add duplicated entry |
178 map.put("Sunday", FOO); | 207 map.put("Sunday", FOO); |
179 // Add duplicated entry with different casing | 208 // Add duplicated entry with different casing |
180 map.put("sunday", BAR); | 209 map.put("sunday", BAR); |
181 | 210 |
182 // Make sure the all entries are returned | 211 // Make sure the all entries are returned |
183 itr = map.get("Sunday"); | 212 itr = map.get("Sunday"); |
184 checkResult("Get Sunday", itr, new Object[]{FOO, SUN}); | 213 checkResult("Get Sunday", itr, new Object[]{FOO, SUN}); |
185 } | 214 } |
186 | 215 |
(...skipping 22 matching lines...) Expand all Loading... |
209 itr = map.get(textBuf.toString(), i); | 238 itr = map.get(textBuf.toString(), i); |
210 checkResult("get(String, int) case " + i, itr, TESTCASES[i][2]); | 239 checkResult("get(String, int) case " + i, itr, TESTCASES[i][2]); |
211 } | 240 } |
212 | 241 |
213 logln("Test for ParseState"); | 242 logln("Test for ParseState"); |
214 for (int i = 0; i < TESTCASES_PARSE.length; i++) { | 243 for (int i = 0; i < TESTCASES_PARSE.length; i++) { |
215 String test = (String) TESTCASES_PARSE[i][0]; | 244 String test = (String) TESTCASES_PARSE[i][0]; |
216 Object[] expecteds = (Object[]) TESTCASES_PARSE[i][1]; | 245 Object[] expecteds = (Object[]) TESTCASES_PARSE[i][1]; |
217 checkParse(map, test, expecteds, false); | 246 checkParse(map, test, expecteds, false); |
218 } | 247 } |
| 248 |
| 249 logln("Test for partial match"); |
| 250 for (Object[] cas : TESTDATA) { |
| 251 String str = (String) cas[0]; |
| 252 for (int i = 0; i < str.length() - 1; i++) { |
| 253 TextTrieMap.Output output = new TextTrieMap.Output(); |
| 254 map.get(str.substring(0, i), 0, output); |
| 255 assertTrue("Partial string means partial match", output.partialM
atch); |
| 256 } |
| 257 String bad = str + "x"; |
| 258 TextTrieMap.Output output = new TextTrieMap.Output(); |
| 259 map.get(bad, 0, output); |
| 260 assertFalse("No partial match on bad string", output.partialMatch); |
| 261 } |
| 262 TextTrieMap.Output output = new TextTrieMap.Output(); |
| 263 map.get("Sunday", 0, output); |
| 264 assertFalse("No partial match on string with no continuation", output.pa
rtialMatch); |
| 265 |
| 266 logln("Test for LeadCodePoints"); |
| 267 UnicodeSet expectedLeadCodePoints = new UnicodeSet("[smtwfl📺📻🃏]"); |
| 268 UnicodeSet actualLeadCodePoints = new UnicodeSet(); |
| 269 map.putLeadCodePoints(actualLeadCodePoints); |
| 270 assertEquals("leadCodePoints", expectedLeadCodePoints, actualLeadCodePoi
nts); |
219 | 271 |
220 // Add duplicated entry | 272 // Add duplicated entry |
221 map.put("Sunday", FOO); | 273 map.put("Sunday", FOO); |
222 // Add duplicated entry with different casing | 274 // Add duplicated entry with different casing |
223 map.put("sunday", BAR); | 275 map.put("sunday", BAR); |
224 | 276 |
225 // Make sure the all entries are returned | 277 // Make sure the all entries are returned |
226 itr = map.get("Sunday"); | 278 itr = map.get("Sunday"); |
227 checkResult("Get Sunday", itr, new Object[]{SUN, FOO, BAR}); | 279 checkResult("Get Sunday", itr, new Object[]{SUN, FOO, BAR}); |
228 } | 280 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 } | 368 } |
317 } | 369 } |
318 } | 370 } |
319 for (int i = 0; i < exp.length; i++) { | 371 for (int i = 0; i < exp.length; i++) { |
320 if (found[i] == false) { | 372 if (found[i] == false) { |
321 errln("FAIL: The search result does not contain " + exp[i]); | 373 errln("FAIL: The search result does not contain " + exp[i]); |
322 } | 374 } |
323 } | 375 } |
324 } | 376 } |
325 } | 377 } |
LEFT | RIGHT |