Browse Source

Fix clang-tidy warnings inside Double class

Patrick-Christopher Mattulat 1 year ago
parent
commit
3c7bbd4e6e
3 changed files with 39 additions and 48 deletions
  1. 3 7
      include/ls-std/boxing/Double.hpp
  2. 17 22
      source/ls-std/boxing/Double.cpp
  3. 19 19
      test/cases/boxing/DoubleTest.cpp

+ 3 - 7
include/ls-std/boxing/Double.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2023-02-06
+ * Changed:         2023-02-22
  *
  * */
 
@@ -25,10 +25,6 @@ namespace ls::std::boxing
       explicit Double(double _value);
       ~Double() override;
 
-      // conversion operator
-
-      operator double() const; // do not make explicit!
-
       // assignment operators
 
       ls::std::boxing::Double &operator=(double _value);
@@ -83,8 +79,8 @@ namespace ls::std::boxing
 
       // additional functionality
 
-      [[nodiscard]] double getEpsilon();
-      [[nodiscard]] double getValue();
+      [[nodiscard]] double getEpsilon() const;
+      [[nodiscard]] double getValue() const;
       void setEpsilon(double _epsilon);
 
     private:

+ 17 - 22
source/ls-std/boxing/Double.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2023-02-07
+ * Changed:         2023-02-22
  *
  * */
 
@@ -23,11 +23,6 @@ ls::std::boxing::Double::Double(double _value) : ls::std::core::Class("Double"),
 
 ls::std::boxing::Double::~Double() = default;
 
-ls::std::boxing::Double::operator double() const
-{
-  return this->value;
-}
-
 ls::std::boxing::Double &ls::std::boxing::Double::operator=(double _value)
 {
   this->value = _value;
@@ -41,7 +36,7 @@ double ls::std::boxing::Double::operator-() const
 
 double ls::std::boxing::Double::operator+(const ls::std::boxing::Double &_double) const
 {
-  return this->value + _double;
+  return this->value + _double.getValue();
 }
 
 double ls::std::boxing::Double::operator+(double _value) const
@@ -51,7 +46,7 @@ double ls::std::boxing::Double::operator+(double _value) const
 
 double ls::std::boxing::Double::operator*(const ls::std::boxing::Double &_double) const
 {
-  return this->value * _double;
+  return this->value * _double.getValue();
 }
 
 double ls::std::boxing::Double::operator*(double _value) const
@@ -61,7 +56,7 @@ double ls::std::boxing::Double::operator*(double _value) const
 
 double ls::std::boxing::Double::operator-(const ls::std::boxing::Double &_double) const
 {
-  return this->value - _double;
+  return this->value - _double.getValue();
 }
 
 double ls::std::boxing::Double::operator-(double _value) const
@@ -71,7 +66,7 @@ double ls::std::boxing::Double::operator-(double _value) const
 
 double ls::std::boxing::Double::operator/(const ls::std::boxing::Double &_double) const
 {
-  return this->value / _double;
+  return this->value / _double.getValue();
 }
 
 double ls::std::boxing::Double::operator/(double _value) const
@@ -81,7 +76,7 @@ double ls::std::boxing::Double::operator/(double _value) const
 
 ls::std::boxing::Double &ls::std::boxing::Double::operator+=(const ls::std::boxing::Double &_double)
 {
-  this->value += _double;
+  this->value += _double.getValue();
   return *this;
 }
 
@@ -93,7 +88,7 @@ ls::std::boxing::Double &ls::std::boxing::Double::operator+=(double _value)
 
 ls::std::boxing::Double &ls::std::boxing::Double::operator-=(const ls::std::boxing::Double &_double)
 {
-  this->value -= _double;
+  this->value -= _double.getValue();
   return *this;
 }
 
@@ -105,7 +100,7 @@ ls::std::boxing::Double &ls::std::boxing::Double::operator-=(double _value)
 
 ls::std::boxing::Double &ls::std::boxing::Double::operator*=(const ls::std::boxing::Double &_double)
 {
-  this->value *= _double;
+  this->value *= _double.getValue();
   return *this;
 }
 
@@ -117,7 +112,7 @@ ls::std::boxing::Double &ls::std::boxing::Double::operator*=(double _value)
 
 ls::std::boxing::Double &ls::std::boxing::Double::operator/=(const ls::std::boxing::Double &_double)
 {
-  this->value /= _double;
+  this->value /= _double.getValue();
   return *this;
 }
 
@@ -129,7 +124,7 @@ ls::std::boxing::Double &ls::std::boxing::Double::operator/=(double _value)
 
 bool ls::std::boxing::Double::operator==(const ls::std::boxing::Double &_double) const
 {
-  return ::std::fabs(this->value - _double) < this->epsilon;
+  return ::std::fabs(this->value - _double.getValue()) < this->epsilon;
 }
 
 bool ls::std::boxing::Double::operator==(double _value) const
@@ -139,7 +134,7 @@ bool ls::std::boxing::Double::operator==(double _value) const
 
 bool ls::std::boxing::Double::operator!=(const ls::std::boxing::Double &_double) const
 {
-  return ::std::fabs(this->value - _double) >= this->epsilon;
+  return ::std::fabs(this->value - _double.getValue()) >= this->epsilon;
 }
 
 bool ls::std::boxing::Double::operator!=(double _value) const
@@ -149,7 +144,7 @@ bool ls::std::boxing::Double::operator!=(double _value) const
 
 bool ls::std::boxing::Double::operator>(const ls::std::boxing::Double &_double) const
 {
-  return this->value > _double;
+  return this->value > _double.getValue();
 }
 
 bool ls::std::boxing::Double::operator>(double _value) const
@@ -159,7 +154,7 @@ bool ls::std::boxing::Double::operator>(double _value) const
 
 bool ls::std::boxing::Double::operator>=(const ls::std::boxing::Double &_double) const
 {
-  return this->value >= _double;
+  return this->value >= _double.getValue();
 }
 
 bool ls::std::boxing::Double::operator>=(double _value) const
@@ -169,7 +164,7 @@ bool ls::std::boxing::Double::operator>=(double _value) const
 
 bool ls::std::boxing::Double::operator<(const ls::std::boxing::Double &_double) const
 {
-  return this->value < _double;
+  return this->value < _double.getValue();
 }
 
 bool ls::std::boxing::Double::operator<(double _value) const
@@ -179,7 +174,7 @@ bool ls::std::boxing::Double::operator<(double _value) const
 
 bool ls::std::boxing::Double::operator<=(const ls::std::boxing::Double &_double) const
 {
-  return this->value <= _double;
+  return this->value <= _double.getValue();
 }
 
 bool ls::std::boxing::Double::operator<=(double _value) const
@@ -207,12 +202,12 @@ void ls::std::boxing::Double::parse(::std::string _parseText)
   return ::std::to_string(this->value);
 }
 
