Просмотр исходного кода

Fix clang-tidy warning inside Integer class

Patrick-Christopher Mattulat 1 год назад
Родитель
Сommit
9655e94ad6
3 измененных файлов с 34 добавлено и 43 удалено
  1. 1 5
      include/ls-std/boxing/Integer.hpp
  2. 18 23
      source/ls-std/boxing/Integer.cpp
  3. 15 15
      test/cases/boxing/IntegerTest.cpp

+ 1 - 5
include/ls-std/boxing/Integer.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-07
- * Changed:         2023-02-06
+ * Changed:         2023-02-22
  *
  * */
 
@@ -25,10 +25,6 @@ namespace ls::std::boxing
       Integer();
       ~Integer() override;
 
-      // conversion operator
-
-      operator int() const;
-
       // assignment operators
 
       ls::std::boxing::Integer &operator=(int _value);

+ 18 - 23
source/ls-std/boxing/Integer.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-07
- * Changed:         2023-02-07
+ * Changed:         2023-02-22
  *
  * */
 
@@ -18,11 +18,6 @@ ls::std::boxing::Integer::Integer() : ls::std::core::Class("Integer")
 
 ls::std::boxing::Integer::~Integer() = default;
 
-ls::std::boxing::Integer::operator int() const
-{
-  return this->value;
-}
-
 ls::std::boxing::Integer &ls::std::boxing::Integer::operator=(int _value)
 {
   this->value = _value;
@@ -36,7 +31,7 @@ int ls::std::boxing::Integer::operator-() const
 
 int ls::std::boxing::Integer::operator+(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value + _integer;
+  return this->value + _integer.getValue();
 }
 
 int ls::std::boxing::Integer::operator+(int _value) const
@@ -46,7 +41,7 @@ int ls::std::boxing::Integer::operator+(int _value) const
 
 int ls::std::boxing::Integer::operator*(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value * _integer;
+  return this->value * _integer.getValue();
 }
 
 int ls::std::boxing::Integer::operator*(int _value) const
@@ -56,7 +51,7 @@ int ls::std::boxing::Integer::operator*(int _value) const
 
 int ls::std::boxing::Integer::operator-(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value - _integer;
+  return this->value - _integer.getValue();
 }
 
 int ls::std::boxing::Integer::operator-(int _value) const
@@ -71,7 +66,7 @@ int ls::std::boxing::Integer::operator/(const ls::std::boxing::Integer &_integer
     throw ls::std::core::IllegalArithmeticOperationException{"division by zero is not allowed"};
   }
 
-  return this->value / _integer;
+  return this->value / _integer.getValue();
 }
 
 int ls::std::boxing::Integer::operator/(int _value) const
@@ -86,7 +81,7 @@ int ls::std::boxing::Integer::operator/(int _value) const
 
 int ls::std::boxing::Integer::operator%(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value % _integer;
+  return this->value % _integer.getValue();
 }
 
 int ls::std::boxing::Integer::operator%(int _value) const
@@ -96,7 +91,7 @@ int ls::std::boxing::Integer::operator%(int _value) const
 
 ls::std::boxing::Integer &ls::std::boxing::Integer::operator+=(const ls::std::boxing::Integer &_integer)
 {
-  this->value += _integer;
+  this->value += _integer.getValue();
   return *this;
 }
 
@@ -108,7 +103,7 @@ ls::std::boxing::Integer &ls::std::boxing::Integer::operator+=(int _value)
 
 ls::std::boxing::Integer &ls::std::boxing::Integer::operator-=(const ls::std::boxing::Integer &_integer)
 {
-  this->value -= _integer;
+  this->value -= _integer.getValue();
   return *this;
 }
 
@@ -120,7 +115,7 @@ ls::std::boxing::Integer &ls::std::boxing::Integer::operator-=(int _value)
 
 ls::std::boxing::Integer &ls::std::boxing::Integer::operator*=(const ls::std::boxing::Integer &_integer)
 {
-  this->value *= _integer;
+  this->value *= _integer.getValue();
   return *this;
 }
 
@@ -137,7 +132,7 @@ ls::std::boxing::Integer &ls::std::boxing::Integer::operator/=(const ls::std::bo
     throw ls::std::core::IllegalArithmeticOperationException{"division by zero is not allowed"};
   }
 
-  this->value /= _integer;
+  this->value /= _integer.getValue();
   return *this;
 }
 
@@ -154,7 +149,7 @@ ls::std::boxing::Integer &ls::std::boxing::Integer::operator/=(int _value)
 
 bool ls::std::boxing::Integer::operator==(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value == _integer;
+  return this->value == _integer.getValue();
 }
 
 bool ls::std::boxing::Integer::operator==(int _value) const
@@ -164,7 +159,7 @@ bool ls::std::boxing::Integer::operator==(int _value) const
 
 bool ls::std::boxing::Integer::operator!=(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value != _integer;
+  return this->value != _integer.getValue();
 }
 
 bool ls::std::boxing::Integer::operator!=(int _value) const
@@ -174,7 +169,7 @@ bool ls::std::boxing::Integer::operator!=(int _value) const
 
 bool ls::std::boxing::Integer::operator>(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value > _integer;
+  return this->value > _integer.getValue();
 }
 
 bool ls::std::boxing::Integer::operator>(int _value) const
