Exemplo n.º 1
0
        public void Test_Values_Of_Same_Types_Are_Always_Similar()
        {
            void Test(object x, object y)
            {
                bool expected = x == null ? y == null : y != null && x.Equals(y);

                Assert.That(ComparisonHelper.AreSimilar(x, y), Is.EqualTo(expected), expected ? "{0} == {1}" : "{0} != {1}", x, y);
            }

            Test(null, null);

            Test("hello", "world");
            Test("hello", "hello");
            Test("hello", "Hello");
            Test("hello", null);
            Test(null, "world");

            Test(123, 123);
            Test(123, 456);
            Test(123, null);
            Test(null, 456);

            Test(123L, 123L);
            Test(123L, 456L);
            Test(123L, null);
            Test(null, 456L);
        }
Exemplo n.º 2
0
        public void Test_Values_Of_Similar_Types_Are_Similar()
        {
            void Similar(object x, object y)
            {
                if (!ComparisonHelper.AreSimilar(x, y))
                {
                    Assert.Fail("({0}) {1} ~= ({2}) {3}", x == null ? "object" : x.GetType().Name, x, y == null ? "object" : y.GetType().Name, y);
                }
            }

            void Different(object x, object y)
            {
                if (ComparisonHelper.AreSimilar(x, y))
                {
                    Assert.Fail("({0}) {1} !~= ({2}) {3}", x == null ? "object" : x.GetType().Name, x, y == null ? "object" : y.GetType().Name, y);
                }
            }

            Different("hello", 123);
            Different(123, "hello");

            Similar("A", 'A');
            Similar('A', "A");
            Different("AA", 'A');
            Different('A', "AA");
            Different("A", 'B');
            Different('A', "B");

            Similar("123", 123);
            Similar("123", 123L);
            Similar("123.4", 123.4f);
            Similar("123.4", 123.4d);

            Similar(123, "123");
            Similar(123L, "123");
            Similar(123.4f, "123.4");
            Similar(123.4d, "123.4");

            var g = Guid.NewGuid();

            Similar(g, g.ToString());
            Similar(g.ToString(), g);

            Different(g.ToString(), Guid.Empty);
            Different(Guid.Empty, g.ToString());
        }