Skip to content

Commit 7c0182d

Browse files
committed
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary into develop
***NO_CI***
2 parents 668efa7 + acfc7d3 commit 7c0182d

File tree

11 files changed

+367
-278
lines changed

11 files changed

+367
-278
lines changed

Tests/NFUnitTestArithmetic/UnitTestFormat.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,37 @@ public void FixedFormat()
103103

104104
TestFormat("0", "F", "0.00");
105105
TestFormat("0", "F4", "0.0000");
106+
TestFormat("0", "F0", "0");
106107
TestFormat("123", "F", "123.00");
108+
TestFormat("123", "F0", "123");
107109
TestFormat("129", "F", "129.00");
108110
TestFormat("-129", "F", "-129.00");
111+
TestFormat("-129", "F0", "-129");
109112
TestFormat("128", "F", "128.00");
110113
TestFormat("128", "F4", "128.0000");
114+
TestFormat("128", "F0", "128");
111115
TestFormat("-128", "F", "-128.00");
112116
TestFormat("-128", "F2", "-128.00");
117+
TestFormat("-128", "F0", "-128");
113118
TestFormat("1234", "F2", "1234.00");
119+
TestFormat("1234", "F0", "1234");
114120
TestFormat("-1234", "F", "-1234.00");
121+
TestFormat("-1234", "F0", "-1234");
115122
TestFormat("1234", "F6", "1234.000000");
116123
TestFormat("-1234", "F6", "-1234.000000");
117124
TestFormat("123.78", "F3", "123.780");
118125
TestFormat("123.78", "F1", "123.8");
126+
TestFormat("123.78", "F0", "124");
119127
TestFormat("1234.8999", "F3", "1234.900");
128+
TestFormat("1234.8999", "F0", "1235");
129+
TestFormat("-1234.8999", "F0", "-1235");
130+
// Test cases from issue #1650
131+
TestFormat("9.8999", "F", "9.90");
132+
TestFormat("9.8999", "F0", "10");
133+
TestFormat("9.8999", "F1", "9.9");
134+
TestFormat("99.8999", "F", "99.90");
135+
TestFormat("99.8999", "F0", "100");
136+
TestFormat("99.8999", "F1", "99.9");
120137

121138
sampleDisplay.WriteOutput();
122139

@@ -240,21 +257,40 @@ public void NumberFormat()
240257
sampleDisplay = new SampleDisplay();
241258

242259
TestFormat("123", "N", "123.00"); // default for CultureInvariant is 2 decimal places
260+
TestFormat("123", "N0", "123");
243261
TestFormat("129", "N", "129.00");
262+
TestFormat("129", "N0", "129");
244263
TestFormat("-129", "N", "-129.00");
264+
TestFormat("-129", "N0", "-129");
245265
TestFormat("128", "N", "128.00");
246266
TestFormat("128", "N4", "128.0000");
267+
TestFormat("128", "N0", "128");
247268
TestFormat("-128", "N", "-128.00");
248269
TestFormat("-128", "N2", "-128.00");
270+
TestFormat("-128", "N0", "-128");
249271
TestFormat("1234", "N2", "1,234.00");
272+
TestFormat("1234", "N0", "1,234");
250273
TestFormat("-1234", "N", "-1,234.00");
274+
TestFormat("-1234", "N0", "-1,234");
251275
TestFormat("1234", "N6", "1,234.000000");
252276
TestFormat("-1234", "N6", "-1,234.000000");
253277
TestFormat("1234.567", "N2", "1,234.57");
278+
TestFormat("1234.567", "N0", "1,235");
254279
TestFormat("-1234.567", "N2", "-1,234.57");
280+
TestFormat("-1234.567", "N0", "-1,235");
255281
TestFormat("123456.78", "N2", "123,456.78");
282+
TestFormat("123456.78", "N0", "123,457");
256283
TestFormat("1234567.1210", "N2", "1,234,567.12");
284+
TestFormat("1234567.1210", "N0", "1,234,567");
257285
TestFormat("-0.099999999999999978", "N2", "-0.10");
286+
TestFormat("-0.099999999999999978", "N0", "0");
287+
// Test cases from issue #1650
288+
TestFormat("9.8999", "N", "9.90");
289+
TestFormat("9.8999", "N0", "10");
290+
TestFormat("9.8999", "N1", "9.9");
291+
TestFormat("99.8999", "N", "99.90");
292+
TestFormat("99.8999", "N0", "100");
293+
TestFormat("99.8999", "N1", "99.9");
258294
sampleDisplay.WriteOutput();
259295
}
260296