-double ls::std::boxing::Double::getEpsilon()
+double ls::std::boxing::Double::getEpsilon() const
 {
   return this->epsilon;
 }
 
-double ls::std::boxing::Double::getValue()
+double ls::std::boxing::Double::getValue() const
 {
   return this->value;
 }

+ 19 - 19
test/cases/boxing/DoubleTest.cpp

@@ -40,7 +40,7 @@ namespace
     Double x{};
     x = 44.22;
 
-    ASSERT_EQ(44.22, x);
+    ASSERT_EQ(44.22, x.getValue());
   }
 
   // arithmetic operators
@@ -57,7 +57,7 @@ namespace
     Double y{2.223};
     Double z{x + y};
 
-    ASSERT_DOUBLE_EQ(5.3645, z);
+    ASSERT_DOUBLE_EQ(5.3645, z.getValue());
   }
 
   TEST_F(DoubleTest, operator_addition_with_value)
@@ -72,7 +72,7 @@ namespace
     Double y{2.22};
     Double z{x * y};
 
-    ASSERT_DOUBLE_EQ(6.9708, z);
+    ASSERT_DOUBLE_EQ(6.9708, z.getValue());
   }
 
   TEST_F(DoubleTest, operator_multiplication_with_value)
@@ -87,7 +87,7 @@ namespace
     Double y{2.225};
     Double z{x - y};
 
-    ASSERT_DOUBLE_EQ(0.9165, z);
+    ASSERT_DOUBLE_EQ(0.9165, z.getValue());
   }
 
   TEST_F(DoubleTest, operator_substraction_with_value)
@@ -102,7 +102,7 @@ namespace
     Double y{0.5};
     Double z{x / y};
 
-    ASSERT_DOUBLE_EQ(4.5, z);
+    ASSERT_DOUBLE_EQ(4.5, z.getValue());
   }
 
   TEST_F(DoubleTest, operator_division_with_value)
@@ -119,7 +119,7 @@ namespace
     Double y{3.14000000};
 
     x += y;
