123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2020-08-14
- * Changed: 2022-05-09
- *
- * */
- #include <gtest/gtest.h>
- #include <ls_std/ls_std.hpp>
- namespace
- {
- class FloatTest : public ::testing::Test
- {
- protected:
- FloatTest() = default;
- ~FloatTest() override = default;
- void SetUp() override
- {}
- void TearDown() override
- {}
- };
- // assignment operators
- TEST_F(FloatTest, operator_assignment)
- {
- ls::std::boxing::Float x{13.023f};
- x = 44.22f;
- ASSERT_EQ(44.22f, x);
- }
- // arithmetic operators
- TEST_F(FloatTest, operator_negative)
- {
- ls::std::boxing::Float x{3.25f};
- ASSERT_FLOAT_EQ(-3.25f, -x);
- }
- TEST_F(FloatTest, operator_addition_with_reference)
- {
- ls::std::boxing::Float x{3.1415f};
- ls::std::boxing::Float y{2.223f};
- ls::std::boxing::Float z{x + y};
- ASSERT_FLOAT_EQ(5.3645f, z);
- }
- TEST_F(FloatTest, operator_addition_with_value)
- {
- ls::std::boxing::Float x{3.1415f};
- ASSERT_FLOAT_EQ(5.3645f, x + 2.223f);
- }
- TEST_F(FloatTest, operator_multiplication_with_reference)
- {
- ls::std::boxing::Float x{3.14f};
- ls::std::boxing::Float y{2.22f};
- ls::std::boxing::Float z{x * y};
- ASSERT_FLOAT_EQ(6.9708f, z);
- }
- TEST_F(FloatTest, operator_multiplication_with_value)
- {
- ls::std::boxing::Float x{3.14f};
- ASSERT_FLOAT_EQ(6.9708f, x * 2.22f);
- }
- TEST_F(FloatTest, operator_substraction_with_reference)
- {
- ls::std::boxing::Float x{3.1415f};
- ls::std::boxing::Float y{2.225f};
- ls::std::boxing::Float z{x - y};
- ASSERT_FLOAT_EQ(0.9165f, z);
- }
- TEST_F(FloatTest, operator_substraction_with_value)
- {
- ls::std::boxing::Float x{3.1415f};
- ASSERT_FLOAT_EQ(0.9165f, x - 2.225f);
- }
- TEST_F(FloatTest, operator_division_with_reference)
- {
- ls::std::boxing::Float x{2.25f};
- ls::std::boxing::Float y{0.5f};
- ls::std::boxing::Float z{x / y};
- ASSERT_FLOAT_EQ(4.5f, z);
- }
- TEST_F(FloatTest, operator_division_with_value)
- {
- ls::std::boxing::Float x{2.25f};
- ASSERT_FLOAT_EQ(4.5f, x / 0.5f);
- }
- // compound operators
- TEST_F(FloatTest, operator_add_assign_with_reference)
- {
- ls::std::boxing::Float x{2.25f};
- ls::std::boxing::Float y{3.14f};
- x += y;
- ASSERT_FLOAT_EQ(5.39f, x);
- }
- TEST_F(FloatTest, operator_add_assign_with_value)
- {
- ls::std::boxing::Float x{2.25f};
- x += 3.14f;
- ASSERT_FLOAT_EQ(5.39f, x);
- }
- TEST_F(FloatTest, operator_sub_assign_with_reference)
- {
- ls::std::boxing::Float x{2.25f};
- ls::std::boxing::Float y{1.14f};
- x -= y;
- ASSERT_FLOAT_EQ(1.11f, x);
- }
- TEST_F(FloatTest, operator_sub_assign_with_value)
- {
- ls::std::boxing::Float x{2.25f};
- x -= 1.14f;
- ASSERT_FLOAT_EQ(1.11f, x);
- }
- TEST_F(FloatTest, operator_mul_assign_with_reference)
- {
- ls::std::boxing::Float x{2.25f};
- ls::std::boxing::Float y{0.04f};
- x *= y;
- ASSERT_FLOAT_EQ(0.09f, x);
- }
- TEST_F(FloatTest, operator_mul_assign_with_value)
- {
- ls::std::boxing::Float x{2.25f};
- x *= 1.14f;
- ASSERT_FLOAT_EQ(2.565f, x);
- }
- TEST_F(FloatTest, operator_division_assign_with_reference)
- {
- ls::std::boxing::Float x{2.25f};
- ls::std::boxing::Float y{1.5f};
- x /= y;
- ASSERT_FLOAT_EQ(1.5f, x);
- }
- TEST_F(FloatTest, operator_division_assign_with_value)
- {
- ls::std::boxing::Float x{2.25f};
- x /= 0.05f;
- ASSERT_FLOAT_EQ(45.0f, x);
- }
- // comparison operators
- TEST_F(FloatTest, operator_equals_with_reference)
- {
- ls::std::boxing::Float x{3.14159f};
- ls::std::boxing::Float y{3.14159f};
- ASSERT_TRUE(x == y);
- ASSERT_TRUE(y == x);
- }
- TEST_F(FloatTest, operator_equals_with_value)
- {
- ls::std::boxing::Float x{3.14159f};
- ASSERT_TRUE(x == 3.14159f);
- }
- TEST_F(FloatTest, operator_not_equals_with_reference)
- {
- ls::std::boxing::Float x{3.1415f};
- ls::std::boxing::Float y{3.1414f};
- ASSERT_TRUE(x != y);
- ASSERT_TRUE(y != x);
- }
- TEST_F(FloatTest, operator_not_equals_with_value)
- {
- ls::std::boxing::Float x{3.1415f};
- ASSERT_TRUE(x != 3.1414f);
- }
- TEST_F(FloatTest, operator_greater_than_with_reference)
- {
- ls::std::boxing::Float x{3.1415f};
- ls::std::boxing::Float y{3.1414f};
- ASSERT_TRUE(x > y);
- ASSERT_TRUE(x > 3.1414f);
- }
- TEST_F(FloatTest, operator_greater_than_with_value)
- {
- ls::std::boxing::Float x{3.1415f};
- ASSERT_TRUE(x > 3.1414f);
- }
- TEST_F(FloatTest, operator_greater_than_equals_with_reference)
- {
- ls::std::boxing::Float x{3.1414f};
- ls::std::boxing::Float y{3.1414f};
- ls::std::boxing::Float z{3.1415f};
- ASSERT_TRUE(x >= y);
- ASSERT_TRUE(z >= y);
- }
- TEST_F(FloatTest, operator_greater_than_equals_with_value)
- {
- ls::std::boxing::Float x{3.1414f};
- ls::std::boxing::Float z{3.1415f};
- ASSERT_TRUE(x >= 3.1414f);
- ASSERT_TRUE(z >= 3.1414f);
- }
- TEST_F(FloatTest, operator_less_than_with_reference)
- {
- ls::std::boxing::Float x{3.1413f};
- ls::std::boxing::Float y{3.1414f};
- ASSERT_TRUE(x < y);
- }
- TEST_F(FloatTest, operator_less_than_with_value)
- {
- ls::std::boxing::Float x{3.1413f};
- ASSERT_TRUE(x < 3.1414f);
- }
- TEST_F(FloatTest, operator_less_than_equals_with_reference)
- {
- ls::std::boxing::Float x{3.1414f};
- ls::std::boxing::Float y{3.1414f};
- ls::std::boxing::Float z{3.1415f};
- ASSERT_TRUE(x <= y);
- ASSERT_TRUE(x <= z);
- }
- TEST_F(FloatTest, operator_less_than_equals_with_value)
- {
- ls::std::boxing::Float x{3.1414f};
- ASSERT_TRUE(x <= 3.1414f);
- ASSERT_TRUE(x <= 3.1415f);
- }
- // increment / decrement operator
- TEST_F(FloatTest, operator_increment)
- {
- ls::std::boxing::Float x{3.1415f};
- ++x;
- ASSERT_FLOAT_EQ(4.1415f, x);
- }
- TEST_F(FloatTest, operator_decrement)
- {
- ls::std::boxing::Float x{3.1415f};
- --x;
- ASSERT_FLOAT_EQ(2.1415f, x);
- }
- // implementation
- TEST_F(FloatTest, parse)
- {
- ls::std::boxing::Float number{};
- number.parse("3.1415f");
- ASSERT_FLOAT_EQ(3.1415f, number);
- }
- TEST_F(FloatTest, toString)
- {
- ls::std::boxing::Float x{13.1543f};
- ASSERT_TRUE(x.toString().find("13.1543") != std::string::npos);
- }
- // additional functionality
- TEST_F(FloatTest, getEpsilon)
- {
- ls::std::boxing::Float x{};
- ASSERT_FLOAT_EQ(0.00001f, x.getEpsilon());
- }
- TEST_F(FloatTest, getValue)
- {
- ls::std::boxing::Float x{3.1415f};
- ASSERT_FLOAT_EQ(3.1415f, x.getValue());
- }
- TEST_F(FloatTest, setEpsilon)
- {
- ls::std::boxing::Float x{};
- x.setEpsilon(0.01f);
- ASSERT_FLOAT_EQ(0.01f, x.getEpsilon());
- }
- TEST_F(FloatTest, setEpsilon_invalid_value)
- {
- ls::std::boxing::Float x{};
- EXPECT_THROW({
- try
- {
- x.setEpsilon(0.0f);
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- }
|