public virtual void TestSliceEquals() { string left = "this is equal"; string right = left; char[] leftChars = left.ToCharArray(); char[] rightChars = right.ToCharArray(); Assert.IsTrue(ArrayUtil.Equals(leftChars, 0, rightChars, 0, left.Length), left + " does not equal: " + right); Assert.IsFalse(ArrayUtil.Equals(leftChars, 1, rightChars, 0, left.Length), left + " does not equal: " + right); Assert.IsFalse(ArrayUtil.Equals(leftChars, 1, rightChars, 2, left.Length), left + " does not equal: " + right); Assert.IsFalse(ArrayUtil.Equals(leftChars, 25, rightChars, 0, left.Length), left + " does not equal: " + right); Assert.IsFalse(ArrayUtil.Equals(leftChars, 12, rightChars, 0, left.Length), left + " does not equal: " + right); }
public virtual void TestUTF8toUTF32() { BytesRef utf8 = new BytesRef(20); Int32sRef utf32 = new Int32sRef(20); int[] codePoints = new int[20]; int num = AtLeast(50000); for (int i = 0; i < num; i++) { string s = TestUtil.RandomUnicodeString(Random); UnicodeUtil.UTF16toUTF8(s.ToCharArray(), 0, s.Length, utf8); UnicodeUtil.UTF8toUTF32(utf8, utf32); int charUpto = 0; int intUpto = 0; while (charUpto < s.Length) { int cp = Character.CodePointAt(s, charUpto); codePoints[intUpto++] = cp; charUpto += Character.CharCount(cp); } if (!ArrayUtil.Equals(codePoints, 0, utf32.Int32s, utf32.Offset, intUpto)) { Console.WriteLine("FAILED"); for (int j = 0; j < s.Length; j++) { Console.WriteLine(" char[" + j + "]=" + ((int)s[j]).ToString("x")); } Console.WriteLine(); Assert.AreEqual(intUpto, utf32.Length); for (int j = 0; j < intUpto; j++) { Console.WriteLine(" " + utf32.Int32s[j].ToString("x") + " vs " + codePoints[j].ToString("x")); } Assert.Fail("mismatch"); } } }