Skip to content

Commit 234c740

Browse files
authored
[BinaryPrimitives] Migrate to CollectionAssert.AreEqual replacing custom method (#1199)
1 parent 61b7376 commit 234c740

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

tests/BinaryPrimitivesUnitTests/BinaryPrimitivesTests.cs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void TestBeInt16()
3232
uint16res = BinaryPrimitives.ReadUInt16BigEndian(uint16byte);
3333

3434
// Assert
35-
CompareArray(int16byte, int16Res);
36-
CompareArray(uint16byte, uint16Res);
35+
CollectionAssert.AreEqual(int16byte, int16Res.ToArray());
36+
CollectionAssert.AreEqual(uint16byte, uint16Res.ToArray());
3737
Assert.AreEqual(int16, int16res);
3838
Assert.AreEqual(uint16, uint16res);
3939
}
@@ -58,8 +58,8 @@ public void TestLeInt16()
5858
uint16res = BinaryPrimitives.ReadUInt16LittleEndian(uint16byte);
5959

6060
// Assert
61-
CompareArray(int16byte, int16Res);
62-
CompareArray(uint16byte, uint16Res);
61+
CollectionAssert.AreEqual(int16byte, int16Res.ToArray());
62+
CollectionAssert.AreEqual(uint16byte, uint16Res.ToArray());
6363
Assert.AreEqual(int16, int16res);
6464
Assert.AreEqual(uint16, uint16res);
6565
}
@@ -84,8 +84,8 @@ public void TestBeInt32()
8484
uint32res = BinaryPrimitives.ReadUInt32BigEndian(uint32byte);
8585

8686
// Assert
87-
CompareArray(int32byte, intRes);
88-
CompareArray(uint32byte, uint32Res);
87+
CollectionAssert.AreEqual(int32byte, intRes.ToArray());
88+
CollectionAssert.AreEqual(uint32byte, uint32Res.ToArray());
8989
Assert.AreEqual(int32, int32res);
9090
Assert.AreEqual(uint32, uint32res);
9191
}
@@ -110,8 +110,8 @@ public void TestLeInt32()
110110
uint32res = BinaryPrimitives.ReadUInt32LittleEndian(uint32byte);
111111

112112
// Assert
113-
CompareArray(int32byte, intRes);
114-
CompareArray(uint32byte, uint32Res);
113+
CollectionAssert.AreEqual(int32byte, intRes.ToArray());
114+
CollectionAssert.AreEqual(uint32byte, uint32Res.ToArray());
115115
Assert.AreEqual(int32, int32res);
116116
Assert.AreEqual(uint32, uint32res);
117117
}
@@ -136,8 +136,8 @@ public void TestBeInt64()
136136
uint64res = BinaryPrimitives.ReadUInt64BigEndian(uint64byte);
137137

138138
// Assert
139-
CompareArray(int64byte, int64Res);
140-
CompareArray(uint64byte, uint64Res);
139+
CollectionAssert.AreEqual(int64byte, int64Res.ToArray());
140+
CollectionAssert.AreEqual(uint64byte, uint64Res.ToArray());
141141
Assert.AreEqual(int64, int64res);
142142
Assert.AreEqual(uint64, uint64res);
143143
}
@@ -162,8 +162,8 @@ public void TestLeInt64()
162162
uint64res = BinaryPrimitives.ReadUInt64LittleEndian(uint64byte);
163163

164164
// Assert
165-
CompareArray(int64byte, int64Res);
166-
CompareArray(uint64byte, uint64Res);
165+
CollectionAssert.AreEqual(int64byte, int64Res.ToArray());
166+
CollectionAssert.AreEqual(uint64byte, uint64Res.ToArray());
167167
Assert.AreEqual(int64, int64res);
168168
Assert.AreEqual(uint64, uint64res);
169169
}
@@ -202,7 +202,7 @@ public void TestBeSingle()
202202
floatValueFromBitConverter = BitConverter.IsLittleEndian ? BitConverter.ToSingle(Reverse(floatValueInBe), 0) : BitConverter.ToSingle(floatValueInBe, 0);
203203

204204
// Assert
205-
CompareArray(floatValueInBe, floatToBytes);
205+
CollectionAssert.AreEqual(floatValueInBe, floatToBytes.ToArray());
206206
Assert.AreEqual(floatValue, floatFromBytes);
207207
Assert.AreEqual(floatValue, floatValueFromBitConverter);
208208
Assert.AreEqual(floatValue, doubleFromBytes, "This assert fails when the CLR didn't properly convert the uint into a float");
@@ -226,7 +226,7 @@ public void TestLeSingle()
226226
floatValueFromBitConverter = BitConverter.IsLittleEndian ? BitConverter.ToSingle(floatValueInLe, 0) : BitConverter.ToSingle(Reverse(floatValueInLe), 0);
227227

228228
// Assert
229-
CompareArray(floatValueInLe, floatToBytes);
229+
CollectionAssert.AreEqual(floatValueInLe, floatToBytes.ToArray());
230230
Assert.AreEqual(floatValue, floatFromBytes);
231231
Assert.AreEqual(floatValue, floatValueFromBitConverter);
232232
Assert.AreEqual(floatValue, doubleFromBytes, "This assert fails when the CLR didn't properly convert the uint into a float");
@@ -248,7 +248,7 @@ public void TestBeDouble()
248248
doubleValueFromBitConverter = BitConverter.IsLittleEndian ? BitConverter.ToDouble(Reverse(doubleValueInBe), 0) : BitConverter.ToDouble(doubleValueInBe, 0);
249249

250250
// Assert
251-
CompareArray(doubleValueInBe, doubleToBytes);
251+
CollectionAssert.AreEqual(doubleValueInBe, doubleToBytes.ToArray());
252252
Assert.AreEqual(doubleValue, doubleFromBytes);
253253
Assert.AreEqual(doubleValue, doubleValueFromBitConverter);
254254
}
@@ -269,19 +269,11 @@ public void TestLeDouble()
269269
doubleValueFromBitConverter = BitConverter.IsLittleEndian ? BitConverter.ToDouble(doubleValueInLe, 0) : BitConverter.ToDouble(Reverse(doubleValueInLe), 0);
270270

271271
// Assert
272-
CompareArray(doubleValueInLe, doubleToBytes);
272+
CollectionAssert.AreEqual(doubleValueInLe, doubleToBytes.ToArray());
273273
Assert.AreEqual(doubleValue, doubleFromBytes);
274274
Assert.AreEqual(doubleValue, doubleValueFromBitConverter);
275275
}
276276

277-
private void CompareArray(SpanByte array1, SpanByte array2)
278-
{
279-
for (int i = 0; i < array1.Length; i++)
280-
{
281-
Assert.AreEqual(array1[i], array2[i]);
282-
}
283-
}
284-
285277
private byte[] Reverse(byte[] array)
286278
{
287279
if (array == null || array.Length <= 1)

0 commit comments

Comments
 (0)