Bladeren bron

Improved Long class

- replaced primitive datatype with ls_std::long_type
- adjusted tests for Long class
Patrick 4 jaren geleden
bovenliggende
commit
05a6a7d2d1
3 gewijzigde bestanden met toevoegingen van 83 en 82 verwijderingen
  1. 30 30
      source/boxing/Long.cpp
  2. 30 29
      source/boxing/Long.hpp
  3. 23 23
      test/cases/boxing/LongTest.cpp

+ 30 - 30
source/boxing/Long.cpp

@@ -10,69 +10,69 @@
 #include "Long.hpp"
 #include "../exception/IllegalArithmeticOperationException.hpp"
 
-ls_std::Long::Long(long _value) : Class("Long"),
-value((long) _value)
+ls_std::Long::Long(ls_std::long_type _value) : Class("Long"),
+value(_value)
 {}
 
 ls_std::Long::Long() : Class("Long")
 {}
 
-ls_std::Long::operator long() const
+ls_std::Long::operator ls_std::long_type() const
 {
   return this->value;
 }
 
-ls_std::Long& ls_std::Long::operator=(long _value)
+ls_std::Long& ls_std::Long::operator=(ls_std::long_type _value)
 {
   this->value = _value;
   return *this;
 }
 
-long ls_std::Long::operator-() const
+ls_std::long_type ls_std::Long::operator-() const
 {
   return -this->value;
 }
 
-long ls_std::Long::operator+(const Long &_long) const
+ls_std::long_type ls_std::Long::operator+(const Long &_long) const
 {
   return this->value + _long;
 }
 
-long ls_std::Long::operator+(long _value) const
+ls_std::long_type ls_std::Long::operator+(ls_std::long_type _value) const
 {
   return this->value + _value;
 }
 
-long ls_std::Long::operator*(const Long &_long) const
+ls_std::long_type ls_std::Long::operator*(const Long &_long) const
 {
   return this->value * _long;
 }
 
-long ls_std::Long::operator*(long _value) const
+ls_std::long_type ls_std::Long::operator*(ls_std::long_type _value) const
 {
   return this->value * _value;
 }
 
-long ls_std::Long::operator-(const Long &_long) const
+ls_std::long_type ls_std::Long::operator-(const Long &_long) const
 {
   return this->value - _long;
 }
 
-long ls_std::Long::operator-(long _value) const
+ls_std::long_type ls_std::Long::operator-(ls_std::long_type _value) const
 {
   return this->value - _value;
 }
 
-long ls_std::Long::operator/(const Long &_long) const
+ls_std::long_type ls_std::Long::operator/(const Long &_long) const
 {
-  if(_long == (long) 0) {
+  if(_long == (ls_std::long_type) 0) {
     throw ls_std::IllegalArithmeticOperationException {};
   }
 
   return this->value / _long;
 }
 
-long ls_std::Long::operator/(long _value) const
+ls_std::long_type ls_std::Long::operator/(ls_std::long_type _value) const
 {
   if(_value == 0) {
     throw ls_std::IllegalArithmeticOperationException {};
@@ -81,12 +81,12 @@ long ls_std::Long::operator/(long _value) const
   return this->value / _value;
 }
 
-long ls_std::Long::operator%(const Long &_long) const
+ls_std::long_type ls_std::Long::operator%(const Long &_long) const
 {
   return this->value % _long;
 }
 
-long ls_std::Long::operator%(long _value) const
+ls_std::long_type ls_std::Long::operator%(ls_std::long_type _value) const
 {
   return this->value % _value;
 }
@@ -97,7 +97,7 @@ ls_std::Long & ls_std::Long::operator+=(const Long &_long)
   return *this;
 }
 
-ls_std::Long & ls_std::Long::operator+=(long _value)
+ls_std::Long & ls_std::Long::operator+=(ls_std::long_type _value)
 {
   this->value += _value;
   return *this;
@@ -109,7 +109,7 @@ ls_std::Long & ls_std::Long::operator-=(const Long &_long)
   return *this;
 }
 
-ls_std::Long & ls_std::Long::operator-=(long _value)
+ls_std::Long & ls_std::Long::operator-=(ls_std::long_type _value)
 {
   this->value -= _value;
   return *this;
@@ -121,7 +121,7 @@ ls_std::Long & ls_std::Long::operator*=(const Long &_long)
   return *this;
 }
 
-ls_std::Long & ls_std::Long::operator*=(long _value)
+ls_std::Long & ls_std::Long::operator*=(ls_std::long_type _value)
 {
   this->value *= _value;
   return *this;
@@ -129,7 +129,7 @@ ls_std::Long & ls_std::Long::operator*=(long _value)
 
 ls_std::Long & ls_std::Long::operator/=(const Long &_long)
 {
-  if(_long == (long) 0) {
+  if(_long == (ls_std::long_type) 0) {
     throw ls_std::IllegalArithmeticOperationException {};
   }
 
@@ -137,7 +137,7 @@ ls_std::Long & ls_std::Long::operator/=(const Long &_long)
   return *this;
 }
 
-ls_std::Long & ls_std::Long::operator/=(long _value)
+ls_std::Long & ls_std::Long::operator/=(ls_std::long_type _value)
 {
   if(_value == 0) {
     throw ls_std::IllegalArithmeticOperationException {};
@@ -152,7 +152,7 @@ bool ls_std::Long::operator==(const Long &_long) const
   return this->value == _long;
 }
 
-bool ls_std::Long::operator==(long _value) const
+bool ls_std::Long::operator==(ls_std::long_type _value) const
 {
   return this->value == _value;
 }
@@ -162,7 +162,7 @@ bool ls_std::Long::operator!=(const Long &_long) const
   return this->value != _long;
 }
 
-bool ls_std::Long::operator!=(long _value) const
+bool ls_std::Long::operator!=(ls_std::long_type _value) const
 {
   return this->value != _value;
 }
@@ -172,7 +172,7 @@ bool ls_std::Long::operator>(const Long &_long) const
   return this->value > _long;
 }
 
-bool ls_std::Long::operator>(long _value) const
+bool ls_std::Long::operator>(ls_std::long_type _value) const
 {
   return this->value > _value;
 }
@@ -182,7 +182,7 @@ bool ls_std::Long::operator>=(const Long &_long) const
   return this->value >= _long;
 }
 
-bool ls_std::Long::operator>=(long _value) const
+bool ls_std::Long::operator>=(ls_std::long_type _value) const
 {
   return this->value >= _value;
 }
@@ -192,7 +192,7 @@ bool ls_std::Long::operator<(const Long &_long) const
   return this->value < _long;
 }
 
