Эх сурвалжийг харах

Fix clang-tidy warnings inside Float class

Patrick-Christopher Mattulat 1 жил өмнө
parent
commit
efd9f9c18b

+ 3 - 7
include/ls-std/boxing/Float.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 Float(float _value);
       ~Float() override;
 
-      // conversion operator
-
-      operator float() const; // do not make explicit!
-
       // assignment operators
 
       ls::std::boxing::Float &operator=(float _value);
@@ -83,8 +79,8 @@ namespace ls::std::boxing
 
       // additional functionality
 
-      [[nodiscard]] float getEpsilon();
-      [[nodiscard]] float getValue();
+      [[nodiscard]] float getEpsilon() const;
+      [[nodiscard]] float getValue() const;
       void setEpsilon(float _epsilon);
 
     private:

+ 17 - 22
source/ls-std/boxing/Float.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
  *
  * */
 
@@ -19,11 +19,6 @@ ls::std::boxing::Float::Float(float _value) : ls::std::core::Class("Float"), eps
 
 ls::std::boxing::Float::~Float() = default;
 
-ls::std::boxing::Float::operator float() const
-{
-  return this->value;
-}
-
 ls::std::boxing::Float &ls::std::boxing::Float::operator=(float _value)
 {
   this->value = _value;
@@ -37,7 +32,7 @@ float ls::std::boxing::Float::operator-() const
 
 float ls::std::boxing::Float::operator+(const ls::std::boxing::Float &_float) const
 {
-  return this->value + _float;
+  return this->value + _float.getValue();
 }
 
 float ls::std::boxing::Float::operator+(float _value) const
@@ -47,7 +42,7 @@ float ls::std::boxing::Float::operator+(float _value) const
 
 float ls::std::boxing::Float::operator*(const ls::std::boxing::Float &_float) const
 {
-  return this->value * _float;
+  return this->value * _float.getValue();
 }
 
 float ls::std::boxing::Float::operator*(float _value) const
@@ -57,7 +52,7 @@ float ls::std::boxing::Float::operator*(float _value) const
 
 float ls::std::boxing::Float::operator-(const ls::std::boxing::Float &_float) const
 {
-  return this->value - _float;
+  return this->value - _float.getValue();
 }
 
 float ls::std::boxing::Float::operator-(float _value) const
@@ -67,7 +62,7 @@ float ls::std::boxing::Float::operator-(float _value) const
 
 float ls::std::boxing::Float::operator/(const ls::std::boxing::Float &_float) const
 {
-  return this->value / _float;
+  return this->value / _float.getValue();
 }
 
 float ls::std::boxing::Float::operator/(float _value) const
@@ -77,7 +72,7 @@ float ls::std::boxing::Float::operator/(float _value) const
 
 ls::std::boxing::Float &ls::std::boxing::Float::operator+=(const ls::std::boxing::Float &_float)
 {
-  this->value += _float;
+  this->value += _float.getValue();
   return *this;
 }
 
@@ -89,7 +84,7 @@ ls::std::boxing::Float &ls::std::boxing::Float::operator+=(float _value)
 
 ls::std::boxing::Float &ls::std::boxing::Float::operator-=(const ls::std::boxing::Float &_float)
 {
-  this->value -= _float;
+  this->value -= _float.getValue();
   return *this;
 }
 
@@ -101,7 +96,7 @@ ls::std::boxing::Float &ls::std::boxing::Float::operator-=(float _value)
 
 ls::std::boxing::Float &ls::std::boxing::Float::operator*=(const ls::std::boxing::Float &_float)
 {
-  this->value *= _float;
+  this->value *= _float.getValue();
   return *this;
 }
 
@@ -113,7 +108,7 @@ ls::std::boxing::Float &ls::std::boxing::Float::operator*=(float _value)
 
 ls::std::boxing::Float &ls::std::boxing::Float::operator/=(const ls::std::boxing::Float &_float)
 {
-  this->value /= _float;
+  this->value /= _float.getValue();
   return *this;
 }
 
@@ -125,7 +120,7 @@ ls::std::boxing::Float &ls::std::boxing::Float::operator/=(float _value)
 
 bool ls::std::boxing::Float::operator==(const ls::std::boxing::Float &_float) const
 {
-  return ::std::fabs(this->value - _float) < this->epsilon;
+  return ::std::fabs(this->value - _float.getValue()) < this->epsilon;
 }
 
 bool ls::std::boxing::Float::operator==(float _value) const
@@ -135,7 +130,7 @@ bool ls::std::boxing::Float::operator==(float _value) const
 
 bool ls::std::boxing::Float::operator!=(const ls::std::boxing::Float &_float) const
 {
-  return ::std::fabs(this->value - _float) >= this->epsilon;
+  return ::std::fabs(this->value - _float.getValue()) >= this->epsilon;
 }
 
 bool ls::std::boxing::Float::operator!=(float _value) const
@@ -145,7 +140,7 @@ bool ls::std::boxing::Float::operator!=(float _value) const
 
 bool ls::std::boxing::Float::operator>(const ls::std::boxing::Float &_float) const
 {
-  return this->value > _float;
+  return this->value > _float.getValue();
 }
 
 bool ls::std::boxing::Float::operator>(float _value) const
@@ -155,7 +150,7 @@ bool ls::std::boxing::Float::operator>(float _value) const
 
 bool ls::std::boxing::Float::operator>=(const ls::std::boxing::Float &_float) const
 {
-  return this->value >= _float;
+  return this->value >= _float.getValue();
 }
 
 bool ls::std::boxing::Float::operator>=(float _value) const
@@ -165,7 +160,7 @@ bool ls::std::boxing::Float::operator>=(float _value) const
 
 bool ls::std::boxing::Float::operator<(const ls::std::boxing::Float &_float) const
 {
-  return this->value < _float;
+  return this->value < _float.getValue();
 }
 
 bool ls::std::boxing::Float::operator<(float _value) const
@@ -175,7 +170,7 @@ bool ls::std::boxing::Float::operator<(float _value) const
 
 bool ls::std::boxing::Float::operator<=(const ls::std::boxing::Float &_float) const
 {
-  return this->value <= _float;
+  return this->value <= _float.getValue();
 }
 
 bool ls::std::boxing::Float::operator<=(float _value) const
@@ -203,12 +198,12 @@ void ls::std::boxing::Float::parse(::std::string _parseText)
   return ::std::to_string(this->value);
 }
 
