Browse Source

Fix clang-tidy warning inside Boolean class

Patrick-Christopher Mattulat 1 year ago
parent
commit
e6e6f2c7a0

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

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

+ 5 - 10
source/ls-std/boxing/Boolean.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-09
- * Changed:         2023-02-07
+ * Changed:         2023-02-22
  *
  * */
 
@@ -19,11 +19,6 @@ ls::std::boxing::Boolean::Boolean() : ls::std::core::Class("Boolean")
 
 ls::std::boxing::Boolean::~Boolean() = default;
 
-ls::std::boxing::Boolean::operator bool() const
-{
-  return this->value;
-}
-
 ls::std::boxing::Boolean &ls::std::boxing::Boolean::operator=(int _value)
 {
   this->value = _value;
@@ -38,7 +33,7 @@ ls::std::boxing::Boolean &ls::std::boxing::Boolean::operator=(bool _value)
 
 bool ls::std::boxing::Boolean::operator&&(const ls::std::boxing::Boolean &_boolean) const
 {
-  return this->value && _boolean;
+  return this->value && _boolean.getValue();
 }
 
 bool ls::std::boxing::Boolean::operator&&(bool _value) const
@@ -53,7 +48,7 @@ bool ls::std::boxing::Boolean::operator&&(int _value) const
 
 bool ls::std::boxing::Boolean::operator||(const ls::std::boxing::Boolean &_boolean) const
 {
-  return this->value || _boolean;
+  return this->value || _boolean.getValue();
 }
 
 bool ls::std::boxing::Boolean::operator||(bool _value) const
@@ -100,7 +95,7 @@ bool ls::std::boxing::Boolean::getValue() const
 
 bool ls::std::boxing::Boolean::XOR(const ls::std::boxing::Boolean &_leftExpression, const ls::std::boxing::Boolean &_rightExpression)
 {
-  return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
+  return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression.getValue());
 }
 
 bool ls::std::boxing::Boolean::XOR(const ls::std::boxing::Boolean &_leftExpression, bool _rightExpression)
@@ -110,7 +105,7 @@ bool ls::std::boxing::Boolean::XOR(const ls::std::boxing::Boolean &_leftExpressi
 
 bool ls::std::boxing::Boolean::XOR(bool _leftExpression, const ls::std::boxing::Boolean &_rightExpression)
 {
-  return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
+  return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression.getValue());
 }
 
 bool ls::std::boxing::Boolean::XOR(bool _leftExpression, bool _rightExpression)

+ 12 - 12
test/cases/boxing/BooleanTest.cpp

@@ -39,7 +39,7 @@ namespace
     Boolean expression{};
     expression = true;
 
-    ASSERT_TRUE(expression);
+    ASSERT_TRUE(expression.getValue());
   }
 
   TEST_F(BooleanTest, operator_assignment_integer)
@@ -47,7 +47,7 @@ namespace
     Boolean expression{};
     expression = 1;
 
-    ASSERT_TRUE(expression);
+    ASSERT_TRUE(expression.getValue());
   }
 
   // stream operators
@@ -78,19 +78,19 @@ namespace
   TEST_F(BooleanTest, operator_and)
   {
     Boolean expressionA{true};
-    Boolean expressionB{3 == 3};
+    Boolean expressionB{true};
 
     ASSERT_TRUE(expressionA && expressionB);
     ASSERT_TRUE(expressionB && expressionA);
     ASSERT_TRUE(expressionA && true);
     ASSERT_TRUE(expressionA && 1);
-    ASSERT_TRUE(1 && expressionB);
+    ASSERT_TRUE(1 && expressionB.getValue());
   }
 
   TEST_F(BooleanTest, operator_and_with_false_result)
   {
     Boolean expressionA{true};
-    Boolean expressionB{3 == 4};
+    Boolean expressionB{false};
 
     ASSERT_FALSE(expressionA && expressionB);
     ASSERT_FALSE(expressionB && expressionA);
@@ -102,25 +102,25 @@ namespace
   TEST_F(BooleanTest, operator_or)
   {
     Boolean expressionA{false};
-    Boolean expressionB{3 == 3};
+    Boolean expressionB{true};
 
     ASSERT_TRUE(expressionA || expressionB);
     ASSERT_TRUE(expressionB || expressionA);
     ASSERT_TRUE(expressionA || 1);
     ASSERT_TRUE(expressionA || true);
-    ASSERT_TRUE(1 || expressionA);
+    ASSERT_TRUE(1 || expressionA.getValue());
   }
 
   TEST_F(BooleanTest, operator_or_with_false_result)
   {
     Boolean expressionA{false};
-    Boolean expressionB{3 == 4};
+    Boolean expressionB{false};
 
     ASSERT_FALSE(expressionA || expressionB);
     ASSERT_FALSE(expressionB || expressionA);
     ASSERT_FALSE(expressionA || 0);
     ASSERT_FALSE(expressionA || false);
-    ASSERT_FALSE(0 || expressionA);
+    ASSERT_FALSE(0 || expressionA.getValue());
   }
 
   // implementation
@@ -130,13 +130,13 @@ namespace
     Boolean expression{};
 
     expression.parse("true");
-    ASSERT_TRUE(expression);
+    ASSERT_TRUE(expression.getValue());
 
     expression.parse("tRue");
-    ASSERT_TRUE(expression);
+    ASSERT_TRUE(expression.getValue());
 
     expression.parse("TRUE");
-    ASSERT_TRUE(expression);
+    ASSERT_TRUE(expression.getValue());
   }
 
   TEST_F(BooleanTest, parse_false_value)