-bool ls_std::Long::operator<(long _value) const
+bool ls_std::Long::operator<(ls_std::long_type _value) const
 {
   return this->value < _value;
 }
@@ -202,7 +202,7 @@ bool ls_std::Long::operator<=(const Long &_long) const
   return this->value <= _long;
 }
 
-bool ls_std::Long::operator<=(long _value) const
+bool ls_std::Long::operator<=(ls_std::long_type _value) const
 {
   return this->value <= _value;
 }
@@ -212,7 +212,7 @@ bool ls_std::Long::operator&&(const Long &_long) const
   return this->value && _long;
 }
 
-bool ls_std::Long::operator&&(long _value) const
+bool ls_std::Long::operator&&(ls_std::long_type _value) const
 {
   return this->value && _value;
 }
@@ -227,7 +227,7 @@ bool ls_std::Long::operator||(const Long &_long) const
   return this->value || _long;
 }
 
-bool ls_std::Long::operator||(long _value) const
+bool ls_std::Long::operator||(ls_std::long_type _value) const
 {
   return this->value || _value;
 }
@@ -257,6 +257,6 @@ std::string ls_std::Long::toString()
   return std::to_string(this->value);
 }
 
-long ls_std::Long::getValue() const {
+ls_std::long_type ls_std::Long::getValue() const {
   return this->value;
 }

+ 30 - 29
source/boxing/Long.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-17
- * Changed:         2020-08-25
+ * Changed:         2020-08-26
  *
  * */
 
@@ -12,62 +12,63 @@
 
 #include "../base/Class.hpp"
 #include "IBoxing.hpp"
+#include "../base/Types.hpp"
 
 namespace ls_std {
   class Long : public Class, IBoxing {
     public:
 
-      explicit Long(long _value);
+      explicit Long(ls_std::long_type _value);
       Long();
       ~Long() = default;
 
       // conversion operator
 
-      operator long() const;
+      operator ls_std::long_type() const;
 
       // assignment operators
 
-      Long& operator=(long _value);
+      Long& operator=(ls_std::long_type _value);
 
       // arithmetic operators
 
-      long operator-() const;
-      long operator+(const Long& _long) const;
-      long operator+(long _value) const;
-      long operator*(const Long& _long) const;
-      long operator*(long _value) const;
-      long operator-(const Long& _long) const;
-      long operator-(long _value) const;
-      long operator/(const Long& _long) const;
-      long operator/(long _value) const;
-      long operator%(const Long& _long) const;
-      long operator%(long _value) const;
+      ls_std::long_type operator-() const;
+      ls_std::long_type operator+(const Long& _long) const;
+      ls_std::long_type operator+(ls_std::long_type _value) const;
+      ls_std::long_type operator*(const Long& _long) const;
+      ls_std::long_type operator*(ls_std::long_type _value) const;
+      ls_std::long_type operator-(const Long& _long) const;
+      ls_std::long_type operator-(ls_std::long_type _value) const;
+      ls_std::long_type operator/(const Long& _long) const;
+      ls_std::long_type operator/(ls_std::long_type _value) const;
+      ls_std::long_type operator%(const Long& _long) const;
+      ls_std::long_type operator%(ls_std::long_type _value) const;
 
       // compound operators
 
       Long& operator+=(const Long& _long);
-      Long& operator+=(long _value);
+      Long& operator+=(ls_std::long_type _value);
       Long& operator-=(const Long& _long);
-      Long& operator-=(long _value);
+      Long& operator-=(ls_std::long_type _value);
       Long& operator*=(const Long& _long);
-      Long& operator*=(long _value);
+      Long& operator*=(ls_std::long_type _value);
       Long& operator/=(const Long& _long);
-      Long& operator/=(long _value);
+      Long& operator/=(ls_std::long_type _value);
 
       // comparison operators
 
       bool operator==(const Long& _long) const;
-      bool operator==(long _value) const;
+      bool operator==(ls_std::long_type _value) const;
       bool operator!=(const Long& _long) const;
-      bool operator!=(long _value) const;
+      bool operator!=(ls_std::long_type _value) const;
       bool operator>(const Long& _long) const;
-      bool operator>(long _value) const;
+      bool operator>(ls_std::long_type _value) const;
       bool operator>=(const Long& _long) const;
-      bool operator>=(long _value) const;
+      bool operator>=(ls_std::long_type _value) const;
       bool operator<(const Long& _long) const;
-      bool operator<(long _value) const;
+      bool operator<(ls_std::long_type _value) const;
       bool operator<=(const Long& _long) const;
-      bool operator<=(long _value) const;
+      bool operator<=(ls_std::long_type _value) const;
 
       // logical operators
 
@@ -76,10 +77,10 @@ namespace ls_std {
       }
 
       bool operator&&(const Long& _long) const;
-      bool operator&&(long _value) const;
+      bool operator&&(ls_std::long_type _value) const;
       bool operator&&(bool _expression) const;
       bool operator||(const Long& _long) const;
-      bool operator||(long _value) const;
+      bool operator||(ls_std::long_type _value) const;
       bool operator||(bool _expression) const;
 
       // increment / decrement operator
@@ -94,11 +95,11 @@ namespace ls_std {
 
       // additional functionality
 
-      long getValue() const;
+      ls_std::long_type getValue() const;
 
     private:
 
-      long value {};
+      ls_std::long_type value {};
   };
 }
 

+ 23 - 23
test/cases/boxing/LongTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-17
- * Changed:         2020-08-25
+ * Changed:         2020-08-26
  *
  * */
 
@@ -59,8 +59,8 @@ namespace {
     ASSERT_EQ(20, x + y);
     ASSERT_EQ(8, 1 + y);
     ASSERT_EQ(5, x + y + z);
-    ASSERT_EQ(15, x + (long) 2);
-    ASSERT_EQ(0, x + (long) 2 + z);
+    ASSERT_EQ(15, x + (ls_std::long_type) 2);
+    ASSERT_EQ(0, x + (ls_std::long_type) 2 + z);
   }
 
   TEST_F(LongTest, operatorMultiplication)
@@ -71,8 +71,8 @@ namespace {
 
     ASSERT_EQ(21, x * y);
     ASSERT_EQ(105, x * y * z);
-    ASSERT_EQ(6, x * (long) 2);
-    ASSERT_EQ(71, 1 + y * (long) 2 * z);
+    ASSERT_EQ(6, x * (ls_std::long_type) 2);
+    ASSERT_EQ(71, 1 + y * (ls_std::long_type) 2 * z);
   }
 
   TEST_F(LongTest, operatorSubtraction)
@@ -81,8 +81,8 @@ namespace {
     ls_std::Long y {17};
 
     ASSERT_EQ(34, x - y);
-    ASSERT_EQ(30, x - (long) 21);
-    ASSERT_EQ(13, x - (long) 21 - y);
+    ASSERT_EQ(30, x - (ls_std::long_type) 21);
+    ASSERT_EQ(13, x - (ls_std::long_type) 21 - y);
   }
 
   TEST_F(LongTest, operatorDivision)
@@ -102,7 +102,7 @@ namespace {
     ls_std::Long y {9};
 
     ASSERT_EQ(4, x % y);
-    ASSERT_EQ(1, x % (long) 3);
+    ASSERT_EQ(1, x % (ls_std::long_type) 3);
   }
 
   // compound operators
@@ -173,7 +173,7 @@ namespace {
     ls_std::Long y {3};
     ls_std::Long z {3};
 
-    ASSERT_TRUE(x == (long) 12);
+    ASSERT_TRUE(x == (ls_std::long_type) 12);
     ASSERT_TRUE(y == z);
     ASSERT_TRUE(z == y);
   }
@@ -184,7 +184,7 @@ namespace {
     ls_std::Long y {3};
     ls_std::Long z {3};
 
-    ASSERT_TRUE(x != (long) 14);
+    ASSERT_TRUE(x != (ls_std::long_type) 14);
     ASSERT_TRUE(y != x);
     ASSERT_TRUE(z != x);
   }
@@ -194,7 +194,7 @@ namespace {
     ls_std::Long x {12};
     ls_std::Long y {3};
 
-    ASSERT_TRUE(x > (long) 4);
+    ASSERT_TRUE(x > (ls_std::long_type) 4);
     ASSERT_TRUE(x > y);
   }
 
@@ -203,8 +203,8 @@ namespace {
     ls_std::Long x {12};
     ls_std::Long y {3};
 
-    ASSERT_FALSE(x > (long) 14);
-    ASSERT_FALSE(x > (y + (long) 20));
+    ASSERT_FALSE(x > (ls_std::long_type) 14);
+    ASSERT_FALSE(x > (y + (ls_std::long_type) 20));
   }
 
   TEST_F(LongTest, operatorGreaterThanEqual)
@@ -212,7 +212,7 @@ namespace {
     ls_std::Long x {12};
     ls_std::Long y {12};
 
-    ASSERT_TRUE(x >= (long) 12);
+    ASSERT_TRUE(x >= (ls_std::long_type) 12);
     ASSERT_TRUE(x >= y);
   }
 
@@ -221,7 +221,7 @@ namespace {
     ls_std::Long x {12};
     ls_std::Long y {13};
 
-    ASSERT_FALSE(x >= (long) 13);
+    ASSERT_FALSE(x >= (ls_std::long_type) 13);
     ASSERT_FALSE(x >= y);
   }
 
@@ -230,7 +230,7 @@ namespace {
     ls_std::Long x {10};
     ls_std::Long y {12};
 
-    ASSERT_TRUE(x < (long) 12);
+    ASSERT_TRUE(x < (ls_std::long_type) 12);
     ASSERT_TRUE(x < y);
   }
 
@@ -239,7 +239,7 @@ namespace {
     ls_std::Long x {10};
     ls_std::Long y {10};
 
-    ASSERT_FALSE(x < (long) 10);
+    ASSERT_FALSE(x < (ls_std::long_type) 10);
     ASSERT_FALSE(x < y);
   }
 
@@ -248,7 +248,7 @@ namespace {
     ls_std::Long x {10};
     ls_std::Long y {10};
 
-    ASSERT_TRUE(x <= (long) 11);
+    ASSERT_TRUE(x <= (ls_std::long_type) 11);
     ASSERT_TRUE(x <= y);
   }
 
@@ -257,7 +257,7 @@ namespace {
     ls_std::Long x {11};
     ls_std::Long y {10};
 
-    ASSERT_FALSE(x <= (long) 10);
+    ASSERT_FALSE(x <= (ls_std::long_type) 10);
     ASSERT_FALSE(x <= y);
   }
 
@@ -279,7 +279,7 @@ namespace {
   {
     ls_std::Long x {1};
     ls_std::Long y {1};
-    ASSERT_TRUE(x && (long) 1);
+    ASSERT_TRUE(x && (ls_std::long_type) 1);
     ASSERT_TRUE(x && true);
     ASSERT_TRUE(x && y);
   }
@@ -288,7 +288,7 @@ namespace {
   {
     ls_std::Long x {};
     ls_std::Long y {1};
-    ASSERT_FALSE(x && (long) 1);
+    ASSERT_FALSE(x && (ls_std::long_type) 1);
     ASSERT_FALSE(x && true);
     ASSERT_FALSE(x && y);
   }
@@ -297,7 +297,7 @@ namespace {
   {
     ls_std::Long x {};
     ls_std::Long y {1};
-    ASSERT_TRUE(x || (long) 1);
+    ASSERT_TRUE(x || (ls_std::long_type) 1);
     ASSERT_TRUE(x || true);
     ASSERT_TRUE(x || y);
   }
@@ -306,7 +306,7 @@ namespace {
   {
     ls_std::Long x {};
     ls_std::Long y {};
-    ASSERT_FALSE(x || (long) 0);
+    ASSERT_FALSE(x || (ls_std::long_type) 0);
     ASSERT_FALSE(x || false);
     ASSERT_FALSE(x || y);
   }