Tests/NFUnitTestBitConverter/BitConverter.cs

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,26 @@ public void BitConverterTest_DoubleToInt64Bits()
4747
}
4848

4949
[TestMethod]
50-
public void BitConverterTest_GetBytesBool()
50+
[DataRow(true, new byte[] { 1 })]
51+
[DataRow(false, new byte[] { 0 })]
52+
public void BitConverterTest_GetBytesBool(bool value, byte[] expected)
5153
{
52-
Helper.GetBytesBool(true, new byte[] { 1 });
53-
Helper.GetBytesBool(false, new byte[] { 0 });
54+
Helper.GetBytesBool(value, expected);
5455
}
5556

5657
[TestMethod]
57-
public void BitConverterTest_GetBytesChar()
58+
[DataRow('\0', new byte[] { 0x00, 0x00 })]
59+
[DataRow(' ', new byte[] { 0x20, 0x00 })]
60+
[DataRow('*', new byte[] { 0x2A, 0x00 })]
61+
[DataRow('3', new byte[] { 0x33, 0x00 })]
62+
[DataRow('A', new byte[] { 0x41, 0x00 })]
63+
[DataRow('[', new byte[] { 0x5B, 0x00 })]
64+
[DataRow('a', new byte[] { 0x61, 0x00 })]
65+
[DataRow('{', new byte[] { 0x7B, 0x00 })]
66+
[DataRow('测', new byte[] { 0x4B, 0x6D })]
67+
public void BitConverterTest_GetBytesChar(char value, byte[] expected)
5868
{
59-
Helper.GetBytesChar('\0', new byte[] { 0x00, 0x00 });
60-
Helper.GetBytesChar(' ', new byte[] { 0x20, 0x00 });
61-
Helper.GetBytesChar('*', new byte[] { 0x2A, 0x00 });
62-
Helper.GetBytesChar('3', new byte[] { 0x33, 0x00 });
63-
Helper.GetBytesChar('A', new byte[] { 0x41, 0x00 });
64-
Helper.GetBytesChar('[', new byte[] { 0x5B, 0x00 });
65-
Helper.GetBytesChar('a', new byte[] { 0x61, 0x00 });
66-
Helper.GetBytesChar('{', new byte[] { 0x7B, 0x00 });
67-
Helper.GetBytesChar('测', new byte[] { 0x4B, 0x6D });
69+
Helper.GetBytesChar(value, expected);
6870
}
6971

7072
[TestMethod]
@@ -90,27 +92,39 @@ public void BitConverterTest_GetBytesDouble()
9092
}
9193

9294
[TestMethod]
93-
public void BitConverterTest_GetBytesInt16()
95+
[DataRow((short)0, new byte[] { 0x00, 0x00 })]
96+
[DataRow((short)15, new byte[] { 0x0F, 0x00 })]
97+
[DataRow((short)-15, new byte[] { 0xF1, 0xFF })]
98+
[DataRow((short)10000, new byte[] { 0x10, 0x27 })]
99+
[DataRow((short)-10000, new byte[] { 0xF0, 0xD8 })]
100+
public void BitConverterTest_GetBytesInt16(short value, byte[] expected)
101+
{
102+
Helper.GetBytesInt16(value, expected);
103+
}
104+
105+
[TestMethod]
106+
public void BitConverterTest_GetBytesInt16_MinMax()
94107
{
95-
Helper.GetBytesInt16(0, new byte[] { 0x00, 0x00 });
96-
Helper.GetBytesInt16(15, new byte[] { 0x0F, 0x00 });
97-
Helper.GetBytesInt16(-15, new byte[] { 0xF1, 0xFF });
98-
Helper.GetBytesInt16(10000, new byte[] { 0x10, 0x27 });
99-
Helper.GetBytesInt16(-10000, new byte[] { 0xF0, 0xD8 });
100108
Helper.GetBytesInt16(short.MinValue, new byte[] { 0x00, 0x80 });
101109
Helper.GetBytesInt16(short.MaxValue, new byte[] { 0xFF, 0x7F });
102110
}
103111

