public void TestFrozen() { Collator theCollator = Collator.GetInstance(new CultureInfo("pl")); theCollator.Freeze(); Random r = new Random(); Control control = new Control(); Thread[] threads = new Thread[10]; for (int i = 0; i < threads.Length; ++i) { Test test = new Test("Frozen collation test thread " + i, (string[])threadTestData.Clone(), theCollator, r, control); threads[i] = new Thread(() => test.Run()); } RunThreads(threads, control); }
public void TestCollationKey() { if (source.Length == 0) { Errln("CollationMonkeyTest.TestCollationKey(): source is empty - ICU_DATA not set or data missing?"); return; } Collator myPrimaryCollator; Collator mySecondaryCollator; Collator myTertiaryCollator; try { Collator myCollator = Collator.GetInstance(new CultureInfo("en-CA")); myCollator.Freeze(); myPrimaryCollator = myCollator.CloneAsThawed(); myPrimaryCollator.Strength = (Collator.Primary); myPrimaryCollator.Freeze(); mySecondaryCollator = myPrimaryCollator.CloneAsThawed(); mySecondaryCollator.Strength = (Collator.Secondary); mySecondaryCollator.Freeze(); myTertiaryCollator = mySecondaryCollator.CloneAsThawed(); myTertiaryCollator.Strength = (Collator.Tertiary); myTertiaryCollator.Freeze(); } catch (Exception e) { Warnln("ERROR: in creation of collator of ENGLISH locale"); return; } Random rand = CreateRandom(); // use test framework's random seed int s = rand.Next(0x7fff) % source.Length; int t = rand.Next(0x7fff) % source.Length; int slen = Math.Abs(rand.Next(0x7fff) % source.Length - source.Length) % source.Length; int tlen = Math.Abs(rand.Next(0x7fff) % source.Length - source.Length) % source.Length; String subs = source.Substring(Math.Min(s, slen), Math.Min(s + slen, source.Length) - Math.Min(s, slen)); // ICU4N: Corrected 2nd parameter String subt = source.Substring(Math.Min(t, tlen), Math.Min(t + tlen, source.Length) - Math.Min(t, tlen)); // ICU4N: Corrected 2nd parameter CollationKey collationKey1, collationKey2; collationKey1 = myTertiaryCollator.GetCollationKey(subs); collationKey2 = myTertiaryCollator.GetCollationKey(subt); int result = collationKey1.CompareTo(collationKey2); // Tertiary int revResult = collationKey2.CompareTo(collationKey1); // Tertiary Report(subs, subt, result, revResult); collationKey1 = mySecondaryCollator.GetCollationKey(subs); collationKey2 = mySecondaryCollator.GetCollationKey(subt); result = collationKey1.CompareTo(collationKey2); // Secondary revResult = collationKey2.CompareTo(collationKey1); // Secondary Report(subs, subt, result, revResult); collationKey1 = myPrimaryCollator.GetCollationKey(subs); collationKey2 = myPrimaryCollator.GetCollationKey(subt); result = collationKey1.CompareTo(collationKey2); // Primary revResult = collationKey2.CompareTo(collationKey1); // Primary Report(subs, subt, result, revResult); String msg = ""; String addOne = subs + (0xE000).ToString(CultureInfo.InvariantCulture); collationKey1 = myPrimaryCollator.GetCollationKey(subs); collationKey2 = myPrimaryCollator.GetCollationKey(addOne); result = collationKey1.CompareTo(collationKey2); if (result != -1) { msg += "CollationKey("; msg += subs; msg += ") .LT. CollationKey("; msg += addOne; msg += ") Failed."; Errln(msg); } msg = ""; result = collationKey2.CompareTo(collationKey1); if (result != 1) { msg += "CollationKey("; msg += addOne; msg += ") .GT. CollationKey("; msg += subs; msg += ") Failed."; Errln(msg); } }
public void TestCompare() { if (source.Length == 0) { Errln("CollationMonkeyTest.TestCompare(): source is empty - ICU_DATA not set or data missing?"); return; } Collator myPrimaryCollator; Collator mySecondaryCollator; Collator myTertiaryCollator; try { Collator myCollator = Collator.GetInstance(new CultureInfo("en-CA")); myCollator.Freeze(); myPrimaryCollator = myCollator.CloneAsThawed(); myPrimaryCollator.Strength = (Collator.PRIMARY); myPrimaryCollator.Freeze(); mySecondaryCollator = myPrimaryCollator.CloneAsThawed(); mySecondaryCollator.Strength = (Collator.SECONDARY); mySecondaryCollator.Freeze(); myTertiaryCollator = mySecondaryCollator.CloneAsThawed(); myTertiaryCollator.Strength = (Collator.TERTIARY); myTertiaryCollator.Freeze(); } catch (Exception e) { Warnln("ERROR: in creation of collator of ENGLISH locale"); return; } /* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ Random rand = CreateRandom(); // use test framework's random seed int s = rand.Next(0x7fff) % source.Length; int t = rand.Next(0x7fff) % source.Length; int slen = Math.Abs(rand.Next(0x7fff) % source.Length - source.Length) % source.Length; int tlen = Math.Abs(rand.Next(0x7fff) % source.Length - source.Length) % source.Length; String subs = source.Substring(Math.Min(s, slen), Math.Min(s + slen, source.Length) - Math.Min(s, slen)); // ICU4N: Corrected 2nd parameter String subt = source.Substring(Math.Min(t, tlen), Math.Min(t + tlen, source.Length) - Math.Min(t, tlen)); // ICU4N: Corrected 2nd parameter int result = myTertiaryCollator.Compare(subs, subt); // Tertiary int revResult = myTertiaryCollator.Compare(subt, subs); // Tertiary Report(subs, subt, result, revResult); result = mySecondaryCollator.Compare(subs, subt); // Secondary revResult = mySecondaryCollator.Compare(subt, subs); // Secondary Report(subs, subt, result, revResult); result = myPrimaryCollator.Compare(subs, subt); // Primary revResult = myPrimaryCollator.Compare(subt, subs); // Primary Report(subs, subt, result, revResult); String msg = ""; String addOne = subs + (0xE000).ToString(CultureInfo.InvariantCulture); result = myPrimaryCollator.Compare(subs, addOne); if (result != -1) { msg += "Test : "; msg += subs; msg += " .LT. "; msg += addOne; msg += " Failed."; Errln(msg); } msg = ""; result = myPrimaryCollator.Compare(addOne, subs); if (result != 1) { msg += "Test : "; msg += addOne; msg += " .GT. "; msg += subs; msg += " Failed."; Errln(msg); } }