Skip to content

Commit d616d12

Browse files
committed
Adding test code for print(double, int = 2)
1 parent dd4467c commit d616d12

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/src/Print/test_print.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,28 @@ TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-pr
9595
WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); }
9696
WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); }
9797
}
98+
99+
TEST_CASE ("Print::print(double, int = 2)", "[Print-print-07]")
100+
{
101+
PrintMock mock;
102+
103+
WHEN ("val is a positive floating point value")
104+
{
105+
double const val = 3.1459;
106+
WHEN("digits = 0") { mock.print(val, 0); REQUIRE(mock._str == "3"); }
107+
WHEN("digits = 1") { mock.print(val, 1); REQUIRE(mock._str == "3.1"); }
108+
WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "3.15"); }
109+
WHEN("digits = 3") { mock.print(val, 3); REQUIRE(mock._str == "3.146"); }
110+
WHEN("digits = 4") { mock.print(val, 4); REQUIRE(mock._str == "3.1459"); }
111+
WHEN("digits = 5") { mock.print(val, 5); REQUIRE(mock._str == "3.14590"); }
112+
}
113+
114+
WHEN ("val is a negative floating point value")
115+
{
116+
double const val = -3.1459;
117+
WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "-3.15"); }
118+
}
119+
120+
WHEN ("val is NAN") { mock.print(NAN); REQUIRE(mock._str == "nan"); }
121+
WHEN ("val is INFINITY") { mock.print(INFINITY); REQUIRE(mock._str == "inf"); }
122+
}

0 commit comments

Comments
 (0)