Fix unit tests for Convert::ToString

refs #11483
This commit is contained in:
Gunnar Beutner 2016-06-16 15:32:29 +02:00
parent bc6f7d7a21
commit 039461e218
3 changed files with 9 additions and 10 deletions

View File

@ -35,6 +35,12 @@ String Convert::ToString(const Value& val)
String Convert::ToString(double val)
{
double integral;
double fractional = std::modf(val, &integral);
if (fractional == 0)
return Convert::ToString(static_cast<long>(val));
std::ostringstream msgbuf;
msgbuf << std::fixed << val;
return msgbuf.str();

View File

@ -56,19 +56,12 @@ Value::operator double(void) const
Value::operator String(void) const
{
Object *object;
double dvalue, integral, fractional;
switch (GetType()) {
case ValueEmpty:
return String();
case ValueNumber:
dvalue = boost::get<double>(m_Value);
fractional = std::modf(dvalue, &integral);
if (fractional != 0)
return Convert::ToString(dvalue);
else
return Convert::ToString(static_cast<long>(dvalue));
return Convert::ToString(boost::get<double>(m_Value));
case ValueBoolean:
if (boost::get<bool>(m_Value))
return "true";

View File

@ -46,14 +46,14 @@ BOOST_AUTO_TEST_CASE(todouble)
BOOST_AUTO_TEST_CASE(tostring)
{
BOOST_CHECK(Convert::ToString(7) == "7");
BOOST_CHECK(Convert::ToString(7.5) == "7.5");
BOOST_CHECK(Convert::ToString(7.5) == "7.500000");
BOOST_CHECK(Convert::ToString("hello") == "hello");
String str = "hello";
BOOST_CHECK(Convert::ToString(str) == "hello");
BOOST_CHECK(Convert::ToString(Value(7)) == "7");
BOOST_CHECK(Convert::ToString(Value(7.5)) == "7.5");
BOOST_CHECK(Convert::ToString(Value(7.5)) == "7.500000");
BOOST_CHECK(Convert::ToString(Value("hello")) == "hello");
BOOST_CHECK(Convert::ToString(Value("hello hello")) == "hello hello");
}