104112
[TestMethod]
105-
public void BitConverterTest_GetBytesInt32()
113+
[DataRow(0, new byte[] { 0x00, 0x00, 0x00, 0x00 })]
114+
[DataRow(15, new byte[] { 0x0F, 0x00, 0x00, 0x00 })]
115+
[DataRow(-15, new byte[] { 0xF1, 0xFF, 0xFF, 0xFF })]
116+
[DataRow(1048576, new byte[] { 0x00, 0x00, 0x10, 0x00 })]
117+
[DataRow(-1048576, new byte[] { 0x00, 0x00, 0xF0, 0xFF })]
118+
[DataRow(1000000000, new byte[] { 0x00, 0xCA, 0x9A, 0x3B })]
119+
[DataRow(-1000000000, new byte[] { 0x00, 0x36, 0x65, 0xC4 })]
120+
public void BitConverterTest_GetBytesInt32(int value, byte[] expected)
121+
{
122+
Helper.GetBytesInt32(value, expected);
123+
}
124+
125+
[TestMethod]
126+
public void BitConverterTest_GetBytesInt32_MinMax()
106127
{
107-
Helper.GetBytesInt32(0, new byte[] { 0x00, 0x00, 0x00, 0x00 });
108-
Helper.GetBytesInt32(15, new byte[] { 0x0F, 0x00, 0x00, 0x00 });
109-
Helper.GetBytesInt32(-15, new byte[] { 0xF1, 0xFF, 0xFF, 0xFF });
110-
Helper.GetBytesInt32(1048576, new byte[] { 0x00, 0x00, 0x10, 0x00 });
111-
Helper.GetBytesInt32(-1048576, new byte[] { 0x00, 0x00, 0xF0, 0xFF });
112-
Helper.GetBytesInt32(1000000000, new byte[] { 0x00, 0xCA, 0x9A, 0x3B });
113-
Helper.GetBytesInt32(-1000000000, new byte[] { 0x00, 0x36, 0x65, 0xC4 });
114128
Helper.GetBytesInt32(int.MinValue, new byte[] { 0x00, 0x00, 0x00, 0x80 });
115129
Helper.GetBytesInt32(int.MaxValue, new byte[] { 0xFF, 0xFF, 0xFF, 0x7F });
116130
}

Tests/NFUnitTestSystemLib/UnitTestBoolean.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ public void FalseString_Get_ReturnsFalse()
2121
}
2222

2323
[TestMethod]
24-
public void GetHashCode_Invoke_ReturnsExpected()
24+
[DataRow(true, 1)]
25+
[DataRow(false, 0)]
26+
public void GetHashCode_Invoke_ReturnsExpected(bool value, int expected)
2527
{
26-
bool _true = true;
27-
bool _false = false;
28-
29-
Assert.AreEqual(_true.GetHashCode(), 1);
30-
Assert.AreEqual(_false.GetHashCode(), 0);
28+
Assert.AreEqual(value.GetHashCode(), expected);
3129
}
3230
}
3331
}

Tests/NFUnitTestSystemLib/UnitTestByte.cs

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

3737
[TestMethod]
38-
public void Equals()
38+
[DataRow((byte)78, (byte)78, true)]
39+
[DataRow((byte)78, (byte)0, false)]
40+
[DataRow((byte)0, (byte)0, true)]
41+
public void Equals_ByteToByte(byte b, byte obj, bool expected)
3942
{
40-
ByteTestData[] testData = new ByteTestData[]
43+
OutputHelper.WriteLine($"Testing combination {b} and {obj}");
44+
45+
if (expected)
4146
{
42-
new ByteTestData((byte)78, (byte)78, true),
43-
new ByteTestData((byte)78, (byte)0, false),
44-
new ByteTestData((byte)0, (byte)0, true),
45-
new ByteTestData((byte)78, null, false),
46-
new ByteTestData((byte)78, "78", false),
47-
new ByteTestData((byte)78, 78, false)
48-
};
49-
50-
foreach (var test in testData)
47+
Assert.AreEqual(b, obj);
48+
Assert.IsTrue(b.GetHashCode().Equals(obj.GetHashCode()));
49+
}
50+
else
5151
{
52-
OutputHelper.WriteLine($"Testing combination {test.B} and {test.Obj}");
52+
Assert.AreNotEqual(b, obj);
53+
Assert.IsFalse(b.GetHashCode().Equals(obj.GetHashCode()));
54+
}
55+
Assert.AreEqual(b, b.GetHashCode());
56+
}
5357

