示例#1
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Hash code for two objects with same type and same value should be equal");

        try
        {
            ObjectGetHashCode obj1 = new ObjectGetHashCode();
            ObjectGetHashCode obj2 = new ObjectGetHashCode();

            if (obj1.GetHashCode() == obj2.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("001", "Hash code for two objects with same type and same value are not equal");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
示例#2
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Hash code for two objects with same type and same value should be equal");

        try
        {
            ObjectGetHashCode obj1 = new ObjectGetHashCode();
            ObjectGetHashCode obj2 = new ObjectGetHashCode();

            if (obj1.GetHashCode() == obj2.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("001", "Hash code for two objects with same type and same value are not equal");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
示例#3
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Hash function must return exactly the same value regardless of any changes that are made to the object");

        try
        {
            // Hack: Implement of ObjectGetHashCode.GetHashCode is inheritted from Object
            String str1 = TestLibrary.Generator.GetString(-55,
                                                          false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGHT);
            ObjectGetHashCode oghc = new ObjectGetHashCode();
            oghc.m_String = str1;
            int hashCode1 = oghc.GetHashCode();

            String str2 = TestLibrary.Generator.GetString(-55,
                                                          false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGHT);

            if (str1.Length == str2.Length)
            {
                str2 += TestLibrary.Generator.GetChar(-55);
            }

            oghc.m_String = str2;
            int hashCode2 = oghc.GetHashCode();

            if (hashCode1 != hashCode2)
            {
                TestLibrary.TestFramework.LogError("003", "Hash function does not return exactly the same value regardless of any changes that are made to the object");
                retVal = false;
            }

            // Change value type field should not change the hash code
            oghc.m_Int32 = TestLibrary.Generator.GetInt32(-55);
            hashCode2    = oghc.GetHashCode();

            if (hashCode1 != hashCode2)
            {
                TestLibrary.TestFramework.LogError("004", "Hash function does not return exactly the same value regardless of any changes that are made to the object");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
示例#4
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Hash function must return exactly the same value regardless of any changes that are made to the object");

        try
        {
            // Hack: Implement of ObjectGetHashCode.GetHashCode is inheritted from Object
            String str1 = TestLibrary.Generator.GetString(-55, 
                false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGHT);
            ObjectGetHashCode oghc = new ObjectGetHashCode();
            oghc.m_String = str1; 
            int hashCode1 = oghc.GetHashCode();

            String str2 = TestLibrary.Generator.GetString(-55, 
                false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGHT);

            if (str1.Length == str2.Length)
            {
                str2 += TestLibrary.Generator.GetChar(-55);
            }

            oghc.m_String = str2;
            int hashCode2 = oghc.GetHashCode();

            if (hashCode1 != hashCode2)
            {
                TestLibrary.TestFramework.LogError("003", "Hash function does not return exactly the same value regardless of any changes that are made to the object");
                retVal = false;
            }

            // Change value type field should not change the hash code
            oghc.m_Int32 = TestLibrary.Generator.GetInt32(-55);
            hashCode2 = oghc.GetHashCode();

            if (hashCode1 != hashCode2)
            {
                TestLibrary.TestFramework.LogError("004", "Hash function does not return exactly the same value regardless of any changes that are made to the object");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
示例#5
0
    public static int Main()
    {
        ObjectGetHashCode test = new ObjectGetHashCode();

        TestLibrary.TestFramework.BeginTestCase("ObjectGetHashCode");

        if (test.RunTests())
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("PASS");
            return(100);
        }
        else
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("FAIL");
            return(0);
        }
    }
示例#6
0
    public static int Main()
    {
        ObjectGetHashCode test = new ObjectGetHashCode();

        TestLibrary.TestFramework.BeginTestCase("ObjectGetHashCode");

        if (test.RunTests())
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("PASS");
            return 100;
        }
        else
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("FAIL");
            return 0;
        }
    }