mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-14 05:04:50 +00:00
Fixed: Some unit tests with fromString
This commit is contained in:
parent
43d195ec84
commit
026e849a16
1 changed files with 59 additions and 60 deletions
|
@ -17,6 +17,7 @@
|
||||||
#ifndef UT_MISC_STRING_COMMON
|
#ifndef UT_MISC_STRING_COMMON
|
||||||
#define UT_MISC_STRING_COMMON
|
#define UT_MISC_STRING_COMMON
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
#include <nel/misc/string_common.h>
|
#include <nel/misc/string_common.h>
|
||||||
|
|
||||||
struct CUTMiscStringCommon : public Test::Suite
|
struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
@ -63,11 +64,11 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
ret = NLMISC::fromString("-128", val);
|
ret = NLMISC::fromString("-128", val);
|
||||||
TEST_ASSERT(ret && val == -128);
|
TEST_ASSERT(ret && val == std::numeric_limits<sint8>::min());
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("127", val);
|
ret = NLMISC::fromString("127", val);
|
||||||
TEST_ASSERT(ret && val == 127);
|
TEST_ASSERT(ret && val == std::numeric_limits<sint8>::max());
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1
|
||||||
ret = NLMISC::fromString("-129", val);
|
ret = NLMISC::fromString("-129", val);
|
||||||
|
@ -123,11 +124,11 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
ret = NLMISC::fromString("0", val);
|
ret = NLMISC::fromString("0", val);
|
||||||
TEST_ASSERT(ret && val == 0);
|
TEST_ASSERT(ret && val == std::numeric_limits<uint8>::min());
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("255", val);
|
ret = NLMISC::fromString("255", val);
|
||||||
TEST_ASSERT(ret && val == 255);
|
TEST_ASSERT(ret && val == std::numeric_limits<uint8>::max());
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1
|
||||||
ret = NLMISC::fromString("-1", val);
|
ret = NLMISC::fromString("-1", val);
|
||||||
|
@ -187,11 +188,11 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
ret = NLMISC::fromString("-32768", val);
|
ret = NLMISC::fromString("-32768", val);
|
||||||
TEST_ASSERT(ret && val == -32768);
|
TEST_ASSERT(ret && val == std::numeric_limits<sint16>::min());
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("32767", val);
|
ret = NLMISC::fromString("32767", val);
|
||||||
TEST_ASSERT(ret && val == 32767);
|
TEST_ASSERT(ret && val == std::numeric_limits<sint16>::max());
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1
|
||||||
ret = NLMISC::fromString("-32769", val);
|
ret = NLMISC::fromString("-32769", val);
|
||||||
|
@ -247,11 +248,11 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
ret = NLMISC::fromString("0", val);
|
ret = NLMISC::fromString("0", val);
|
||||||
TEST_ASSERT(ret && val == 0);
|
TEST_ASSERT(ret && val == std::numeric_limits<uint16>::min());
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("65535", val);
|
ret = NLMISC::fromString("65535", val);
|
||||||
TEST_ASSERT(ret && val == 65535);
|
TEST_ASSERT(ret && val == std::numeric_limits<uint16>::max());
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1
|
||||||
ret = NLMISC::fromString("-1", val);
|
ret = NLMISC::fromString("-1", val);
|
||||||
|
@ -311,11 +312,11 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
ret = NLMISC::fromString("-2147483648", val);
|
ret = NLMISC::fromString("-2147483648", val);
|
||||||
TEST_ASSERT(ret && val == INT_MIN);
|
TEST_ASSERT(ret && val == std::numeric_limits<sint32>::min());
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("2147483647", val);
|
ret = NLMISC::fromString("2147483647", val);
|
||||||
TEST_ASSERT(ret && val == INT_MAX);
|
TEST_ASSERT(ret && val == std::numeric_limits<sint32>::max());
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1
|
||||||
ret = NLMISC::fromString("-2147483649", val);
|
ret = NLMISC::fromString("-2147483649", val);
|
||||||
|
@ -371,11 +372,11 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
ret = NLMISC::fromString("0", val);
|
ret = NLMISC::fromString("0", val);
|
||||||
TEST_ASSERT(ret && val == 0);
|
TEST_ASSERT(ret && val == std::numeric_limits<uint32>::min());
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("4294967295", val);
|
ret = NLMISC::fromString("4294967295", val);
|
||||||
TEST_ASSERT(ret && val == 4294967295);
|
TEST_ASSERT(ret && val == std::numeric_limits<uint32>::max());
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1
|
||||||
ret = NLMISC::fromString("-1", val);
|
ret = NLMISC::fromString("-1", val);
|
||||||
|
@ -435,21 +436,19 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
ret = NLMISC::fromString("-9223372036854775808", val);
|
ret = NLMISC::fromString("-9223372036854775808", val);
|
||||||
TEST_ASSERT(ret && val == LLONG_MIN);
|
TEST_ASSERT(ret && val == std::numeric_limits<sint64>::min());
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("9223372036854775807", val);
|
ret = NLMISC::fromString("9223372036854775807", val);
|
||||||
TEST_ASSERT(ret && val == LLONG_MAX);
|
TEST_ASSERT(ret && val == std::numeric_limits<sint64>::max());
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1, unable to compare with minimum value because no lower type
|
||||||
ret = NLMISC::fromString("-9223372036854775809", val);
|
ret = NLMISC::fromString("-9223372036854775809", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<sint64>::max());
|
||||||
TEST_ASSERT(LLONG_MIN == val);
|
|
||||||
|
|
||||||
// max limit +1
|
// max limit +1, unable to compare with maximum value because no higher type
|
||||||
ret = NLMISC::fromString("9223372036854775808", val);
|
ret = NLMISC::fromString("9223372036854775808", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<sint64>::min());
|
||||||
TEST_ASSERT(LLONG_MAX == val);
|
|
||||||
|
|
||||||
// with period
|
// with period
|
||||||
ret = NLMISC::fromString("1.2", val);
|
ret = NLMISC::fromString("1.2", val);
|
||||||
|
@ -497,22 +496,19 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
ret = NLMISC::fromString("0", val);
|
ret = NLMISC::fromString("0", val);
|
||||||
TEST_ASSERT(ret && val == 0);
|
TEST_ASSERT(ret && val == std::numeric_limits<uint64>::min());
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("18446744073709551615", val);
|
ret = NLMISC::fromString("18446744073709551615", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<uint64>::max());
|
||||||
TEST_ASSERT(ULLONG_MAX == val);
|
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1, unable to compare with minimum value because no lower type
|
||||||
ret = NLMISC::fromString("-1", val);
|
ret = NLMISC::fromString("-1", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<uint64>::max());
|
||||||
TEST_ASSERT(ULLONG_MAX == val);
|
|
||||||
|
|
||||||
// max limit +1
|
// max limit +1, unable to compare with maximum value because no higher type
|
||||||
ret = NLMISC::fromString("18446744073709551616", val);
|
ret = NLMISC::fromString("18446744073709551616", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<uint64>::min());
|
||||||
TEST_ASSERT(ULLONG_MAX == val);
|
|
||||||
|
|
||||||
// with period
|
// with period
|
||||||
ret = NLMISC::fromString("1.2", val);
|
ret = NLMISC::fromString("1.2", val);
|
||||||
|
@ -548,64 +544,67 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
|
|
||||||
// positive value
|
// positive value
|
||||||
ret = NLMISC::fromString("1", val);
|
ret = NLMISC::fromString("1", val);
|
||||||
TEST_ASSERT(ret && val == 1);
|
TEST_ASSERT(ret && val == 1.f);
|
||||||
|
|
||||||
// negative value
|
// negative value
|
||||||
ret = NLMISC::fromString("-1", val);
|
ret = NLMISC::fromString("-1", val);
|
||||||
TEST_ASSERT(ret && val == -1);
|
TEST_ASSERT(ret && val == -1.f);
|
||||||
|
|
||||||
// bad character
|
// bad character
|
||||||
ret = NLMISC::fromString("a", val);
|
ret = NLMISC::fromString("a", val);
|
||||||
TEST_ASSERT(!ret && val == 0);
|
TEST_ASSERT(!ret && val == 0.f);
|
||||||
|
|
||||||
// right character and bad character
|
// right character and bad character
|
||||||
ret = NLMISC::fromString("1a", val);
|
ret = NLMISC::fromString("1a", val);
|
||||||
TEST_ASSERT(ret && val == 1);
|
TEST_ASSERT(ret && val == 1.f);
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
ret = NLMISC::fromString("-2147483648", val);
|
ret = NLMISC::fromString("-3.4028235e+038", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == -std::numeric_limits<float>::max());
|
||||||
TEST_ASSERT(INT_MIN == val);
|
|
||||||
|
// min limit towards 0
|
||||||
|
ret = NLMISC::fromString("1.1754944e-038", val);
|
||||||
|
TEST_ASSERT(ret && val == std::numeric_limits<float>::min());
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("2147483647", val);
|
ret = NLMISC::fromString("3.4028235e+038", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<float>::max());
|
||||||
TEST_ASSERT(INT_MAX == val);
|
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1
|
||||||
ret = NLMISC::fromString("-2147483649", val);
|
ret = NLMISC::fromString("-3.4028235e+048", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == -std::numeric_limits<float>::infinity());
|
||||||
TEST_ASSERT(INT_MIN == val);
|
|
||||||
|
// min limit towards 0 -1
|
||||||
|
ret = NLMISC::fromString("1.1754944e-048", val);
|
||||||
|
TEST_ASSERT(ret && val == 0.f);
|
||||||
|
|
||||||
// max limit +1
|
// max limit +1
|
||||||
ret = NLMISC::fromString("2147483648", val);
|
ret = NLMISC::fromString("3.4028235e+048", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<float>::infinity());
|
||||||
TEST_ASSERT(INT_MAX == val);
|
|
||||||
|
|
||||||
// with period
|
// with period
|
||||||
ret = NLMISC::fromString("1.2", val);
|
ret = NLMISC::fromString("1.2", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == 1.2f);
|
||||||
TEST_ASSERT(1.2f == val);
|
|
||||||
|
|
||||||
// with coma
|
// with coma
|
||||||
ret = NLMISC::fromString("1,2", val);
|
ret = NLMISC::fromString("1,2", val);
|
||||||
TEST_ASSERT(ret && val == 1);
|
TEST_ASSERT(ret && val == 1.f);
|
||||||
|
|
||||||
// with spaces before
|
// with spaces before
|
||||||
ret = NLMISC::fromString(" 10", val);
|
ret = NLMISC::fromString(" 10", val);
|
||||||
TEST_ASSERT(ret && val == 10);
|
TEST_ASSERT(ret && val == 10.f);
|
||||||
|
|
||||||
// with spaces after
|
// with spaces after
|
||||||
ret = NLMISC::fromString("10 ", val);
|
ret = NLMISC::fromString("10 ", val);
|
||||||
TEST_ASSERT(ret && val == 10);
|
TEST_ASSERT(ret && val == 10.f);
|
||||||
|
|
||||||
// with 0s before
|
// with 0s before
|
||||||
ret = NLMISC::fromString("001", val);
|
ret = NLMISC::fromString("001", val);
|
||||||
TEST_ASSERT(ret && val == 1);
|
TEST_ASSERT(ret && val == 1.f);
|
||||||
|
|
||||||
// with + before
|
// with + before
|
||||||
ret = NLMISC::fromString("+1", val);
|
ret = NLMISC::fromString("+1", val);
|
||||||
TEST_ASSERT(ret && val == 1);
|
TEST_ASSERT(ret && val == 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fromStringDouble()
|
void fromStringDouble()
|
||||||
|
@ -632,24 +631,24 @@ struct CUTMiscStringCommon : public Test::Suite
|
||||||
TEST_ASSERT(ret && val == 1.0);
|
TEST_ASSERT(ret && val == 1.0);
|
||||||
|
|
||||||
// min limit
|
// min limit
|
||||||
|
ret = NLMISC::fromString("-1.7976931348623158e+308", val);
|
||||||
|
TEST_ASSERT(ret && val == -std::numeric_limits<double>::max());
|
||||||
|
|
||||||
|
// min limit towards 0
|
||||||
ret = NLMISC::fromString("2.2250738585072014e-308", val);
|
ret = NLMISC::fromString("2.2250738585072014e-308", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<double>::min());
|
||||||
TEST_ASSERT(DBL_MIN == val);
|
|
||||||
|
|
||||||
// max limit
|
// max limit
|
||||||
ret = NLMISC::fromString("1.7976931348623158e+308", val);
|
ret = NLMISC::fromString("1.7976931348623158e+308", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<double>::max());
|
||||||
TEST_ASSERT(DBL_MAX == val);
|
|
||||||
|
|
||||||
// min limit -1
|
// min limit -1
|
||||||
ret = NLMISC::fromString("3e-408", val);
|
ret = NLMISC::fromString("3e-408", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == 0.0);
|
||||||
TEST_ASSERT(0 == val);
|
|
||||||
|
|
||||||
// max limit +1
|
// max limit +1
|
||||||
ret = NLMISC::fromString("2e+308", val);
|
ret = NLMISC::fromString("2e+308", val);
|
||||||
TEST_ASSERT_MSG(ret, "should succeed");
|
TEST_ASSERT(ret && val == std::numeric_limits<double>::infinity());
|
||||||
TEST_ASSERT(INFINITY == val);
|
|
||||||
|
|
||||||
// with period
|
// with period
|
||||||
ret = NLMISC::fromString("1.2", val);
|
ret = NLMISC::fromString("1.2", val);
|
||||||
|
|
Loading…
Reference in a new issue