#include #include "util/Convert.h" #include "util/Math.h" #include "util/MathConvert.h" namespace orxonox { TEST(multi_cast, ToString) { // int EXPECT_EQ("5", multi_cast(static_cast(5))); EXPECT_EQ("-13", multi_cast(static_cast(-13))); // unsigned int EXPECT_EQ("0", multi_cast(static_cast(0))); EXPECT_EQ("4000000000", multi_cast(static_cast(4000000000LL))); // float EXPECT_EQ("0", multi_cast(0.0f)); EXPECT_EQ("10", multi_cast(10.0f)); EXPECT_EQ("123.456", multi_cast(123.456f)); EXPECT_EQ("1.234e+012", multi_cast(1234000000000.0f)); // double EXPECT_EQ("0", multi_cast(0.0)); EXPECT_EQ("10", multi_cast(10.0)); EXPECT_EQ("123.456", multi_cast(123.456)); EXPECT_EQ("1.234e+012", multi_cast(1234000000000.0)); // char EXPECT_EQ("a", multi_cast('a')); EXPECT_EQ("\n", multi_cast('\n')); // bool EXPECT_EQ("true", multi_cast(true)); EXPECT_EQ("false", multi_cast(false)); // string EXPECT_EQ("testTEST123", multi_cast("testTEST123")); EXPECT_EQ("", multi_cast("")); // TODO: Check consistency of conversion depending on MathConvert.h and reversibility /* // Vector2 EXPECT_EQ("Vector2(10.1, 20)", multi_cast(Vector2(10.1, 20))); // Vector3 EXPECT_EQ("Vector3(10.1, 20, 300000)", multi_cast(Vector3(10.1, 20, 300000))); // Vector4 EXPECT_EQ("Vector4(10.1, 20, 300000, -321)", multi_cast(Vector4(10.1, 20, 300000, -321))); // Quaternion EXPECT_EQ("Quaternion(10.1, 20, 300000, -321)", multi_cast(Quaternion(10.1, 20, 300000, -321))); // ColourValue EXPECT_EQ("ColourValue(10.1, 20, 300000, -321)", multi_cast(ColourValue(10.1, 20, 300000, -321))); // Radian EXPECT_EQ("Radian(1.234)", multi_cast(Radian(1.234))); // Degree EXPECT_EQ("Degree(123)", multi_cast(Degree(123))); */ } TEST(multi_cast, FromString) { // int EXPECT_EQ(5, multi_cast(std::string("5"))); EXPECT_EQ(-13, multi_cast(std::string("-13"))); // unsigned int EXPECT_EQ(0U, multi_cast(std::string("0"))); EXPECT_EQ(4000000000LL, multi_cast(std::string("4000000000"))); // float EXPECT_EQ(0.0f, multi_cast(std::string("0"))); EXPECT_EQ(10.0f, multi_cast(std::string("10"))); EXPECT_EQ(123.456f, multi_cast(std::string("123.456"))); EXPECT_EQ(1234000000000.0f, multi_cast(std::string("1.234e+012"))); // double EXPECT_EQ(0.0, multi_cast(std::string("0"))); EXPECT_EQ(10.0, multi_cast(std::string("10"))); EXPECT_EQ(123.456, multi_cast(std::string("123.456"))); EXPECT_EQ(1234000000000.0, multi_cast(std::string("1.234e+012"))); // char EXPECT_EQ('a', multi_cast(std::string("a"))); EXPECT_EQ('\n', multi_cast(std::string("\n"))); EXPECT_EQ('\0', multi_cast(std::string(""))); // bool EXPECT_TRUE(multi_cast(std::string("true"))); EXPECT_FALSE(multi_cast(std::string("false"))); // TODO: Check consistency of conversion depending on MathConvert.h and reversibility /* // Vector2 EXPECT_EQ(Vector2(10.1, 20), multi_cast(std::string("Vector2(10.1, 20)"))); // Vector3 EXPECT_EQ(Vector3(10.1, 20, 300000), multi_cast(std::string("Vector3(10.1, 20, 300000)"))); // Vector4 EXPECT_EQ(Vector4(10.1, 20, 300000, -321), multi_cast(std::string("Vector4(10.1, 20, 300000, -321)"))); // Quaternion EXPECT_EQ(Quaternion(10.1, 20, 300000, -321), multi_cast(std::string("Quaternion(10.1, 20, 300000, -321)"))); // ColourValue EXPECT_EQ(ColourValue(10.1, 20, 300000, -321), multi_cast(std::string("ColourValue(10.1, 20, 300000, -321)"))); // Radian EXPECT_EQ(Radian(1.234), multi_cast(std::string("Radian(1.234)"))); // Degree EXPECT_EQ(Degree(123), multi_cast(std::string("Degree(123)"))); */ } }