-    ASSERT_DOUBLE_EQ(5.39000000, x);
+    ASSERT_DOUBLE_EQ(5.39000000, x.getValue());
   }
 
   TEST_F(DoubleTest, operator_add_assign_with_value)
@@ -127,7 +127,7 @@ namespace
     Double x{2.25000000};
 
     x += 3.14000000;
-    ASSERT_DOUBLE_EQ(5.39000000, x);
+    ASSERT_DOUBLE_EQ(5.39000000, x.getValue());
   }
 
   TEST_F(DoubleTest, operator_sub_assign_with_reference)
@@ -136,7 +136,7 @@ namespace
     Double y{0.04};
 
     x -= y;
-    ASSERT_DOUBLE_EQ(2.21, x);
+    ASSERT_DOUBLE_EQ(2.21, x.getValue());
   }
 
   TEST_F(DoubleTest, operator_sub_assign_with_value)
@@ -144,7 +144,7 @@ namespace
     Double x{2.25};
 
     x -= 0.04;
-    ASSERT_DOUBLE_EQ(2.21, x);
+    ASSERT_DOUBLE_EQ(2.21, x.getValue());
   }
 
   TEST_F(DoubleTest, operator_mul_assign_with_reference)
@@ -153,7 +153,7 @@ namespace
     Double y{0.04000000};
 
     x *= y;
-    ASSERT_DOUBLE_EQ(0.09000000, x);
+    ASSERT_DOUBLE_EQ(0.09000000, x.getValue());
   }
 
   TEST_F(DoubleTest, operator_mul_assign_with_value)
@@ -161,7 +161,7 @@ namespace
     Double x{2.25000000};
 
     x *= 0.04000000;
-    ASSERT_DOUBLE_EQ(0.09000000, x);
+    ASSERT_DOUBLE_EQ(0.09000000, x.getValue());
   }
 
   TEST_F(DoubleTest, operator_division_assign_with_reference)
@@ -170,7 +170,7 @@ namespace
     Double y{0.05};
 
     x /= y;
-    ASSERT_DOUBLE_EQ(45.0, x);
+    ASSERT_DOUBLE_EQ(45.0, x.getValue());
   }
 
   TEST_F(DoubleTest, operator_division_assign_with_value)
@@ -178,7 +178,7 @@ namespace
     Double x{2.25};
 
     x /= 0.05;
-    ASSERT_DOUBLE_EQ(45.0, x);
+    ASSERT_DOUBLE_EQ(45.0, x.getValue());
   }
 
   // comparison operators
@@ -197,7 +197,7 @@ namespace
     Double x{3.14159};
 
     ASSERT_TRUE(x == 3.14159);
-    ASSERT_TRUE(3.14159 == x);
+    ASSERT_TRUE(3.14159 == x.getValue());
   }
 
   TEST_F(DoubleTest, operator_not_equal_with_reference)
@@ -214,7 +214,7 @@ namespace
     Double x{3.1415};
 
     ASSERT_TRUE(x != 3.1414);
-    ASSERT_TRUE(3.1414 != x);
+    ASSERT_TRUE(3.1414 != x.getValue());
   }
 
   TEST_F(DoubleTest, operator_greater_than_with_reference)
@@ -288,7 +288,7 @@ namespace
     Double x{3.1415};
 
     ++x;
-    ASSERT_DOUBLE_EQ(4.1415, x);
+    ASSERT_DOUBLE_EQ(4.1415, x.getValue());
   }
 
   TEST_F(DoubleTest, operator_decrement)
@@ -296,7 +296,7 @@ namespace
     Double x{3.1415};
 
     --x;
-    ASSERT_DOUBLE_EQ(2.1415, x);
+    ASSERT_DOUBLE_EQ(2.1415, x.getValue());
   }
 
   // implementation
@@ -306,7 +306,7 @@ namespace
     Double x{};
 
     x.parse("3.1415");
-    ASSERT_DOUBLE_EQ(3.1415, x);
+    ASSERT_DOUBLE_EQ(3.1415, x.getValue());
   }
 
   TEST_F(DoubleTest, parse_with_negative_value)
@@ -314,7 +314,7 @@ namespace
     Double x{};
 
     x.parse("-2.1415");
-    ASSERT_DOUBLE_EQ(-2.1415, x);
+    ASSERT_DOUBLE_EQ(-2.1415, x.getValue());
   }
 
   TEST_F(DoubleTest, toString)