diff options
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/math/test_quaternion.h | 50 | ||||
-rw-r--r-- | tests/core/object/test_object.h | 6 | ||||
-rw-r--r-- | tests/core/string/test_string.h | 118 |
3 files changed, 135 insertions, 39 deletions
diff --git a/tests/core/math/test_quaternion.h b/tests/core/math/test_quaternion.h index 94eef6c463..1b80ffba0b 100644 --- a/tests/core/math/test_quaternion.h +++ b/tests/core/math/test_quaternion.h @@ -41,9 +41,9 @@ namespace TestQuaternion { Quaternion quat_euler_yxz_deg(Vector3 angle) { - double yaw = Math::deg2rad(angle[1]); - double pitch = Math::deg2rad(angle[0]); - double roll = Math::deg2rad(angle[2]); + double yaw = Math::deg_to_rad(angle[1]); + double pitch = Math::deg_to_rad(angle[0]); + double roll = Math::deg_to_rad(angle[2]); // Generate YXZ (Z-then-X-then-Y) Quaternion using single-axis Euler // constructor and quaternion product, both tested separately. @@ -77,7 +77,7 @@ TEST_CASE("[Quaternion] Construct x,y,z,w") { TEST_CASE("[Quaternion] Construct AxisAngle 1") { // Easy to visualize: 120 deg about X-axis. - Quaternion q(Vector3(1.0, 0.0, 0.0), Math::deg2rad(120.0)); + Quaternion q(Vector3(1.0, 0.0, 0.0), Math::deg_to_rad(120.0)); // 0.866 isn't close enough; doctest::Approx doesn't cut much slack! CHECK(q[0] == doctest::Approx(0.866025)); // Sine of half the angle. @@ -88,7 +88,7 @@ TEST_CASE("[Quaternion] Construct AxisAngle 1") { TEST_CASE("[Quaternion] Construct AxisAngle 2") { // Easy to visualize: 30 deg about Y-axis. - Quaternion q(Vector3(0.0, 1.0, 0.0), Math::deg2rad(30.0)); + Quaternion q(Vector3(0.0, 1.0, 0.0), Math::deg_to_rad(30.0)); CHECK(q[0] == doctest::Approx(0.0)); CHECK(q[1] == doctest::Approx(0.258819)); // Sine of half the angle. @@ -98,7 +98,7 @@ TEST_CASE("[Quaternion] Construct AxisAngle 2") { TEST_CASE("[Quaternion] Construct AxisAngle 3") { // Easy to visualize: 60 deg about Z-axis. - Quaternion q(Vector3(0.0, 0.0, 1.0), Math::deg2rad(60.0)); + Quaternion q(Vector3(0.0, 0.0, 1.0), Math::deg_to_rad(60.0)); CHECK(q[0] == doctest::Approx(0.0)); CHECK(q[1] == doctest::Approx(0.0)); @@ -109,7 +109,7 @@ TEST_CASE("[Quaternion] Construct AxisAngle 3") { TEST_CASE("[Quaternion] Construct AxisAngle 4") { // More complex & hard to visualize, so test w/ data from online calculator. Vector3 axis(1.0, 2.0, 0.5); - Quaternion q(axis.normalized(), Math::deg2rad(35.0)); + Quaternion q(axis.normalized(), Math::deg_to_rad(35.0)); CHECK(q[0] == doctest::Approx(0.131239)); CHECK(q[1] == doctest::Approx(0.262478)); @@ -119,7 +119,7 @@ TEST_CASE("[Quaternion] Construct AxisAngle 4") { TEST_CASE("[Quaternion] Construct from Quaternion") { Vector3 axis(1.0, 2.0, 0.5); - Quaternion q_src(axis.normalized(), Math::deg2rad(35.0)); + Quaternion q_src(axis.normalized(), Math::deg_to_rad(35.0)); Quaternion q(q_src); CHECK(q[0] == doctest::Approx(0.131239)); @@ -129,9 +129,9 @@ TEST_CASE("[Quaternion] Construct from Quaternion") { } TEST_CASE("[Quaternion] Construct Euler SingleAxis") { - double yaw = Math::deg2rad(45.0); - double pitch = Math::deg2rad(30.0); - double roll = Math::deg2rad(10.0); + double yaw = Math::deg_to_rad(45.0); + double pitch = Math::deg_to_rad(30.0); + double roll = Math::deg_to_rad(10.0); Vector3 euler_y(0.0, yaw, 0.0); Quaternion q_y(euler_y); @@ -156,9 +156,9 @@ TEST_CASE("[Quaternion] Construct Euler SingleAxis") { } TEST_CASE("[Quaternion] Construct Euler YXZ dynamic axes") { - double yaw = Math::deg2rad(45.0); - double pitch = Math::deg2rad(30.0); - double roll = Math::deg2rad(10.0); + double yaw = Math::deg_to_rad(45.0); + double pitch = Math::deg_to_rad(30.0); + double roll = Math::deg_to_rad(10.0); // Generate YXZ comparision data (Z-then-X-then-Y) using single-axis Euler // constructor and quaternion product, both tested separately. @@ -187,9 +187,9 @@ TEST_CASE("[Quaternion] Construct Euler YXZ dynamic axes") { } TEST_CASE("[Quaternion] Construct Basis Euler") { - double yaw = Math::deg2rad(45.0); - double pitch = Math::deg2rad(30.0); - double roll = Math::deg2rad(10.0); + double yaw = Math::deg_to_rad(45.0); + double pitch = Math::deg_to_rad(30.0); + double roll = Math::deg_to_rad(10.0); Vector3 euler_yxz(pitch, yaw, roll); Quaternion q_yxz(euler_yxz); Basis basis_axes(euler_yxz); @@ -199,7 +199,7 @@ TEST_CASE("[Quaternion] Construct Basis Euler") { TEST_CASE("[Quaternion] Construct Basis Axes") { // Arbitrary Euler angles. - Vector3 euler_yxz(Math::deg2rad(31.41), Math::deg2rad(-49.16), Math::deg2rad(12.34)); + Vector3 euler_yxz(Math::deg_to_rad(31.41), Math::deg_to_rad(-49.16), Math::deg_to_rad(12.34)); // Basis vectors from online calculation of rotation matrix. Vector3 i_unit(0.5545787, 0.1823950, 0.8118957); Vector3 j_unit(-0.5249245, 0.8337420, 0.1712555); @@ -248,9 +248,9 @@ TEST_CASE("[Quaternion] Product (book)") { } TEST_CASE("[Quaternion] Product") { - double yaw = Math::deg2rad(45.0); - double pitch = Math::deg2rad(30.0); - double roll = Math::deg2rad(10.0); + double yaw = Math::deg_to_rad(45.0); + double pitch = Math::deg_to_rad(30.0); + double roll = Math::deg_to_rad(10.0); Vector3 euler_y(0.0, yaw, 0.0); Quaternion q_y(euler_y); @@ -292,7 +292,7 @@ TEST_CASE("[Quaternion] Product") { TEST_CASE("[Quaternion] xform unit vectors") { // Easy to visualize: 120 deg about X-axis. // Transform the i, j, & k unit vectors. - Quaternion q(Vector3(1.0, 0.0, 0.0), Math::deg2rad(120.0)); + Quaternion q(Vector3(1.0, 0.0, 0.0), Math::deg_to_rad(120.0)); Vector3 i_t = q.xform(Vector3(1.0, 0.0, 0.0)); Vector3 j_t = q.xform(Vector3(0.0, 1.0, 0.0)); Vector3 k_t = q.xform(Vector3(0.0, 0.0, 1.0)); @@ -305,7 +305,7 @@ TEST_CASE("[Quaternion] xform unit vectors") { CHECK(k_t.length_squared() == doctest::Approx(1.0)); // Easy to visualize: 30 deg about Y-axis. - q = Quaternion(Vector3(0.0, 1.0, 0.0), Math::deg2rad(30.0)); + q = Quaternion(Vector3(0.0, 1.0, 0.0), Math::deg_to_rad(30.0)); i_t = q.xform(Vector3(1.0, 0.0, 0.0)); j_t = q.xform(Vector3(0.0, 1.0, 0.0)); k_t = q.xform(Vector3(0.0, 0.0, 1.0)); @@ -318,7 +318,7 @@ TEST_CASE("[Quaternion] xform unit vectors") { CHECK(k_t.length_squared() == doctest::Approx(1.0)); // Easy to visualize: 60 deg about Z-axis. - q = Quaternion(Vector3(0.0, 0.0, 1.0), Math::deg2rad(60.0)); + q = Quaternion(Vector3(0.0, 0.0, 1.0), Math::deg_to_rad(60.0)); i_t = q.xform(Vector3(1.0, 0.0, 0.0)); j_t = q.xform(Vector3(0.0, 1.0, 0.0)); k_t = q.xform(Vector3(0.0, 0.0, 1.0)); @@ -333,7 +333,7 @@ TEST_CASE("[Quaternion] xform unit vectors") { TEST_CASE("[Quaternion] xform vector") { // Arbitrary quaternion rotates an arbitrary vector. - Vector3 euler_yzx(Math::deg2rad(31.41), Math::deg2rad(-49.16), Math::deg2rad(12.34)); + Vector3 euler_yzx(Math::deg_to_rad(31.41), Math::deg_to_rad(-49.16), Math::deg_to_rad(12.34)); Basis basis_axes(euler_yzx); Quaternion q(basis_axes); diff --git a/tests/core/object/test_object.h b/tests/core/object/test_object.h index 88a3e4ccad..f5c5de7fdf 100644 --- a/tests/core/object/test_object.h +++ b/tests/core/object/test_object.h @@ -82,6 +82,12 @@ public: Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const override { return Variant::PACKED_FLOAT32_ARRAY; } + bool property_can_revert(const StringName &p_name) const override { + return false; + }; + bool property_get_revert(const StringName &p_name, Variant &r_ret) const override { + return false; + }; void get_method_list(List<MethodInfo> *p_list) const override { } bool has_method(const StringName &p_method) const override { diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 8914dbfd9a..62d2051eee 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -619,7 +619,7 @@ TEST_CASE("[String] sprintf") { output = format.sprintf(args, &error); REQUIRE(error == false); CHECK(output == String("fish % frog")); - //////// INTS + ///// Ints // Int format = "fish %d frog"; @@ -727,7 +727,7 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish 143 frog")); - ////// REALS + ///// Reals // Real format = "fish %f frog"; @@ -737,7 +737,7 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish 99.990000 frog")); - // Real left-padded + // Real left-padded. format = "fish %11f frog"; args.clear(); args.push_back(99.99); @@ -745,7 +745,7 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish 99.990000 frog")); - // Real right-padded + // Real right-padded. format = "fish %-11f frog"; args.clear(); args.push_back(99.99); @@ -769,7 +769,7 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish +99.990000 frog")); - // Real with 1 decimals. + // Real with 1 decimal. format = "fish %.1f frog"; args.clear(); args.push_back(99.99); @@ -803,7 +803,97 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish -99.990000 frog")); - /////// Strings. + ///// Vectors + + // Vector2 + format = "fish %v frog"; + args.clear(); + args.push_back(Variant(Vector2(19.99, 1.00))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (19.990000, 1.000000) frog")); + + // Vector3 + format = "fish %v frog"; + args.clear(); + args.push_back(Variant(Vector3(19.99, 1.00, -2.05))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (19.990000, 1.000000, -2.050000) frog")); + + // Vector4 + format = "fish %v frog"; + args.clear(); + args.push_back(Variant(Vector4(19.99, 1.00, -2.05, 5.5))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (19.990000, 1.000000, -2.050000, 5.500000) frog")); + + // Vector with negative values. + format = "fish %v frog"; + args.clear(); + args.push_back(Variant(Vector2(-19.99, -1.00))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (-19.990000, -1.000000) frog")); + + // Vector left-padded. + format = "fish %11v frog"; + args.clear(); + args.push_back(Variant(Vector3(19.99, 1.00, -2.05))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish ( 19.990000, 1.000000, -2.050000) frog")); + + // Vector right-padded. + format = "fish %-11v frog"; + args.clear(); + args.push_back(Variant(Vector3(19.99, 1.00, -2.05))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (19.990000 , 1.000000 , -2.050000 ) frog")); + + // Vector left-padded with zeros. + format = "fish %011v frog"; + args.clear(); + args.push_back(Variant(Vector3(19.99, 1.00, -2.05))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (0019.990000, 0001.000000, -002.050000) frog")); + + // Vector given Vector3i. + format = "fish %v frog"; + args.clear(); + args.push_back(Variant(Vector3i(19, 1, -2))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (19.000000, 1.000000, -2.000000) frog")); + + // Vector with 1 decimal. + format = "fish %.1v frog"; + args.clear(); + args.push_back(Variant(Vector3(19.99, 1.00, -2.05))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (20.0, 1.0, -2.0) frog")); + + // Vector with 12 decimals. + format = "fish %.12v frog"; + args.clear(); + args.push_back(Variant(Vector3(19.00, 1.00, -2.00))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (19.000000000000, 1.000000000000, -2.000000000000) frog")); + + // Vector with no decimals. + format = "fish %.v frog"; + args.clear(); + args.push_back(Variant(Vector3(19.99, 1.00, -2.05))); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish (20, 1, -2) frog")); + + ///// Strings // String format = "fish %s frog"; @@ -813,7 +903,7 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish cheese frog")); - // String left-padded + // String left-padded. format = "fish %10s frog"; args.clear(); args.push_back("cheese"); @@ -821,7 +911,7 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish cheese frog")); - // String right-padded + // String right-padded. format = "fish %-10s frog"; args.clear(); args.push_back("cheese"); @@ -849,7 +939,7 @@ TEST_CASE("[String] sprintf") { ///// Dynamic width - // String dynamic width + // String dynamic width. format = "fish %*s frog"; args.clear(); args.push_back(10); @@ -858,7 +948,7 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); REQUIRE(output == String("fish cheese frog")); - // Int dynamic width + // Int dynamic width. format = "fish %*d frog"; args.clear(); args.push_back(10); @@ -867,7 +957,7 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); REQUIRE(output == String("fish 99 frog")); - // Float dynamic width + // Float dynamic width. format = "fish %*.*f frog"; args.clear(); args.push_back(10); @@ -904,7 +994,7 @@ TEST_CASE("[String] sprintf") { REQUIRE(error); CHECK(output == "incomplete format"); - // Bad character in format string + // Bad character in format string. format = "fish %&f frog"; args.clear(); args.push_back("cheese"); @@ -920,14 +1010,14 @@ TEST_CASE("[String] sprintf") { REQUIRE(error); CHECK(output == "too many decimal points in format"); - // * not a number + // * not a number or vector. format = "fish %*f frog"; args.clear(); args.push_back("cheese"); args.push_back(99.99); output = format.sprintf(args, &error); REQUIRE(error); - CHECK(output == "* wants number"); + CHECK(output == "* wants number or vector"); // Character too long. format = "fish %c frog"; |