Ejemplo n.º 1
0
    public bool PosTest2()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest2: Verify the EqualityComparer.Equals(T,T) when T is reference type... ";
        const string c_TEST_ID   = "P002";

        String str1 = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);
        String str2 = str1;
        MyEqualityComparer <String> myEC = new MyEqualityComparer <String>();

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (!myEC.Equals(str1, str2))
            {
                string errorDesc = "result should be true when two String object is the same reference";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
        public void UsesProvidedEqualityComparer()
        {
            MyEqualityComparer comparer = new MyEqualityComparer();

            Assert.That(2 + 2, Is.EqualTo(4).Using(comparer));
            Assert.That(comparer.Called, "Comparer was not called");
        }
Ejemplo n.º 3
0
    public bool PosTest1()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest1: Verify EqualityCompare.Equals(T,T) when Type is int...";
        const string c_TEST_ID   = "P001";

        MyEqualityComparer <int> myEC = new MyEqualityComparer <int>();
        int x = TestLibrary.Generator.GetInt32(-55);

        int expectedValue = x.GetHashCode();

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            int actualValue = myEC.GetHashCode(x);
            if (expectedValue != actualValue)
            {
                string errorDesc = "Value is not " + actualValue + " as expected: Actual(" + expectedValue + ")";
                TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 4
0
    public bool PosTest2()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest2: Verify EqualityCompare.Equals(T,T) when Type is a reference type...";
        const string c_TEST_ID   = "P002";

        MyEqualityComparer <String> myEC = new MyEqualityComparer <String>();
        string str = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);

        int expectedValue = str.GetHashCode();

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            int actualValue = myEC.GetHashCode(str);
            if (expectedValue != actualValue)
            {
                string errorDesc = "Value is not " + actualValue + " as expected: Actual(" + expectedValue + ")";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 5
0
    public bool PosTest3()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest3: Verify EqualityCompare.Equals(T,T) when Type is a reference type...";
        const string c_TEST_ID   = "P003";

        MyEqualityComparer <MyClass> myEC = new MyEqualityComparer <MyClass>();
        MyClass myclass1 = new MyClass();

        int expectedValue = myclass1.GetHashCode();

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            int actualValue = myEC.GetHashCode(myclass1);
            if (expectedValue != actualValue)
            {
                string errorDesc = "Value is not " + actualValue + " as expected: Actual(" + expectedValue + ")";
                TestLibrary.TestFramework.LogError("005" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 6
0
    public bool NegTest1()
    {
        bool retVal = true;

        const string c_TEST_DESC = "NegTest1: object is a null reference";
        const string c_TEST_ID   = "N001";

        MyEqualityComparer <MyClass> myEC = new MyEqualityComparer <MyClass>();

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            myEC.GetHashCode(null);
            TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, "ArgumentNullException is not thrown as expected.");
            retVal = false;
        }
        catch (ArgumentNullException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
            retVal = false;
        }

        return(retVal);
    }
    public bool PosTest4()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest4: Using user-defined class which implemented the GetHashCode method in IEqualityComparer<T>...";
        const string c_TEST_ID   = "P004";

        MyEqualityComparer <String> myEC = new MyEqualityComparer <String>();
        String str = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);

        int expectedValue = str.GetHashCode();

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            int actualValue = ((IEqualityComparer <String>)myEC).GetHashCode(str);
            if (expectedValue != actualValue)
            {
                string errorDesc = "Value is not " + actualValue + " as expected: Actual(" + expectedValue + ")";
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 8
0
    public bool PosTest5()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest5: Verify EqualityCompare.Equals(T,T) when a parameters is a null reference and another is not... ";
        const string c_TEST_ID   = "P005";

        MyEqualityComparer <String> myEC = new MyEqualityComparer <String>();
        String str1 = null;
        String str2 = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (myEC.Equals(str1, str2))
            {
                string errorDesc = "result should be false when a String is null and another is not";
                TestLibrary.TestFramework.LogError("009" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("010", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 9
0
    public bool PosTest1()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest1: Verify EqualityCompare.Equals(T,T) when Type is int...";
        const string c_TEST_ID   = "P001";

        MyEqualityComparer <int> myEC = new MyEqualityComparer <int>();
        int x = TestLibrary.Generator.GetInt32(-55);
        int y = x;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (!myEC.Equals(x, y))
            {
                string errorDesc = "result should be true when two int both is 1";
                TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 10
0
    public bool PosTest4()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest4: Verify EqualityCompare.Equals(T,T) when two parameters are null reference... ";
        const string c_TEST_ID   = "P004";

        MyEqualityComparer <String> myEC = new MyEqualityComparer <String>();
        String str1 = null;
        String str2 = null;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (!myEC.Equals(str2, str1))
            {
                string errorDesc = "result should be true when two DateTime object is null reference";
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 11
0
    public bool PosTest3()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest3: Verify EqualityCompare.Equals(T,T) when Type is user-defined class... ";
        const string c_TEST_ID   = "P003";

        MyEqualityComparer <MyClass> myEC = new MyEqualityComparer <MyClass>();
        MyClass myClass1 = new MyClass();
        MyClass myClass2 = myClass1;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (!myEC.Equals(myClass1, myClass2))
            {
                string errorDesc = "result should be true when two MyClass object is the same reference";
                TestLibrary.TestFramework.LogError("005" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 12
0
    public bool PosTest5()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest5: Using user-defined class which implemented the Equals method in IEqualityComparer<T> and two parament are null...";
        const string c_TEST_ID   = "P005";

        MyEqualityComparer <Object> myEC = new MyEqualityComparer <Object>();
        Object x = null;
        Object y = null;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (!((IEqualityComparer <Object>)myEC).Equals(x, y))
            {
                string errorDesc = "result should be true when two object are null";
                TestLibrary.TestFramework.LogError("009" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("010", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 13
0
    public bool PosTest4()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest4: Using user-defined class which implemented the Equals method in IEqualityComparer<T>...";
        const string c_TEST_ID   = "P004";

        MyEqualityComparer <String> myEC = new MyEqualityComparer <String>();
        String str1 = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);
        String str2 = str1 + TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (((IEqualityComparer <String>)myEC).Equals(str1, str2))
            {
                string errorDesc = "result should be true when two string are difference";
                errorDesc += "\n str1 is " + str1;
                errorDesc += "\n str2 is " + str2;
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 14
0
        public void UsesProvidedEqualityComparer()
        {
            MyEqualityComparer comparer = new MyEqualityComparer();

            Assert.That(new string[] { "Hello", "World" },
                        new CollectionContainsConstraint("World").Using(comparer));
            Assert.That(comparer.Called, "Comparer was not called");
        }
Ejemplo n.º 15
0
        public void TestClone()
        {
            {
                char[]    c1 = { 'a', 'b', 'c' };
                char[]    c2 = { 'd', 'e', 'f' };
                Hashtable h1 = new Hashtable();
                for (int i = 0; i < c1.Length; i++)
                {
                    h1[c1[i]] = c2[i];
                }
                Hashtable h2 = (Hashtable)h1.Clone();
                Assert.IsNotNull(h2, "got no clone!");
                Assert.IsNotNull(h2[c1[0]], "clone's got nothing!");
                for (int i = 0; i < c1.Length; i++)
                {
                    Assert.AreEqual(h1[c1[i]], h2[c1[i]], "Hashtable match");
                }
            }
            {
                char[]    c1  = { 'a', 'b', 'c' };
                char[]    c20 = { '1', '2' };
                char[]    c21 = { '3', '4' };
                char[]    c22 = { '5', '6' };
                char[][]  c2  = { c20, c21, c22 };
                Hashtable h1  = new Hashtable();
                for (int i = 0; i < c1.Length; i++)
                {
                    h1[c1[i]] = c2[i];
                }
                Hashtable h2 = (Hashtable)h1.Clone();
                Assert.IsNotNull(h2, "got no clone!");
                Assert.IsNotNull(h2[c1[0]], "clone's got nothing!");
                for (int i = 0; i < c1.Length; i++)
                {
                    Assert.AreEqual(h1[c1[i]], h2[c1[i]], "Hashtable match");
                }

                ((char[])h1[c1[0]])[0] = 'z';
                Assert.AreEqual(h1[c1[0]], h2[c1[0]], "shallow copy");

#if NET_2_0
                // NET 2.0 stuff
                MyEqualityComparer a        = new MyEqualityComparer();
                Hashtable          mh1      = new Hashtable(a);
                Hashtable          mh1clone = (Hashtable)mh1.Clone();

                // warning, depends on the field name.
                Assert.AreEqual(GetEqualityComparer(mh1), GetEqualityComparer(mh1clone), "EqualityComparer");
#endif
            }
        }
Ejemplo n.º 16
0
 public MyCountingHashTable(int bucketCount) : base(bucketCount)
 {
     myEqualityComparer = new MyEqualityComparer();
     this.bucketCount   = ((bucketCount > 1024) ? bucketCount : 1024);
     this.buckets       = new Node[bucketCount];
 }
Ejemplo n.º 17
0
	public void TestClone() {
		{
			char[] c1 = {'a', 'b', 'c'};
			char[] c2 = {'d', 'e', 'f'};
			Hashtable h1 = new Hashtable();
			for (int i = 0; i < c1.Length; i++) {
				h1[c1[i]] = c2[i];
			}
			Hashtable h2 = (Hashtable)h1.Clone();
			Assert.IsNotNull (h2, "got no clone!");
			Assert.IsNotNull (h2[c1[0]], "clone's got nothing!");
			for (int i = 0; i < c1.Length; i++) {
				Assert.AreEqual (h1[c1[i]], h2[c1[i]], "Hashtable match");
			}
		}
		{
			char[] c1 = {'a', 'b', 'c'};
			char[] c20 = {'1', '2'};
			char[] c21 = {'3', '4'};
			char[] c22 = {'5', '6'};
			char[][] c2 = {c20, c21, c22};
			Hashtable h1 = new Hashtable();
			for (int i = 0; i < c1.Length; i++) {
				h1[c1[i]] = c2[i];
			}
			Hashtable h2 = (Hashtable)h1.Clone();
			Assert.IsNotNull (h2, "got no clone!");
			Assert.IsNotNull (h2[c1[0]], "clone's got nothing!");
			for (int i = 0; i < c1.Length; i++) {
				Assert.AreEqual (h1[c1[i]], h2[c1[i]], "Hashtable match");
			}

			((char[])h1[c1[0]])[0] = 'z';
			Assert.AreEqual (h1[c1[0]], h2[c1[0]], "shallow copy");

#if NET_2_0
			// NET 2.0 stuff
			MyEqualityComparer a = new MyEqualityComparer ();
			Hashtable mh1 = new Hashtable (a);
			Hashtable mh1clone = (Hashtable) mh1.Clone ();
			
			// warning, depends on the field name.
			Assert.AreEqual (GetEqualityComparer (mh1), GetEqualityComparer (mh1clone), "EqualityComparer");
#endif
		}
	}
Ejemplo n.º 18
0
        public static IEnumerable <T> Except <T>(this IEnumerable <T> first, IEnumerable <T> second, Func <T, T, bool> predicate)
        {
            var eq = new MyEqualityComparer <T>(predicate);

            return(first.Except(second, eq));
        }