diff --git a/Tests/NFUnitTestBitConverter/BitConverter.cs b/Tests/NFUnitTestBitConverter/BitConverter.cs index 505c3ee9..41bc6a26 100644 --- a/Tests/NFUnitTestBitConverter/BitConverter.cs +++ b/Tests/NFUnitTestBitConverter/BitConverter.cs @@ -47,24 +47,26 @@ public void BitConverterTest_DoubleToInt64Bits() } [TestMethod] - public void BitConverterTest_GetBytesBool() + [DataRow(true, new byte[] { 1 })] + [DataRow(false, new byte[] { 0 })] + public void BitConverterTest_GetBytesBool(bool value, byte[] expected) { - Helper.GetBytesBool(true, new byte[] { 1 }); - Helper.GetBytesBool(false, new byte[] { 0 }); + Helper.GetBytesBool(value, expected); } [TestMethod] - public void BitConverterTest_GetBytesChar() + [DataRow('\0', new byte[] { 0x00, 0x00 })] + [DataRow(' ', new byte[] { 0x20, 0x00 })] + [DataRow('*', new byte[] { 0x2A, 0x00 })] + [DataRow('3', new byte[] { 0x33, 0x00 })] + [DataRow('A', new byte[] { 0x41, 0x00 })] + [DataRow('[', new byte[] { 0x5B, 0x00 })] + [DataRow('a', new byte[] { 0x61, 0x00 })] + [DataRow('{', new byte[] { 0x7B, 0x00 })] + [DataRow('测', new byte[] { 0x4B, 0x6D })] + public void BitConverterTest_GetBytesChar(char value, byte[] expected) { - Helper.GetBytesChar('\0', new byte[] { 0x00, 0x00 }); - Helper.GetBytesChar(' ', new byte[] { 0x20, 0x00 }); - Helper.GetBytesChar('*', new byte[] { 0x2A, 0x00 }); - Helper.GetBytesChar('3', new byte[] { 0x33, 0x00 }); - Helper.GetBytesChar('A', new byte[] { 0x41, 0x00 }); - Helper.GetBytesChar('[', new byte[] { 0x5B, 0x00 }); - Helper.GetBytesChar('a', new byte[] { 0x61, 0x00 }); - Helper.GetBytesChar('{', new byte[] { 0x7B, 0x00 }); - Helper.GetBytesChar('测', new byte[] { 0x4B, 0x6D }); + Helper.GetBytesChar(value, expected); } [TestMethod] @@ -90,27 +92,39 @@ public void BitConverterTest_GetBytesDouble() } [TestMethod] - public void BitConverterTest_GetBytesInt16() + [DataRow((short)0, new byte[] { 0x00, 0x00 })] + [DataRow((short)15, new byte[] { 0x0F, 0x00 })] + [DataRow((short)-15, new byte[] { 0xF1, 0xFF })] + [DataRow((short)10000, new byte[] { 0x10, 0x27 })] + [DataRow((short)-10000, new byte[] { 0xF0, 0xD8 })] + public void BitConverterTest_GetBytesInt16(short value, byte[] expected) + { + Helper.GetBytesInt16(value, expected); + } + + [TestMethod] + public void BitConverterTest_GetBytesInt16_MinMax() { - Helper.GetBytesInt16(0, new byte[] { 0x00, 0x00 }); - Helper.GetBytesInt16(15, new byte[] { 0x0F, 0x00 }); - Helper.GetBytesInt16(-15, new byte[] { 0xF1, 0xFF }); - Helper.GetBytesInt16(10000, new byte[] { 0x10, 0x27 }); - Helper.GetBytesInt16(-10000, new byte[] { 0xF0, 0xD8 }); Helper.GetBytesInt16(short.MinValue, new byte[] { 0x00, 0x80 }); Helper.GetBytesInt16(short.MaxValue, new byte[] { 0xFF, 0x7F }); } [TestMethod] - public void BitConverterTest_GetBytesInt32() + [DataRow(0, new byte[] { 0x00, 0x00, 0x00, 0x00 })] + [DataRow(15, new byte[] { 0x0F, 0x00, 0x00, 0x00 })] + [DataRow(-15, new byte[] { 0xF1, 0xFF, 0xFF, 0xFF })] + [DataRow(1048576, new byte[] { 0x00, 0x00, 0x10, 0x00 })] + [DataRow(-1048576, new byte[] { 0x00, 0x00, 0xF0, 0xFF })] + [DataRow(1000000000, new byte[] { 0x00, 0xCA, 0x9A, 0x3B })] + [DataRow(-1000000000, new byte[] { 0x00, 0x36, 0x65, 0xC4 })] + public void BitConverterTest_GetBytesInt32(int value, byte[] expected) + { + Helper.GetBytesInt32(value, expected); + } + + [TestMethod] + public void BitConverterTest_GetBytesInt32_MinMax() { - Helper.GetBytesInt32(0, new byte[] { 0x00, 0x00, 0x00, 0x00 }); - Helper.GetBytesInt32(15, new byte[] { 0x0F, 0x00, 0x00, 0x00 }); - Helper.GetBytesInt32(-15, new byte[] { 0xF1, 0xFF, 0xFF, 0xFF }); - Helper.GetBytesInt32(1048576, new byte[] { 0x00, 0x00, 0x10, 0x00 }); - Helper.GetBytesInt32(-1048576, new byte[] { 0x00, 0x00, 0xF0, 0xFF }); - Helper.GetBytesInt32(1000000000, new byte[] { 0x00, 0xCA, 0x9A, 0x3B }); - Helper.GetBytesInt32(-1000000000, new byte[] { 0x00, 0x36, 0x65, 0xC4 }); Helper.GetBytesInt32(int.MinValue, new byte[] { 0x00, 0x00, 0x00, 0x80 }); Helper.GetBytesInt32(int.MaxValue, new byte[] { 0xFF, 0xFF, 0xFF, 0x7F }); } diff --git a/Tests/NFUnitTestSystemLib/UnitTestBoolean.cs b/Tests/NFUnitTestSystemLib/UnitTestBoolean.cs index 3461a9eb..51b94577 100644 --- a/Tests/NFUnitTestSystemLib/UnitTestBoolean.cs +++ b/Tests/NFUnitTestSystemLib/UnitTestBoolean.cs @@ -21,13 +21,11 @@ public void FalseString_Get_ReturnsFalse() } [TestMethod] - public void GetHashCode_Invoke_ReturnsExpected() + [DataRow(true, 1)] + [DataRow(false, 0)] + public void GetHashCode_Invoke_ReturnsExpected(bool value, int expected) { - bool _true = true; - bool _false = false; - - Assert.AreEqual(_true.GetHashCode(), 1); - Assert.AreEqual(_false.GetHashCode(), 0); + Assert.AreEqual(value.GetHashCode(), expected); } } } diff --git a/Tests/NFUnitTestSystemLib/UnitTestByte.cs b/Tests/NFUnitTestSystemLib/UnitTestByte.cs index 788b4187..994026b5 100644 --- a/Tests/NFUnitTestSystemLib/UnitTestByte.cs +++ b/Tests/NFUnitTestSystemLib/UnitTestByte.cs @@ -35,45 +35,57 @@ public void MinValue() } [TestMethod] - public void Equals() + [DataRow((byte)78, (byte)78, true)] + [DataRow((byte)78, (byte)0, false)] + [DataRow((byte)0, (byte)0, true)] + public void Equals_ByteToByte(byte b, byte obj, bool expected) { - ByteTestData[] testData = new ByteTestData[] + OutputHelper.WriteLine($"Testing combination {b} and {obj}"); + + if (expected) { - new ByteTestData((byte)78, (byte)78, true), - new ByteTestData((byte)78, (byte)0, false), - new ByteTestData((byte)0, (byte)0, true), - new ByteTestData((byte)78, null, false), - new ByteTestData((byte)78, "78", false), - new ByteTestData((byte)78, 78, false) - }; - - foreach (var test in testData) + Assert.AreEqual(b, obj); + Assert.IsTrue(b.GetHashCode().Equals(obj.GetHashCode())); + } + else { - OutputHelper.WriteLine($"Testing combination {test.B} and {test.Obj}"); + Assert.AreNotEqual(b, obj); + Assert.IsFalse(b.GetHashCode().Equals(obj.GetHashCode())); + } + Assert.AreEqual(b, b.GetHashCode()); + } - if (test.Obj is byte b2) - { - Assert.AreEqual(test.Expected, test.B.Equals(b2), $"Casting Obj wasn't successful for {test.Obj}"); - Assert.AreEqual(test.Expected, test.B.GetHashCode().Equals(b2.GetHashCode()), $"HashCode of {test.B}({test.B.GetHashCode()}) differs from the one of {b2}(b2.GetHashCode())"); - Assert.AreEqual((byte)test.B, test.B.GetHashCode(), $"HashCode of {(byte)test.B} different from expected, is {test.B.GetHashCode()}"); - } + [TestMethod] + public void Equals_ByteToNull() + { + byte b = 78; + object obj = null; - Assert.AreEqual(test.Expected, test.B.Equals(test.Obj), $"Equality test between {test.B} and {test.Obj} failed"); - } + OutputHelper.WriteLine($"Testing combination {b} and {obj}"); + + Assert.AreNotEqual(b, obj); + } + + [TestMethod] + public void Equals_ByteToString() + { + byte b = 78; + object obj = "78"; + + OutputHelper.WriteLine($"Testing combination {b} and {obj}"); + + Assert.AreNotEqual(b, obj); } - private sealed class ByteTestData + [TestMethod] + public void Equals_ByteToInt() { - public object B { get; } - public object Obj { get; } - public bool Expected { get; } + byte b = 78; + object obj = 78; - public ByteTestData(object b, object obj, bool expected) - { - B = b; - Obj = obj; - Expected = expected; - } + OutputHelper.WriteLine($"Testing combination {b} and {obj}"); + + Assert.AreNotEqual(b, obj); } } } diff --git a/Tests/NFUnitTestSystemLib/UnitTestInt16.cs b/Tests/NFUnitTestSystemLib/UnitTestInt16.cs index 7af03806..498ff307 100644 --- a/Tests/NFUnitTestSystemLib/UnitTestInt16.cs +++ b/Tests/NFUnitTestSystemLib/UnitTestInt16.cs @@ -35,46 +35,51 @@ public void MinValue() } [TestMethod] - public void Equals() + [DataRow((short)789, (short)789, true)] + [DataRow((short)789, (short)-789, false)] + [DataRow((short)789, (short)0, false)] + [DataRow((short)0, (short)0, true)] + [DataRow((short)-789, (short)-789, true)] + [DataRow((short)-789, (short)789, false)] + public void Equals_Int16ToInt16(short i1, short obj, bool expected) { - Int16TestData[] testData = new Int16TestData[] + if (expected) { - new Int16TestData((short)789, (short)789, true), - new Int16TestData((short)789, (short)-789, false), - new Int16TestData((short)789, (short)0, false), - new Int16TestData((short)0, (short)0, true), - new Int16TestData((short)-789, (short)-789, true), - new Int16TestData((short)-789, (short)789, false), - new Int16TestData((short)789, null, false), - new Int16TestData((short)789, "789", false), - new Int16TestData((short)789, 789, false) - }; - - foreach (var test in testData) + Assert.AreEqual(i1, obj); + Assert.IsTrue(i1.GetHashCode().Equals(obj.GetHashCode())); + } + else { - if (test.Obj is short) - { - short i2 = (short)test.Obj; - Assert.AreEqual(test.Expected, test.I1.Equals(i2)); - Assert.AreEqual(test.Expected, test.I1.GetHashCode().Equals(i2.GetHashCode())); - } - - Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj)); + Assert.AreNotEqual(i1, obj); + Assert.IsFalse(i1.GetHashCode().Equals(obj.GetHashCode())); } } - private sealed class Int16TestData + [TestMethod] + public void Equals_Int16ToNull() { - public object I1 { get; } - public object Obj { get; } - public bool Expected { get; } + short i1 = 789; + object obj = null; - public Int16TestData(object i1, object obj, bool expected) - { - I1 = i1; - Obj = obj; - Expected = expected; - } + Assert.AreNotEqual(i1, obj); + } + + [TestMethod] + public void Equals_Int16ToString() + { + short i1 = 789; + object obj = "789"; + + Assert.AreNotEqual(i1, obj); + } + + [TestMethod] + public void Equals_Int16ToInt() + { + short i1 = 789; + object obj = 789; + + Assert.AreNotEqual(i1, obj); } } } diff --git a/Tests/NFUnitTestSystemLib/UnitTestInt32.cs b/Tests/NFUnitTestSystemLib/UnitTestInt32.cs index a6e20ede..22de135e 100644 --- a/Tests/NFUnitTestSystemLib/UnitTestInt32.cs +++ b/Tests/NFUnitTestSystemLib/UnitTestInt32.cs @@ -35,45 +35,43 @@ public void MinValue() } [TestMethod] - public void Equals() + [DataRow(789, 789, true)] + [DataRow(789, -789, false)] + [DataRow(789, 0, false)] + [DataRow(0, 0, true)] + [DataRow(-789, -789, true)] + [DataRow(-789, 789, false)] + public void Equals_Int32ToInt32(int i1, int obj, bool expected) { - Int32TestData[] testData = new Int32TestData[] + if (expected) { - new Int32TestData((int)789, (int)789, true), - new Int32TestData((int)789, (int)-789, false), - new Int32TestData((int)789, (int)0, false), - new Int32TestData((int)0, (int)0, true), - new Int32TestData((int)-789, (int)-789, true), - new Int32TestData((int)-789, (int)789, false), - new Int32TestData((int)789, null, false), - new Int32TestData((int)89, "789", false), - }; - - foreach (var test in testData) + Assert.AreEqual(i1, obj); + Assert.IsTrue(i1.GetHashCode().Equals(obj.GetHashCode())); + } + else { - if (test.Obj is int) - { - int i2 = (int)test.Obj; - Assert.AreEqual(test.Expected, test.I1.Equals(i2)); - Assert.AreEqual(test.Expected, test.I1.GetHashCode().Equals(i2.GetHashCode())); - } - - Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj)); + Assert.AreNotEqual(i1, obj); + Assert.IsFalse(i1.GetHashCode().Equals(obj.GetHashCode())); } + Assert.AreEqual(i1, i1.GetHashCode()); } - private sealed class Int32TestData + [TestMethod] + public void Equals_Int32ToNull() { - public object I1 { get; } - public object Obj { get; } - public bool Expected { get; } + int i1 = 789; + object obj = null; - public Int32TestData(object i1, object obj, bool expected) - { - I1 = i1; - Obj = obj; - Expected = expected; - } + Assert.AreNotEqual(i1, obj); + } + + [TestMethod] + public void Equals_Int32ToString() + { + int i1 = 89; + object obj = "789"; + + Assert.AreNotEqual(i1, obj); } } } diff --git a/Tests/NFUnitTestSystemLib/UnitTestInt64.cs b/Tests/NFUnitTestSystemLib/UnitTestInt64.cs index 82b927ee..00e1b854 100644 --- a/Tests/NFUnitTestSystemLib/UnitTestInt64.cs +++ b/Tests/NFUnitTestSystemLib/UnitTestInt64.cs @@ -35,45 +35,42 @@ public void MinValue() } [TestMethod] - public void Equals() + [DataRow((long)789, (long)789, true)] + [DataRow((long)789, (long)-789, false)] + [DataRow((long)789, (long)0, false)] + [DataRow((long)0, (long)0, true)] + [DataRow((long)-789, (long)-789, true)] + [DataRow((long)-789, (long)789, false)] + public void Equals_LongToLong(long i1, long obj, bool expected) { - Int64TestData[] testData = new Int64TestData[] + if (expected) { - new Int64TestData((long)789, (long)789, true), - new Int64TestData((long)789, (long)-789, false), - new Int64TestData((long)789, (long)0, false), - new Int64TestData((long)0, (long)0, true), - new Int64TestData((long)-789, (long)-789, true), - new Int64TestData((long)-789, (long)789, false), - new Int64TestData((long)789, null, false), - new Int64TestData((long)789, "789", false), - }; - - foreach (var test in testData) + Assert.AreEqual(i1, obj); + Assert.IsTrue(i1.GetHashCode().Equals(obj.GetHashCode())); + } + else { - if (test.Obj is long) - { - long i2 = (long)test.Obj; - Assert.AreEqual(test.Expected, test.I1.Equals(i2)); - Assert.AreEqual(test.Expected, test.I1.GetHashCode().Equals(i2.GetHashCode())); - } - - Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj)); + Assert.AreNotEqual(i1, obj); + Assert.IsFalse(i1.GetHashCode().Equals(obj.GetHashCode())); } } - private sealed class Int64TestData + [TestMethod] + public void Equals_LongToNull() { - public object I1 { get; } - public object Obj { get; } - public bool Expected { get; } + long i1 = 789; + object obj = null; - public Int64TestData(object i1, object obj, bool expected) - { - I1 = i1; - Obj = obj; - Expected = expected; - } + Assert.AreNotEqual(i1, obj); + } + + [TestMethod] + public void Equals_LongToString() + { + long i1 = 789; + object obj = "789"; + + Assert.AreNotEqual(i1, obj); } } } diff --git a/Tests/NFUnitTestSystemLib/UnitTestSByte.cs b/Tests/NFUnitTestSystemLib/UnitTestSByte.cs index 46b907a2..c68c32f4 100644 --- a/Tests/NFUnitTestSystemLib/UnitTestSByte.cs +++ b/Tests/NFUnitTestSystemLib/UnitTestSByte.cs @@ -35,46 +35,52 @@ public void MinValue() } [TestMethod] - public void Equals() + [DataRow((sbyte)78, (sbyte)78, true)] + [DataRow((sbyte)78, (sbyte)-78, false)] + [DataRow((sbyte)78, (sbyte)0, false)] + [DataRow((sbyte)0, (sbyte)0, true)] + [DataRow((sbyte)-78, (sbyte)-78, true)] + [DataRow((sbyte)-78, (sbyte)78, false)] + public void Equals_SByteToSByte(sbyte b, sbyte obj, bool expected) { - SByteTestData[] testData = new SByteTestData[] + if (expected) { - new SByteTestData((sbyte)78, (sbyte)78, true), - new SByteTestData((sbyte)78, (sbyte)-78, false), - new SByteTestData((sbyte)78, (sbyte)0, false), - new SByteTestData((sbyte)0, (sbyte)0, true), - new SByteTestData((sbyte)-78, (sbyte)-78, true), - new SByteTestData((sbyte)-78, (sbyte)78, false), - new SByteTestData((sbyte)78, null, false), - new SByteTestData((sbyte)78, "78", false), - new SByteTestData((sbyte)78, 78, false) - }; - - foreach (var test in testData) + Assert.AreEqual(b, obj); + Assert.IsTrue(b.GetHashCode().Equals(obj.GetHashCode())); + } + else { - if (test.Obj is sbyte) - { - sbyte i2 = (sbyte)test.Obj; - Assert.AreEqual(test.Expected, test.B.Equals(i2)); - Assert.AreEqual(test.Expected, test.B.GetHashCode().Equals(i2.GetHashCode())); - } - - Assert.AreEqual(test.Expected, test.B.Equals(test.Obj)); + Assert.AreNotEqual(b, obj); + Assert.IsFalse(b.GetHashCode().Equals(obj.GetHashCode())); } + Assert.AreEqual(b, b.GetHashCode()); } - private sealed class SByteTestData + [TestMethod] + public void Equals_SByteToNull() { - public object B { get; } - public object Obj { get; } - public bool Expected { get; } + sbyte b = 78; + object obj = null; - public SByteTestData(object b, object obj, bool expected) - { - B = b; - Obj = obj; - Expected = expected; - } + Assert.AreNotEqual(b, obj); + } + + [TestMethod] + public void Equals_SByteToString() + { + sbyte b = 78; + object obj = "78"; + + Assert.AreNotEqual(b, obj); + } + + [TestMethod] + public void Equals_SByteToInt() + { + sbyte b = 78; + object obj = 78; + + Assert.AreNotEqual(b, obj); } } } diff --git a/Tests/NFUnitTestSystemLib/UnitTestUInt16.cs b/Tests/NFUnitTestSystemLib/UnitTestUInt16.cs index 53b19d6f..80ef0c55 100644 --- a/Tests/NFUnitTestSystemLib/UnitTestUInt16.cs +++ b/Tests/NFUnitTestSystemLib/UnitTestUInt16.cs @@ -35,43 +35,49 @@ public void MinValue() } [TestMethod] - public void Equals() + [DataRow((ushort)789, (ushort)789, true)] + [DataRow((ushort)788, (ushort)0, false)] + [DataRow((ushort)0, (ushort)0, true)] + public void Equals_UInt16ToUInt16(ushort i1, ushort obj, bool expected) { - UInt16TestData[] testData = new UInt16TestData[] + if (expected) { - new UInt16TestData((ushort)789, (ushort)789, true), - new UInt16TestData((ushort)788, (ushort)0, false), - new UInt16TestData((ushort)0, (ushort)0, true), - new UInt16TestData((ushort)789, null, false), - new UInt16TestData((ushort)789, "789", false), - new UInt16TestData((ushort)789, 789, false) - }; - - foreach (var test in testData) + Assert.AreEqual(i1, obj); + Assert.IsTrue(i1.GetHashCode().Equals(obj.GetHashCode())); + } + else { - if (test.Obj is ushort) - { - Assert.AreEqual(test.Expected, test.I1.Equals((ushort)test.Obj)); - Assert.AreEqual(test.Expected, test.I1.GetHashCode().Equals(((ushort)test.Obj).GetHashCode())); - Assert.AreEqual((ushort)test.I1, test.I1.GetHashCode()); - } - - Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj)); + Assert.AreNotEqual(i1, obj); + Assert.IsFalse(i1.GetHashCode().Equals(obj.GetHashCode())); } + Assert.AreEqual(i1, i1.GetHashCode()); } - private sealed class UInt16TestData + [TestMethod] + public void Equals_UInt16ToNull() { - public object I1 { get; } - public object Obj { get; } - public bool Expected { get; } + ushort i1 = 789; + object obj = null; - public UInt16TestData(object i1, object obj, bool expected) - { - I1 = i1; - Obj = obj; - Expected = expected; - } + Assert.AreNotEqual(i1, obj); + } + + [TestMethod] + public void Equals_UInt16ToString() + { + ushort i1 = 789; + object obj = "789"; + + Assert.AreNotEqual(i1, obj); + } + + [TestMethod] + public void Equals_UInt16ToInt() + { + ushort i1 = 789; + object obj = 789; + + Assert.AreNotEqual(i1, obj); } } } diff --git a/Tests/NFUnitTestSystemLib/UnitTestUInt32.cs b/Tests/NFUnitTestSystemLib/UnitTestUInt32.cs index 19f32666..026bb12a 100644 --- a/Tests/NFUnitTestSystemLib/UnitTestUInt32.cs +++ b/Tests/NFUnitTestSystemLib/UnitTestUInt32.cs @@ -35,44 +35,49 @@ public void MinValue() } [TestMethod] - public void Equals() + [DataRow((uint)789, (uint)789, true)] + [DataRow((uint)788, (uint)0, false)] + [DataRow((uint)0, (uint)0, true)] + public void Equals_UInt32ToUInt32(uint i1, uint obj, bool expected) { - UInt32TestData[] testData = new UInt32TestData[] + if (expected) { - new UInt32TestData((uint)789, (uint)789, true), - new UInt32TestData((uint)788, (uint)0, false), - new UInt32TestData((uint)0, (uint)0, true), - new UInt32TestData((uint)789, null, false), - new UInt32TestData((uint)789, "789", false), - new UInt32TestData((uint)789, 789, false) - }; - - foreach (var test in testData) + Assert.AreEqual(i1, obj); + Assert.IsTrue(i1.GetHashCode().Equals(obj.GetHashCode())); + } + else { - if (test.Obj is uint) - { - uint i2 = (uint)test.Obj; - Assert.AreEqual(test.Expected, test.I1.Equals(i2)); - Assert.AreEqual(test.Expected, test.I1.GetHashCode().Equals(i2.GetHashCode())); - Assert.AreEqual((uint)test.I1, test.I1.GetHashCode()); - } - - Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj)); + Assert.AreNotEqual(i1, obj); + Assert.IsFalse(i1.GetHashCode().Equals(obj.GetHashCode())); } + Assert.AreEqual(i1, i1.GetHashCode()); } - private sealed class UInt32TestData + [TestMethod] + public void Equals_UInt32ToNull() { - public object I1 { get; } - public object Obj { get; } - public bool Expected { get; } + uint i1 = 789; + object obj = null; - public UInt32TestData(object i1, object obj, bool expected) - { - I1 = i1; - Obj = obj; - Expected = expected; - } + Assert.AreNotEqual(i1, obj); + } + + [TestMethod] + public void Equals_UInt32ToString() + { + uint i1 = 789; + object obj = "789"; + + Assert.AreNotEqual(i1, obj); + } + + [TestMethod] + public void Equals_UInt32ToInt() + { + uint i1 = 789; + object obj = 789; + + Assert.AreNotEqual(i1, obj); } } } diff --git a/Tests/NFUnitTestSystemLib/UnitTestUInt64.cs b/Tests/NFUnitTestSystemLib/UnitTestUInt64.cs index 1863885f..862b23cd 100644 --- a/Tests/NFUnitTestSystemLib/UnitTestUInt64.cs +++ b/Tests/NFUnitTestSystemLib/UnitTestUInt64.cs @@ -35,45 +35,57 @@ public void MinValue() } [TestMethod] - public void Equals() + [DataRow((ulong)789, (ulong)789, true)] + [DataRow((ulong)789, (ulong)0, false)] + [DataRow((ulong)0, (ulong)0, true)] + public void Equals_UInt64ToUInt64(ulong i1, ulong obj, bool expected) { - UInt64TestData[] testData = new UInt64TestData[] + OutputHelper.WriteLine($"Testing combination {i1} and {obj}"); + + if (expected) { - new UInt64TestData((ulong)789, (ulong)789, true), - new UInt64TestData((ulong)789, (ulong)0, false), - new UInt64TestData((ulong)0, (ulong)0, true), - new UInt64TestData((ulong)789, null, false), - new UInt64TestData((ulong)789, "789", false), - new UInt64TestData((ulong)789, 789, false), - }; - - foreach (var test in testData) + Assert.AreEqual(i1, obj); + Assert.IsTrue(i1.GetHashCode().Equals(obj.GetHashCode())); + } + else { - OutputHelper.WriteLine($"Testing combination {test.I1} and {test.Obj}"); + Assert.AreNotEqual(i1, obj); + Assert.IsFalse(i1.GetHashCode().Equals(obj.GetHashCode())); + } + Assert.AreEqual(i1, i1.GetHashCode()); + } - if (test.Obj is ulong i2) - { - Assert.AreEqual(test.Expected, test.I1.Equals(i2)); - Assert.AreEqual(test.Expected, test.I1.GetHashCode().Equals(i2.GetHashCode())); - Assert.AreEqual((ulong)test.I1, test.I1.GetHashCode()); - } + [TestMethod] + public void Equals_UInt64ToNull() + { + ulong i1 = 789; + object obj = null; - Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj), $"Equality test between {test.I1} and {test.Obj} failed"); - } + OutputHelper.WriteLine($"Testing combination {i1} and {obj}"); + + Assert.AreNotEqual(i1, obj); + } + + [TestMethod] + public void Equals_UInt64ToString() + { + ulong i1 = 789; + object obj = "789"; + + OutputHelper.WriteLine($"Testing combination {i1} and {obj}"); + + Assert.AreNotEqual(i1, obj); } - private sealed class UInt64TestData + [TestMethod] + public void Equals_UInt64ToInt() { - public object I1 { get; } - public object Obj { get; } - public bool Expected { get; } + ulong i1 = 789; + object obj = 789; - public UInt64TestData(object i1, object obj, bool expected) - { - I1 = i1; - Obj = obj; - Expected = expected; - } + OutputHelper.WriteLine($"Testing combination {i1} and {obj}"); + + Assert.AreNotEqual(i1, obj); } } }