diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/math/test_basis.h | 94 | ||||
-rw-r--r-- | tests/core/string/test_string.h | 81 | ||||
-rw-r--r-- | tests/scene/test_primitives.h | 2 | ||||
-rw-r--r-- | tests/scene/test_text_edit.h | 2 |
4 files changed, 168 insertions, 11 deletions
diff --git a/tests/core/math/test_basis.h b/tests/core/math/test_basis.h index fcac9a6231..a9bc2e9b99 100644 --- a/tests/core/math/test_basis.h +++ b/tests/core/math/test_basis.h @@ -324,6 +324,100 @@ TEST_CASE("[Basis] Is conformal checks") { CHECK_FALSE_MESSAGE( Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_conformal(), "Basis with the X axis skewed 45 degrees should not be conformal."); + + CHECK_MESSAGE( + Basis(0, 0, 0, 0, 0, 0, 0, 0, 0).is_conformal(), + "Edge case: Basis with all zeroes should return true for is_conformal (because a 0 scale is uniform)."); +} + +TEST_CASE("[Basis] Is orthogonal checks") { + CHECK_MESSAGE( + Basis().is_orthogonal(), + "Identity Basis should be orthogonal."); + + CHECK_MESSAGE( + Basis::from_euler(Vector3(1.2, 3.4, 5.6)).is_orthogonal(), + "Basis with only rotation should be orthogonal."); + + CHECK_MESSAGE( + Basis::from_scale(Vector3(-1, -1, -1)).is_orthogonal(), + "Basis with only a flip should be orthogonal."); + + CHECK_MESSAGE( + Basis::from_scale(Vector3(1.2, 3.4, 5.6)).is_orthogonal(), + "Basis with only scale should be orthogonal."); + + CHECK_MESSAGE( + Basis(Vector3(3, 4, 0), Vector3(4, -3, 0), Vector3(0, 0, 5)).is_orthogonal(), + "Basis with a flip, rotation, and uniform scale should be orthogonal."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_orthogonal(), + "Basis with the X axis skewed 45 degrees should not be orthogonal."); + + CHECK_MESSAGE( + Basis(0, 0, 0, 0, 0, 0, 0, 0, 0).is_orthogonal(), + "Edge case: Basis with all zeroes should return true for is_orthogonal, since zero vectors are orthogonal to all vectors."); +} + +TEST_CASE("[Basis] Is orthonormal checks") { + CHECK_MESSAGE( + Basis().is_orthonormal(), + "Identity Basis should be orthonormal."); + + CHECK_MESSAGE( + Basis::from_euler(Vector3(1.2, 3.4, 5.6)).is_orthonormal(), + "Basis with only rotation should be orthonormal."); + + CHECK_MESSAGE( + Basis::from_scale(Vector3(-1, -1, -1)).is_orthonormal(), + "Basis with only a flip should be orthonormal."); + + CHECK_FALSE_MESSAGE( + Basis::from_scale(Vector3(1.2, 3.4, 5.6)).is_orthonormal(), + "Basis with only scale should not be orthonormal."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(3, 4, 0), Vector3(4, -3, 0), Vector3(0, 0, 5)).is_orthonormal(), + "Basis with a flip, rotation, and uniform scale should not be orthonormal."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_orthonormal(), + "Basis with the X axis skewed 45 degrees should not be orthonormal."); + + CHECK_FALSE_MESSAGE( + Basis(0, 0, 0, 0, 0, 0, 0, 0, 0).is_orthonormal(), + "Edge case: Basis with all zeroes should return false for is_orthonormal, since the vectors do not have a length of 1."); +} + +TEST_CASE("[Basis] Is rotation checks") { + CHECK_MESSAGE( + Basis().is_rotation(), + "Identity Basis should be a rotation (a rotation of zero)."); + + CHECK_MESSAGE( + Basis::from_euler(Vector3(1.2, 3.4, 5.6)).is_rotation(), + "Basis with only rotation should be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis::from_scale(Vector3(-1, -1, -1)).is_rotation(), + "Basis with only a flip should not be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis::from_scale(Vector3(1.2, 3.4, 5.6)).is_rotation(), + "Basis with only scale should not be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(2, 0, 0), Vector3(0, 0.5, 0), Vector3(0, 0, 1)).is_rotation(), + "Basis with a squeeze should not be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_rotation(), + "Basis with the X axis skewed 45 degrees should not be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis(0, 0, 0, 0, 0, 0, 0, 0, 0).is_rotation(), + "Edge case: Basis with all zeroes should return false for is_rotation, because it is not just a rotation (has a scale of 0)."); } } // namespace TestBasis diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 02349aedc0..8a11491bb2 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -456,30 +456,93 @@ TEST_CASE("[String] Number to string") { } TEST_CASE("[String] String to integer") { - static const char *nums[4] = { "1237461283", "- 22", "0", " - 1123412" }; - static const int num[4] = { 1237461283, -22, 0, -1123412 }; + static const char *nums[14] = { "1237461283", "- 22", "0", " - 1123412", "", "10_000_000", "-1_2_3_4", "10__000", " 1 2 34 ", "-0", "007", "--45", "---46", "-7-2" }; + static const int num[14] = { 1237461283, -22, 0, -1123412, 0, 10000000, -1234, 10000, 1234, 0, 7, 45, -46, -72 }; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 14; i++) { CHECK(String(nums[i]).to_int() == num[i]); } + CHECK(String("0b1011").to_int() == 1011); // Looks like a binary number, but to_int() handles this as a base-10 number, "b" is just ignored. + CHECK(String("0x1012").to_int() == 1012); // Looks like a hexadecimal number, but to_int() handles this as a base-10 number, "x" is just ignored. + + ERR_PRINT_OFF + CHECK(String("999999999999999999999999999999999999999999999999999999999").to_int() == INT64_MAX); // Too large, largest possible is returned. + CHECK(String("-999999999999999999999999999999999999999999999999999999999").to_int() == INT64_MIN); // Too small, smallest possible is returned. + ERR_PRINT_ON } TEST_CASE("[String] Hex to integer") { - static const char *nums[4] = { "0xFFAE", "22", "0", "AADDAD" }; - static const int64_t num[4] = { 0xFFAE, 0x22, 0, 0xAADDAD }; + static const char *nums[12] = { "0xFFAE", "22", "0", "AADDAD", "0x7FFFFFFFFFFFFFFF", "-0xf", "", "000", "000f", "0xaA", "-ff", "-" }; + static const int64_t num[12] = { 0xFFAE, 0x22, 0, 0xAADDAD, 0x7FFFFFFFFFFFFFFF, -0xf, 0, 0, 0xf, 0xaa, -0xff, 0x0 }; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 12; i++) { CHECK(String(nums[i]).hex_to_int() == num[i]); } + + // Invalid hex strings should return 0. + static const char *invalid_nums[15] = { "qwerty", "QWERTY", "0xqwerty", "0x00qwerty", "qwerty00", "0x", "0x__", "__", "x12", "+", " ff", "ff ", "f f", "+ff", "--0x78" }; + + ERR_PRINT_OFF + for (int i = 0; i < 15; i++) { + CHECK(String(invalid_nums[i]).hex_to_int() == 0); + } + + CHECK(String("0xFFFFFFFFFFFFFFFFFFFFFFF").hex_to_int() == INT64_MAX); // Too large, largest possible is returned. + CHECK(String("-0xFFFFFFFFFFFFFFFFFFFFFFF").hex_to_int() == INT64_MIN); // Too small, smallest possible is returned. + ERR_PRINT_ON +} + +TEST_CASE("[String] Bin to integer") { + static const char *nums[10] = { "", "0", "0b0", "0b1", "0b", "1", "0b1010", "-0b11", "-1010", "0b0111111111111111111111111111111111111111111111111111111111111111" }; + static const int64_t num[10] = { 0, 0, 0, 1, 0, 1, 10, -3, -10, 0x7FFFFFFFFFFFFFFF }; + + for (int i = 0; i < 10; i++) { + CHECK(String(nums[i]).bin_to_int() == num[i]); + } + + // Invalid bin strings should return 0. The long "0x11...11" is just too long for a 64 bit int. + static const char *invalid_nums[16] = { "qwerty", "QWERTY", "0bqwerty", "0b00qwerty", "qwerty00", "0x__", "0b__", "__", "b12", "+", "-", "0x12ab", " 11", "11 ", "1 1", "--0b11" }; + + for (int i = 0; i < 16; i++) { + CHECK(String(invalid_nums[i]).bin_to_int() == 0); + } + + ERR_PRINT_OFF + CHECK(String("0b111111111111111111111111111111111111111111111111111111111111111111111111111111111").bin_to_int() == INT64_MAX); // Too large, largest possible is returned. + CHECK(String("-0b111111111111111111111111111111111111111111111111111111111111111111111111111111111").bin_to_int() == INT64_MIN); // Too small, smallest possible is returned. + ERR_PRINT_ON } TEST_CASE("[String] String to float") { - static const char *nums[4] = { "-12348298412.2", "0.05", "2.0002", " -0.0001" }; - static const double num[4] = { -12348298412.2, 0.05, 2.0002, -0.0001 }; + static const char *nums[12] = { "-12348298412.2", "0.05", "2.0002", " -0.0001", "0", "000", "123", "0.0", "000.000", "000.007", "234__", "3..14" }; + static const double num[12] = { -12348298412.2, 0.05, 2.0002, -0.0001, 0.0, 0.0, 123.0, 0.0, 0.0, 0.007, 234.0, 3.0 }; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 12; i++) { CHECK(!(ABS(String(nums[i]).to_float() - num[i]) > 0.00001)); } + + // Invalid float strings should return 0. + static const char *invalid_nums[6] = { "qwerty", "qwerty123", "0xffff", "0b1010", "--3.13", "__345" }; + + for (int i = 0; i < 6; i++) { + CHECK(String(invalid_nums[i]).to_float() == 0); + } + + // Very large exponents. + CHECK(String("1e308").to_float() == 1e308); + CHECK(String("-1e308").to_float() == -1e308); + + // Exponent is so high that value is INFINITY/-INFINITY. + CHECK(String("1e309").to_float() == INFINITY); + CHECK(String("1e511").to_float() == INFINITY); + CHECK(String("-1e309").to_float() == -INFINITY); + CHECK(String("-1e511").to_float() == -INFINITY); + + // Exponent is so high that a warning message is printed. Value is INFINITY/-INFINITY. + ERR_PRINT_OFF + CHECK(String("1e512").to_float() == INFINITY); + CHECK(String("-1e512").to_float() == -INFINITY); + ERR_PRINT_ON } TEST_CASE("[String] Slicing") { diff --git a/tests/scene/test_primitives.h b/tests/scene/test_primitives.h index 9232a3020d..552f722d24 100644 --- a/tests/scene/test_primitives.h +++ b/tests/scene/test_primitives.h @@ -232,7 +232,7 @@ TEST_CASE("[SceneTree][Primitive][Cylinder] Cylinder Primitive") { CHECK(cylinder->get_bottom_radius() > 0); CHECK(cylinder->get_height() > 0); CHECK(cylinder->get_radial_segments() > 0); - CHECK(cylinder->get_rings() > 0); + CHECK(cylinder->get_rings() >= 0); } SUBCASE("[SceneTree][Primitive][Cylinder] Set properties and get them") { diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h index 9c9ade4445..e81578a862 100644 --- a/tests/scene/test_text_edit.h +++ b/tests/scene/test_text_edit.h @@ -4118,7 +4118,7 @@ TEST_CASE("[SceneTree][TextEdit] setter getters") { CHECK_FALSE(text_edit->is_drawing_spaces()); } - SUBCASE("[TextEdit] draw minimao") { + SUBCASE("[TextEdit] draw minimap") { text_edit->set_draw_minimap(true); CHECK(text_edit->is_drawing_minimap()); text_edit->set_draw_minimap(false); |