2 ******************************************************************************
3 * Copyright (C) 2005-2007, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 ******************************************************************************
15 #if !UCONFIG_NO_COLLATION
17 //Raymond: Following comments are copied from Java implementation
23 // relation "[variable top]"
24 // relation (chars "|")? chars ("/" chars)?
25 // plus, a reset must come before a relation
28 static const char collationBNF
[] =
32 "$alternateOptions = non'-'ignorable | shifted;"
34 "$caseFirstOptions = off | upper | lower;"
35 "$strengthOptions = '1' | '2' | '3' | '4' | 'I';"
37 " ( alternate ' ' $alternateOptions"
39 " | normalization ' ' $onoff "
40 " | caseLevel ' ' $onoff "
41 " | hiraganaQ ' ' $onoff"
42 " | caseFirst ' ' $caseFirstOptions"
43 " | strength ' ' $strengthOptions"
45 "$command = $commandList $crlf;"
47 "$ignorableTypes = (tertiary | secondary | primary) ' ' ignorable;"
48 "$allTypes = variable | regular | implicit | trailing | $ignorableTypes;"
49 "$positionList = '[' (first | last) ' ' $allTypes ']';"
51 "$beforeList = '[before ' ('1' | '2' | '3') ']';"
61 "$string = $chars{1,5}~@;"
62 "$chars = a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z| '<'| '&'| '['| ']';"
63 "$rel1 = '[variable top]' $s;"
64 "$p1 = ($string $s '|' $s)? 25%;"
65 "$p2 = ('/' $s $string $s)? 25%;"
66 "$rel2 = $p1 $string $s $p2;"
67 "$relation = $relationList $s ($rel1 | $rel2) $crlf;"
69 "$reset = '&' $s ($beforeList $s)? 10% ($positionList 1% | $string 10%) $crlf;"
70 "$mostRules = $command 1% | $reset 5% | $relation 25%;"
71 "$root = $command{0,5} $reset $mostRules{1,20};";
74 void RandomCollatorTest::Test2(){
75 // See ticket 5747 about reenabling this test.
76 errln("TestWbnf is incorrectly implemented.\nThis test should be modeled to use the existing test frame work for naming tests.\n");
81 void RandomCollatorTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* ){
82 if (exec
) logln("TestSuite RandomCollatorTest: ");
86 default: name
= ""; break;
91 class TestColltorCompare{
93 UBool operator()(Collator &coll, int count = 1000){
94 UnicodeString a(test_string.get_a_string());
95 UnicodeString b(test_string.get_a_string());
96 UnicodeString c(test_string.get_a_string());
98 if (check_transitivity(coll, a, b, c)){
101 c = UnicodeString(test_string.get_a_string());
103 }while(count-- >= 0 );
107 TestColltorCompare():test_string("$s = $c{1,8};", "$s", "$c", new Magic_SelectOneChar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ[]&<")){
110 UBool check_transitivity(const Collator & coll, const UnicodeString &a, const UnicodeString &b, const UnicodeString &c){
111 int ab = coll.compare(a,b), ba = coll.compare(b,a);
112 int bc = coll.compare(b,c), cb = coll.compare(c,b);
113 int ca = coll.compare(c,a), ac = coll.compare(a,c);
118 if (//counter-clockwise, maximum
119 (ab >=0 && bc >=0 && ac <0)
120 ||(bc >=0 && ca >=0 && ba <0)
121 ||(ca >=0 && ab >=0 && cb <0)
123 //counter-clockwise, minimum
124 ||(ab <=0 && bc <=0 && ca >0)
125 ||(bc <=0 && ca <=0 && ba >0)
126 ||(ca <=0 && ab <=0 && cb >0)
133 LanguageGenerator test_string;
136 void RandomCollatorTest::Test(){
137 // See ticket 5747 about reenabling this test.
138 errln("This test needs to be fixed.\n");
140 LanguageGenerator test_rule
;
141 if (test_rule
.parseBNF(collationBNF
, "$root", TRUE
) != LanguageGenerator::OK
){
142 errln("The test code itself is wrong.");
146 //TestColltorCompare coll_test;
148 static const int CONSTRUCT_RANDOM_COUNT
= 1000;
150 for (i
=0; i
< CONSTRUCT_RANDOM_COUNT
; i
++){
151 const char * rule
= test_rule
.next();
152 logln("\n-----------------------------------%d\n",i
);
153 logln(UnicodeString(rule
, strlen(rule
)));
155 UnicodeString
newRule(rule
); // potential bug
156 UErrorCode status
= U_ZERO_ERROR
;
157 logln( "===========================================\n");
158 fwrite(rule
, strlen(rule
),1,stdout
);
159 logln("\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
161 Collator
* c
= new RuleBasedCollator(newRule
,status
);
163 if (U_FAILURE(status
)) {
164 errln( "Could not create Collator for the %d(th) generated rule.\n"
167 i
, u_errorName(status
));
175 #endif /* #if !UCONFIG_NO_COLLATION */