@@ -184,7 +179,7 @@ bool ls::std::boxing::Integer::operator>(int _value) const
 
 bool ls::std::boxing::Integer::operator>=(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value >= _integer;
+  return this->value >= _integer.getValue();
 }
 
 bool ls::std::boxing::Integer::operator>=(int _value) const
@@ -194,7 +189,7 @@ bool ls::std::boxing::Integer::operator>=(int _value) const
 
 bool ls::std::boxing::Integer::operator<(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value < _integer;
+  return this->value < _integer.getValue();
 }
 
 bool ls::std::boxing::Integer::operator<(int _value) const
@@ -204,7 +199,7 @@ bool ls::std::boxing::Integer::operator<(int _value) const
 
 bool ls::std::boxing::Integer::operator<=(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value <= _integer;
+  return this->value <= _integer.getValue();
 }
 
 bool ls::std::boxing::Integer::operator<=(int _value) const
@@ -214,7 +209,7 @@ bool ls::std::boxing::Integer::operator<=(int _value) const
 
 bool ls::std::boxing::Integer::operator&&(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value && _integer;
+  return this->value && _integer.getValue();
 }
 
 bool ls::std::boxing::Integer::operator&&(int _value) const
@@ -229,7 +224,7 @@ bool ls::std::boxing::Integer::operator&&(bool _expression) const
 
 bool ls::std::boxing::Integer::operator||(const ls::std::boxing::Integer &_integer) const
 {
-  return this->value || _integer;
+  return this->value || _integer.getValue();
 }
 
 bool ls::std::boxing::Integer::operator||(int _value) const

+ 15 - 15
test/cases/boxing/IntegerTest.cpp

@@ -39,7 +39,7 @@ namespace
     Integer y{3};
     x = y;
 
-    ASSERT_EQ(3, x);
+    ASSERT_EQ(3, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_assignment_with_value)
@@ -47,7 +47,7 @@ namespace
     Integer x{};
     x = 44;
 
-    ASSERT_EQ(44, x);
+    ASSERT_EQ(44, x.getValue());
   }
 
   // arithmetic operators
@@ -175,7 +175,7 @@ namespace
     Integer y{2};
     x += y;
 
-    ASSERT_EQ(6, x);
+    ASSERT_EQ(6, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_add_assign_with_value)
@@ -183,7 +183,7 @@ namespace
     Integer x{4};
     x += 2;
 
-    ASSERT_EQ(6, x);
+    ASSERT_EQ(6, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_sub_assign_with_reference)
@@ -192,7 +192,7 @@ namespace
     Integer y{2};
     x -= y;
 
-    ASSERT_EQ(12, x);
+    ASSERT_EQ(12, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_sub_assign_with_value)
@@ -200,7 +200,7 @@ namespace
     Integer x{14};
     x -= 2;
 
-    ASSERT_EQ(12, x);
+    ASSERT_EQ(12, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_mul_assign_with_reference)
@@ -209,7 +209,7 @@ namespace
     Integer y{3};
     x *= y;
 
-    ASSERT_EQ(18, x);
+    ASSERT_EQ(18, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_mul_assign_with_value)
@@ -217,7 +217,7 @@ namespace
     Integer x{6};
     x *= 3;
 
-    ASSERT_EQ(18, x);
+    ASSERT_EQ(18, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_div_assign_with_reference)
@@ -226,7 +226,7 @@ namespace
     Integer y{3};
     x /= y;
 
-    ASSERT_EQ(4, x);
+    ASSERT_EQ(4, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_div_assign_with_value)
@@ -234,7 +234,7 @@ namespace
     Integer x{12};
     x /= 3;
 
-    ASSERT_EQ(4, x);
+    ASSERT_EQ(4, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_div_assign_by_zero_with_reference)
@@ -415,7 +415,7 @@ namespace
     Integer x{};
     ++x;
 
-    ASSERT_EQ(1, x);
+    ASSERT_EQ(1, x.getValue());
   }
 
   TEST_F(IntegerTest, operator_decrement)
@@ -423,7 +423,7 @@ namespace
     Integer x{};
 
     --x;
-    ASSERT_EQ(-1, x);
+    ASSERT_EQ(-1, x.getValue());
   }
 
   // implementation
@@ -433,7 +433,7 @@ namespace
     Integer number{};
 
     number.parse("1989");
-    ASSERT_EQ(1989, number);
+    ASSERT_EQ(1989, number.getValue());
   }
 
   TEST_F(IntegerTest, parse_with_negative_value)
@@ -441,7 +441,7 @@ namespace
     Integer number{};
 
     number.parse("-13");
-    ASSERT_EQ(-13, number);
+    ASSERT_EQ(-13, number.getValue());
   }
 
   TEST_F(IntegerTest, toString)
@@ -463,7 +463,7 @@ namespace
   TEST_F(IntegerTest, constApproach)
   {
     const Integer x{3};
-    ASSERT_EQ(3, x);
+    ASSERT_EQ(3, x.getValue());
 
     // x = 4; // wouldn't work
   }