Skip to content

Commit

Permalink
test(format): add some basic unit tests for Format::Number
Browse files Browse the repository at this point in the history
  • Loading branch information
tehhowch committed Aug 12, 2021
1 parent ddd7062 commit 1ecd2d2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/src/text/test_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ TEST_CASE( "Format::Capitalize", "[Format][Capitalize]") {
}
}

TEST_CASE( "Format::Number", "[Format][Number]") {
SECTION( "0-valued inputs" ) {
CHECK( Format::Number(-0) == "0" );
CHECK( Format::Number(0) == "0" );
CHECK( Format::Number(-.0) == "0" );
CHECK( Format::Number(.0) == "0" );
}
SECTION( "Integral inputs" ) {
CHECK( Format::Number(1) == "1" );
CHECK( Format::Number(-1.) == "-1" );
CHECK( Format::Number(1000.) == "1,000" );
}
SECTION( "Decimals between 0 and 1" ) {
CHECK( Format::Number(0.51) == "0.5" );
CHECK( Format::Number(0.56) == "0.6" );
}
}

// #endregion unit tests

// #region benchmarks
Expand All @@ -136,6 +154,17 @@ TEST_CASE( "Benchmark Format::PlayTime", "[!benchmark][format]" ) {
return Format::PlayTime(std::numeric_limits<int>::max());
};
}
TEST_CASE( "Benchmark Format::Number", "[!benchmark][format]" ) {
BENCHMARK( "Format::Number(0.)" ) {
return Format::Number(0.);
};
BENCHMARK( "Format::Number(100.)" ) {
return Format::Number(100.);
};
BENCHMARK( "Format::Number(-10.312345)" ) {
return Format::Number(-10.312345);
};
}
#endif

} // test namespace

0 comments on commit 1ecd2d2

Please sign in to comment.