-float ls::std::boxing::Float::getEpsilon()
+float ls::std::boxing::Float::getEpsilon() const
 {
   return this->epsilon;
 }
 
-float ls::std::boxing::Float::getValue()
+float ls::std::boxing::Float::getValue() const
 {
   return this->value;
 }

+ 16 - 16
test/cases/boxing/FloatTest.cpp

@@ -39,7 +39,7 @@ namespace
     Float x{13.023f};
 
     x = 44.22f;
-    ASSERT_EQ(44.22f, x);
+    ASSERT_EQ(44.22f, x.getValue());
   }
 
   // arithmetic operators
@@ -56,7 +56,7 @@ namespace
     Float y{2.223f};
     Float z{x + y};
 
-    ASSERT_FLOAT_EQ(5.3645f, z);
+    ASSERT_FLOAT_EQ(5.3645f, z.getValue());
   }
 
   TEST_F(FloatTest, operator_addition_with_value)
@@ -71,7 +71,7 @@ namespace
     Float y{2.22f};
     Float z{x * y};
 
-    ASSERT_FLOAT_EQ(6.9708f, z);
+    ASSERT_FLOAT_EQ(6.9708f, z.getValue());
   }
 
   TEST_F(FloatTest, operator_multiplication_with_value)
@@ -86,7 +86,7 @@ namespace
     Float y{2.225f};
     Float z{x - y};
 
