Browse Source

Extended Integer class

- implemented modulus operator
- extended tests for Integer class
Patrick 4 years ago
parent
commit
76707cde9e
3 changed files with 21 additions and 0 deletions
  1. 10 0
      source/boxing/Integer.cpp
  2. 2 0
      source/boxing/Integer.hpp
  3. 9 0
      test/cases/boxing/IntegerTest.cpp

+ 10 - 0
source/boxing/Integer.cpp

@@ -81,6 +81,16 @@ int ls_std::Integer::operator/(int _value) const
   return this->value / _value;
 }
 
+int ls_std::Integer::operator%(const Integer &_integer) const
+{
+  return this->value % _integer;
+}
+
+int ls_std::Integer::operator%(int _value) const
+{
+  return this->value % _value;
+}
+
 ls_std::Integer & ls_std::Integer::operator+=(const Integer &_integer)
 {
   this->value += _integer;

+ 2 - 0
source/boxing/Integer.hpp

@@ -40,6 +40,8 @@ namespace ls_std {
       int operator-(int _value) const;
       int operator/(const Integer& _integer) const;
       int operator/(int _value) const;
+      int operator%(const Integer& _integer) const;
+      int operator%(int _value) const;
 
       // compound operators
 

+ 9 - 0
test/cases/boxing/IntegerTest.cpp

@@ -93,6 +93,15 @@ namespace
     ASSERT_EQ(1, 19 / 10);
   }
 
+  TEST_F(IntegerTest, operatorModulus)
+  {
+    ls_std::Integer x {85};
+    ls_std::Integer y {9};
+
+    ASSERT_EQ(4, x % y);
+    ASSERT_EQ(1, x % 3);
+  }
+
   // compound operators
 
   TEST_F(IntegerTest, operatorAddEqual)