Skip to content

Commit c0ab655

Browse files
Copilotjosesimoes
andcommitted
Migrate UInt32 and UInt64 tests to use DataRow
Co-authored-by: josesimoes <[email protected]>
1 parent 9882b36 commit c0ab655

File tree

2 files changed

+56
-65
lines changed

2 files changed

+56
-65
lines changed

Tests/NFUnitTestSystemLib/UnitTestUInt32.cs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,38 @@ public void MinValue()
3535
}
3636

3737
[TestMethod]
38-
public void Equals()
38+
[DataRow((uint)789, (uint)789, true)]
39+
[DataRow((uint)788, (uint)0, false)]
40+
[DataRow((uint)0, (uint)0, true)]
41+
public void Equals_UInt32ToUInt32(uint i1, uint obj, bool expected)
3942
{
40-
UInt32TestData[] testData = new UInt32TestData[]
41-
{
42-
new UInt32TestData((uint)789, (uint)789, true),
43-
new UInt32TestData((uint)788, (uint)0, false),
44-
new UInt32TestData((uint)0, (uint)0, true),
45-
new UInt32TestData((uint)789, null, false),
46-
new UInt32TestData((uint)789, "789", false),
47-
new UInt32TestData((uint)789, 789, false)
48-
};
49-
50-
foreach (var test in testData)
51-
{
52-
if (test.Obj is uint)
53-
{
54-
uint i2 = (uint)test.Obj;
55-
Assert.AreEqual(test.Expected, test.I1.Equals(i2));
56-
Assert.AreEqual(test.Expected, test.I1.GetHashCode().Equals(i2.GetHashCode()));
57-
Assert.AreEqual((uint)test.I1, test.I1.GetHashCode());
58-
}
43+
Assert.AreEqual(expected, i1.Equals(obj));
44+
Assert.AreEqual(expected, i1.GetHashCode().Equals(obj.GetHashCode()));
45+
Assert.AreEqual(i1, i1.GetHashCode());
46+
}
5947

60-
Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj));
61-
}
48+
[TestMethod]
49+
public void Equals_UInt32ToNull()
50+
{
51+
uint i1 = 789;
52+
object obj = null;
53+
Assert.AreEqual(false, i1.Equals(obj));
6254
}
6355

64-
private sealed class UInt32TestData
56+
[TestMethod]
57+
public void Equals_UInt32ToString()
6558
{
66-
public object I1 { get; }
67-
public object Obj { get; }
68-
public bool Expected { get; }
59+
uint i1 = 789;
60+
object obj = "789";
61+
Assert.AreEqual(false, i1.Equals(obj));
62+
}
6963

70-
public UInt32TestData(object i1, object obj, bool expected)
71-
{
72-
I1 = i1;
73-
Obj = obj;
74-
Expected = expected;
75-
}
64+
[TestMethod]
65+
public void Equals_UInt32ToInt()
66+
{
67+
uint i1 = 789;
68+
object obj = 789;
69+
Assert.AreEqual(false, i1.Equals(obj));
7670
}
7771
}
7872
}

Tests/NFUnitTestSystemLib/UnitTestUInt64.cs

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,42 @@ public void MinValue()
3535
}
3636

3737
[TestMethod]
38-
public void Equals()
38+
[DataRow((ulong)789, (ulong)789, true)]
39+
[DataRow((ulong)789, (ulong)0, false)]
40+
[DataRow((ulong)0, (ulong)0, true)]
41+
public void Equals_UInt64ToUInt64(ulong i1, ulong obj, bool expected)
3942
{
40-
UInt64TestData[] testData = new UInt64TestData[]
41-
{
42-
new UInt64TestData((ulong)789, (ulong)789, true),
43-
new UInt64TestData((ulong)789, (ulong)0, false),
44-
new UInt64TestData((ulong)0, (ulong)0, true),
45-
new UInt64TestData((ulong)789, null, false),
46-
new UInt64TestData((ulong)789, "789", false),
47-
new UInt64TestData((ulong)789, 789, false),
48-
};
49-
50-
foreach (var test in testData)
51-
{
52-
OutputHelper.WriteLine($"Testing combination {test.I1} and {test.Obj}");
53-
54-
if (test.Obj is ulong i2)
55-
{
56-
Assert.AreEqual(test.Expected, test.I1.Equals(i2));
57-
Assert.AreEqual(test.Expected, test.I1.GetHashCode().Equals(i2.GetHashCode()));
58-
Assert.AreEqual((ulong)test.I1, test.I1.GetHashCode());
59-
}
43+
OutputHelper.WriteLine($"Testing combination {i1} and {obj}");
44+
Assert.AreEqual(expected, i1.Equals(obj), $"Equality test between {i1} and {obj} failed");
45+
Assert.AreEqual(expected, i1.GetHashCode().Equals(obj.GetHashCode()));
46+
Assert.AreEqual(i1, i1.GetHashCode());
47+
}
6048

61-
Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj), $"Equality test between {test.I1} and {test.Obj} failed");
62-
}
49+
[TestMethod]
50+
public void Equals_UInt64ToNull()
51+
{
52+
ulong i1 = 789;
53+
object obj = null;
54+
OutputHelper.WriteLine($"Testing combination {i1} and {obj}");
55+
Assert.AreEqual(false, i1.Equals(obj), $"Equality test between {i1} and {obj} failed");
6356
}
6457

65-
private sealed class UInt64TestData
58+
[TestMethod]
59+
public void Equals_UInt64ToString()
6660
{
67-
public object I1 { get; }
68-
public object Obj { get; }
69-
public bool Expected { get; }
61+
ulong i1 = 789;
62+
object obj = "789";
63+
OutputHelper.WriteLine($"Testing combination {i1} and {obj}");
64+
Assert.AreEqual(false, i1.Equals(obj), $"Equality test between {i1} and {obj} failed");
65+
}
7066

71-
public UInt64TestData(object i1, object obj, bool expected)
72-
{
73-
I1 = i1;
74-
Obj = obj;
75-
Expected = expected;
76-
}
67+
[TestMethod]
68+
public void Equals_UInt64ToInt()
69+
{
70+
ulong i1 = 789;
71+
object obj = 789;
72+
OutputHelper.WriteLine($"Testing combination {i1} and {obj}");
73+
Assert.AreEqual(false, i1.Equals(obj), $"Equality test between {i1} and {obj} failed");
7774
}
7875
}
7976
}

0 commit comments

Comments
 (0)