Skip to content

Commit a67553f

Browse files
authored
Add F0 and N0 format tests for float and double ToString() (#255)
***NO_CI***
1 parent d47412e commit a67553f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
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

0 commit comments

Comments
 (0)