54-
if (test.Obj is byte b2)
55-
{
56-
Assert.AreEqual(test.Expected, test.B.Equals(b2), $"Casting Obj wasn't successful for {test.Obj}");
57-
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())");
58-
Assert.AreEqual((byte)test.B, test.B.GetHashCode(), $"HashCode of {(byte)test.B} different from expected, is {test.B.GetHashCode()}");
59-
}
58+
[TestMethod]
59+
public void Equals_ByteToNull()
60+
{
61+
byte b = 78;
62+
object obj = null;
6063

61-
Assert.AreEqual(test.Expected, test.B.Equals(test.Obj), $"Equality test between {test.B} and {test.Obj} failed");
62-
}
64+
OutputHelper.WriteLine($"Testing combination {b} and {obj}");
65+
66+
Assert.AreNotEqual(b, obj);
67+
}
68+
69+
[TestMethod]
70+
public void Equals_ByteToString()
71+
{
72+
byte b = 78;
73+
object obj = "78";
74+
75+
OutputHelper.WriteLine($"Testing combination {b} and {obj}");
76+
77+
Assert.AreNotEqual(b, obj);
6378
}
6479

65-
private sealed class ByteTestData
80+
[TestMethod]
81+
public void Equals_ByteToInt()
6682
{
67-
public object B { get; }
68-
public object Obj { get; }
69-
public bool Expected { get; }
83+
byte b = 78;
84+
object obj = 78;
7085

71-
public ByteTestData(object b, object obj, bool expected)
72-
{
73-
B = b;
74-
Obj = obj;
75-
Expected = expected;
76-
}
86+
OutputHelper.WriteLine($"Testing combination {b} and {obj}");
87+
88+
Assert.AreNotEqual(b, obj);
7789
}
7890
}
7991
}

Tests/NFUnitTestSystemLib/UnitTestInt16.cs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,46 +35,51 @@ 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[]
46+
if (expected)
4147
{
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)
48+
Assert.AreEqual(i1, obj);
49+
Assert.IsTrue(i1.GetHashCode().Equals(obj.GetHashCode()));
50+
}
51+
else
5452
{
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-
}
61-
62-
Assert.AreEqual(test.Expected, test.I1.Equals(test.Obj));
53+
Assert.AreNotEqual(i1, obj);
54+
Assert.IsFalse(i1.GetHashCode().Equals(obj.GetHashCode()));
6355
}
6456
}
6557

66-
private sealed class Int16TestData
58+
[TestMethod]
59+
public void Equals_Int16ToNull()
6760
{
68-
public object I1 { get; }
69-
public object Obj { get; }
70-
public bool Expected { get; }
61+
short i1 = 789;
62+
object obj = null;
7163

72-
public Int16TestData(object i1, object obj, bool expected)
73-
{
74-
I1 = i1;
75-
Obj = obj;
76-
Expected = expected;
77-
}
64+
Assert.AreNotEqual(i1, obj);
65+
}
66+
67+
[TestMethod]
68+
public void Equals_Int16ToString()
69+
{
70+
short i1 = 789;
71+
object obj = "789";
72+
73+
Assert.AreNotEqual(i1, obj);
74+
}
75+
76+
[TestMethod]
77+
public void Equals_Int16ToInt()
78+
{
79+
short i1 = 789;
80+
object obj = 789;
81+
82+
Assert.AreNotEqual(i1, obj);
7883
}
7984
}
8085
}

0 commit comments

Comments
 (0)