-    ASSERT_FLOAT_EQ(0.9165f, z);
+    ASSERT_FLOAT_EQ(0.9165f, z.getValue());
   }
 
   TEST_F(FloatTest, operator_substraction_with_value)
@@ -101,7 +101,7 @@ namespace
     Float y{0.5f};
     Float z{x / y};
 
-    ASSERT_FLOAT_EQ(4.5f, z);
+    ASSERT_FLOAT_EQ(4.5f, z.getValue());
   }
 
   TEST_F(FloatTest, operator_division_with_value)
@@ -118,7 +118,7 @@ namespace
     Float y{3.14f};
     x += y;
 
-    ASSERT_FLOAT_EQ(5.39f, x);
+    ASSERT_FLOAT_EQ(5.39f, x.getValue());
   }
 
   TEST_F(FloatTest, operator_add_assign_with_value)
@@ -126,7 +126,7 @@ namespace
     Float x{2.25f};
     x += 3.14f;
 
-    ASSERT_FLOAT_EQ(5.39f, x);
+    ASSERT_FLOAT_EQ(5.39f, x.getValue());
   }
 
   TEST_F(FloatTest, operator_sub_assign_with_reference)
@@ -135,7 +135,7 @@ namespace
     Float y{1.14f};
     x -= y;
 
-    ASSERT_FLOAT_EQ(1.11f, x);
+    ASSERT_FLOAT_EQ(1.11f, x.getValue());
   }
 
   TEST_F(FloatTest, operator_sub_assign_with_value)
@@ -143,7 +143,7 @@ namespace
     Float x{2.25f};
     x -= 1.14f;
 
-    ASSERT_FLOAT_EQ(1.11f, x);
+    ASSERT_FLOAT_EQ(1.11f, x.getValue());
   }
 
   TEST_F(FloatTest, operator_mul_assign_with_reference)
@@ -152,7 +152,7 @@ namespace
     Float y{0.04f};
     x *= y;
 
-    ASSERT_FLOAT_EQ(0.09f, x);
+    ASSERT_FLOAT_EQ(0.09f, x.getValue());
   }
 
   TEST_F(FloatTest, operator_mul_assign_with_value)
@@ -160,7 +160,7 @@ namespace
     Float x{2.25f};
     x *= 1.14f;
 
-    ASSERT_FLOAT_EQ(2.565f, x);
+    ASSERT_FLOAT_EQ(2.565f, x.getValue());
   }
 
   TEST_F(FloatTest, operator_division_assign_with_reference)
@@ -169,7 +169,7 @@ namespace
     Float y{1.5f};
     x /= y;
 
-    ASSERT_FLOAT_EQ(1.5f, x);
+    ASSERT_FLOAT_EQ(1.5f, x.getValue());
   }
 
   TEST_F(FloatTest, operator_division_assign_with_value)
@@ -177,7 +177,7 @@ namespace
     Float x{2.25f};
     x /= 0.05f;
 
-    ASSERT_FLOAT_EQ(45.0f, x);
+    ASSERT_FLOAT_EQ(45.0f, x.getValue());
   }
 
   // comparison operators
@@ -285,7 +285,7 @@ namespace
     Float x{3.1415f};
     ++x;
 
-    ASSERT_FLOAT_EQ(4.1415f, x);
+    ASSERT_FLOAT_EQ(4.1415f, x.getValue());
   }
 
   TEST_F(FloatTest, operator_decrement)
@@ -293,7 +293,7 @@ namespace
     Float x{3.1415f};
     --x;
 
-    ASSERT_FLOAT_EQ(2.1415f, x);
+    ASSERT_FLOAT_EQ(2.1415f, x.getValue());
   }
 
   // implementation
@@ -303,7 +303,7 @@ namespace
     Float number{};
 
     number.parse("3.1415f");
-    ASSERT_FLOAT_EQ(3.1415f, number);
+    ASSERT_FLOAT_EQ(3.1415f, number.getValue());
   }
 
   TEST_F(FloatTest, toString)