Format infinity.

This commit is contained in:
Victor Zverovich
2012-12-29 06:44:14 -08:00
parent 529045b65d
commit 4762a8afd0
3 changed files with 30 additions and 6 deletions
+12 -4
View File
@@ -774,10 +774,6 @@ TEST(FormatterTest, FormatDouble) {
sprintf(buffer, "%E", 392.65);
EXPECT_EQ(buffer, str(Format("{0:E}") << 392.65));
EXPECT_EQ("+0000392.6", str(Format("{0:+010.4g}") << 392.65));
double inf = std::numeric_limits<double>::infinity();
EXPECT_EQ("inf", str(Format("{}") << inf));
EXPECT_EQ("-inf", str(Format("{}") << -inf));
EXPECT_EQ("INF", str(Format("{:F}") << inf));
}
TEST(FormatterTest, FormatNaN) {
@@ -792,6 +788,18 @@ TEST(FormatterTest, FormatNaN) {
EXPECT_EQ(" nan", str(Format("{:>7}") << nan));
}
TEST(FormatterTest, FormatInfinity) {
double inf = std::numeric_limits<double>::infinity();
EXPECT_EQ("inf", str(Format("{}") << inf));
EXPECT_EQ("+inf", str(Format("{:+}") << inf));
EXPECT_EQ("-inf", str(Format("{}") << -inf));
EXPECT_EQ(" inf", str(Format("{: }") << inf));
EXPECT_EQ("INF", str(Format("{:F}") << inf));
EXPECT_EQ("inf ", str(Format("{:<7}") << inf));
EXPECT_EQ(" inf ", str(Format("{:^7}") << inf));
EXPECT_EQ(" inf", str(Format("{:>7}") << inf));
}
TEST(FormatterTest, FormatLongDouble) {
EXPECT_EQ("0", str(Format("{0:}") << 0.0l));
EXPECT_EQ("0.000000", str(Format("{0:f}") << 0.0l));