IntegerTest.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-09
  6. * Changed: 2020-08-09
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include "../../../source/boxing/Integer.hpp"
  11. namespace
  12. {
  13. class IntegerTest : public ::testing::Test
  14. {
  15. protected:
  16. IntegerTest() = default;
  17. ~IntegerTest() override = default;
  18. void SetUp() override
  19. {}
  20. void TearDown() override
  21. {}
  22. };
  23. TEST_F(IntegerTest, operatorHyphen)
  24. {
  25. ls_std::Integer x {13};
  26. ls_std::Integer y {-13};
  27. ASSERT_EQ(-13, -x);
  28. ASSERT_EQ(13, -y);
  29. }
  30. TEST_F(IntegerTest, operatorAssignment)
  31. {
  32. ls_std::Integer x {13};
  33. ASSERT_EQ(13, x);
  34. x = 44;
  35. ASSERT_EQ(44, x);
  36. }
  37. TEST_F(IntegerTest, operatorAddition)
  38. {
  39. ls_std::Integer x {13};
  40. ls_std::Integer y {7};
  41. ls_std::Integer z {-15};
  42. ASSERT_EQ(20, x + y);
  43. ASSERT_EQ(5, x + y + z);
  44. ASSERT_EQ(15, x + 2);
  45. ASSERT_EQ(0, x + 2 + z);
  46. }
  47. TEST_F(IntegerTest, operatorMultiplication)
  48. {
  49. ls_std::Integer x {3};
  50. ls_std::Integer y {7};
  51. ls_std::Integer z {5};
  52. ASSERT_EQ(21, x * y);
  53. ASSERT_EQ(105, x * y * z);
  54. ASSERT_EQ(6, x * 2);
  55. ASSERT_EQ(71, 1 + y * 2 * z);
  56. }
  57. TEST_F(IntegerTest, operatorSubtraction)
  58. {
  59. ls_std::Integer x {51};
  60. ls_std::Integer y {17};
  61. ASSERT_EQ(34, x - y);
  62. ASSERT_EQ(30, x - 21);
  63. ASSERT_EQ(13, x - 21 - y);
  64. }
  65. TEST_F(IntegerTest, operatorDivision)
  66. {
  67. ls_std::Integer x {81};
  68. ls_std::Integer y {9};
  69. ASSERT_EQ(9, x / y);
  70. ASSERT_EQ(3, 9 / 3);
  71. ASSERT_EQ(3, x / y / 3);
  72. ASSERT_EQ(1, 19 / 10);
  73. }
  74. TEST_F(IntegerTest, parse)
  75. {
  76. ls_std::Integer x {};
  77. x.parse("1989");
  78. ASSERT_EQ(1989, x);
  79. x.parse("-17");
  80. ASSERT_EQ(-17, x);
  81. }
  82. }