Beispiel #1
0
        public static void Main(string[] args)
        {
            var summary  = BenchmarkRunner.Run <StringComparerBenchmark>();
            var comparer = new SimpleCaseFoldingStringComparer();
            //var r = comparer.Compare("ЯяЫяЯяЯяЯяЯ1", "яЯяЯяЯяЯяЯя2");
            var r = comparer.Compare("CaseFolding1", "cASEfOLDING2");

            Console.WriteLine("Result: {0}", r);
        }
        public static void VerifyComparer()
        {
            SimpleCaseFoldingStringComparer sc = new SimpleCaseFoldingStringComparer();
            string s1  = "Hello";
            string s1a = "Hello";
            string s1b = "HELLO";
            string s2  = "ЯЯЯ2There";
            string aa  = "\0AAAAAAAAA";
            string bb  = "\0BBBBBBBBBBBB";

            Assert.True(sc.Equals(s1, s1a));
            Assert.True(sc.Equals((object)s1, (object)s1a));

            Assert.Equal(0, sc.Compare(s1, s1a));
            Assert.Equal(0, ((IComparer)sc).Compare(s1, s1a));

            Assert.True(sc.Equals(s1, s1));
            Assert.True(((IEqualityComparer)sc).Equals(s1, s1));
            Assert.Equal(0, sc.Compare(s1, s1));
            Assert.Equal(0, ((IComparer)sc).Compare(s1, s1));

            Assert.False(sc.Equals(s1, s2));
            Assert.False(((IEqualityComparer)sc).Equals(s1, s2));
            Assert.True(sc.Compare(s1, s2) < 0);
            Assert.True(((IComparer)sc).Compare(s1, s2) < 0);

            Assert.True(sc.Equals(s1, s1b));
            Assert.True(((IEqualityComparer)sc).Equals(s1, s1b));

            Assert.NotEqual(0, ((IComparer)sc).Compare(aa, bb));
            Assert.False(sc.Equals(aa, bb));
            Assert.False(((IEqualityComparer)sc).Equals(aa, bb));
            Assert.True(sc.Compare(aa, bb) < 0);
            Assert.True(((IComparer)sc).Compare(aa, bb) < 0);

            int result = sc.Compare(s1, s1b);

            Assert.Equal(0, result);

            result = ((IComparer)sc).Compare(s1, s1b);
            Assert.Equal(0, result);
        }
        public static void VerifyStringComparer_Equal(string strA, string strB)
        {
            SimpleCaseFoldingStringComparer sc = new SimpleCaseFoldingStringComparer();

            Assert.True(sc.Equals(strA, strB));
            Assert.True(sc.Equals((object)strA, (object)strB));
            Assert.True(sc.Equals((object)strA, strB));
            Assert.True(sc.Equals(strA, (object)strB));

            Assert.Equal(0, sc.Compare(strA, strB));
            Assert.Equal(0, ((IComparer)sc).Compare(strA, strB));
            Assert.True(((IEqualityComparer)sc).Equals(strA, strB));
        }
        public static void VerifyStringComparer_NotEqual(string strA, string strB, int result)
        {
            SimpleCaseFoldingStringComparer sc = new SimpleCaseFoldingStringComparer();

            Assert.False(sc.Equals(strA, strB));
            Assert.False(sc.Equals((object)strA, (object)strB));
            Assert.False(sc.Equals((object)strA, strB));
            Assert.False(sc.Equals(strA, (object)strB));

            Assert.True(sc.Compare(strA, strB) * result > 0);
            Assert.True(((IComparer)sc).Compare(strA, strB) * result > 0);
            Assert.False(((IEqualityComparer)sc).Equals(strA, strB));
        }
Beispiel #5
0
        public int SimpleCaseFoldCompare(string strA, string strB)
        {
            var comparer = new SimpleCaseFoldingStringComparer();

            return(comparer.Compare(strA, strB));
        }