Skip to content

Commit 80f7f6c

Browse files
Copilotjosesimoes
andcommitted
Migrate Int16, Int32, and UInt16 tests to use DataRow
Co-authored-by: josesimoes <[email protected]>
1 parent c0ab655 commit 80f7f6c

File tree

3 files changed

+75
-99
lines changed

3 files changed

+75
-99
lines changed

Tests/NFUnitTestSystemLib/UnitTestInt16.cs

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,46 +35,40 @@ public void MinValue()
3535
}
3636

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

62-
Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj));
63-
}
50+
[TestMethod]
51+
public void Equals_Int16ToNull()
52+
{
53+
short i1 = 789;
54+
object obj = null;
55+
Assert.AreEqual(false, i1.Equals(obj));
6456
}
6557

66-
private sealed class Int16TestData
58+
[TestMethod]
59+
public void Equals_Int16ToString()
6760
{
68-
public object I1 { get; }
69-
public object Obj { get; }
70-
public bool Expected { get; }
61+
short i1 = 789;
62+
object obj = "789";
63+
Assert.AreEqual(false, i1.Equals(obj));
64+
}
7165

72-
public Int16TestData(object i1, object obj, bool expected)
73-
{
74-
I1 = i1;
75-
Obj = obj;
76-
Expected = expected;
77-
}
66+
[TestMethod]
67+
public void Equals_Int16ToInt()
68+
{
69+
short i1 = 789;
70+
object obj = 789;
71+
Assert.AreEqual(false, i1.Equals(obj));
7872
}
7973
}
8074
}

Tests/NFUnitTestSystemLib/UnitTestInt32.cs

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

3737
[TestMethod]
38-
public void Equals()
38+
[DataRow(789, 789, true)]
39+
[DataRow(789, -789, false)]
40+
[DataRow(789, 0, false)]
41+
[DataRow(0, 0, true)]
42+
[DataRow(-789, -789, true)]
43+
[DataRow(-789, 789, false)]
44+
public void Equals_Int32ToInt32(int i1, int obj, bool expected)
3945
{
40-
Int32TestData[] testData = new Int32TestData[]
41-
{
42-
new Int32TestData((int)789, (int)789, true),
43-
new Int32TestData((int)789, (int)-789, false),
44-
new Int32TestData((int)789, (int)0, false),
45-
new Int32TestData((int)0, (int)0, true),
46-
new Int32TestData((int)-789, (int)-789, true),
47-
new Int32TestData((int)-789, (int)789, false),
48-
new Int32TestData((int)789, null, false),
49-
new Int32TestData((int)89, "789", false),
50-
};
51-
52-
foreach (var test in testData)
53-
{
54-
if (test.Obj is int)
55-
{
56-
int i2 = (int)test.Obj;
57-
Assert.AreEqual(test.Expected, test.I1.Equals(i2));
58-
Assert.AreEqual(test.Expected, test.I1.GetHashCode().Equals(i2.GetHashCode()));
59-
}
60-
61-
Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj));
62-
}
46+
Assert.AreEqual(expected, i1.Equals(obj));
47+
Assert.AreEqual(expected, i1.GetHashCode().Equals(obj.GetHashCode()));
6348
}
6449

65-
private sealed class Int32TestData
50+
[TestMethod]
51+
public void Equals_Int32ToNull()
6652
{
67-
public object I1 { get; }
68-
public object Obj { get; }
69-
public bool Expected { get; }
53+
int i1 = 789;
54+
object obj = null;
55+
Assert.AreEqual(false, i1.Equals(obj));
56+
}
7057

71-
public Int32TestData(object i1, object obj, bool expected)
72-
{
73-
I1 = i1;
74-
Obj = obj;
75-
Expected = expected;
76-
}
58+
[TestMethod]
59+
public void Equals_Int32ToString()
60+
{
61+
int i1 = 89;
62+
object obj = "789";
63+
Assert.AreEqual(false, i1.Equals(obj));
7764
}
7865
}
7966
}

Tests/NFUnitTestSystemLib/UnitTestUInt16.cs

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

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

59-
Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj));
60-
}
48+
[TestMethod]
49+
public void Equals_UInt16ToNull()
50+
{
51+
ushort i1 = 789;
52+
object obj = null;
53+
Assert.AreEqual(false, i1.Equals(obj));
6154
}
6255

63-
private sealed class UInt16TestData
56+
[TestMethod]
57+
public void Equals_UInt16ToString()
6458
{
65-
public object I1 { get; }
66-
public object Obj { get; }
67-
public bool Expected { get; }
59+
ushort i1 = 789;
60+
object obj = "789";
61+
Assert.AreEqual(false, i1.Equals(obj));
62+
}
6863

69-
public UInt16TestData(object i1, object obj, bool expected)
70-
{
71-
I1 = i1;
72-
Obj = obj;
73-
Expected = expected;
74-
}
64+
[TestMethod]
65+
public void Equals_UInt16ToInt()
66+
{
67+
ushort i1 = 789;
68+
object obj = 789;
69+
Assert.AreEqual(false, i1.Equals(obj));
7570
}
7671
}
7772
}

0 commit comments

Comments
 (0)