Added Math::Mod method

This commit is contained in:
Leonetienne
2021-11-15 16:10:07 +01:00
parent e699a20f11
commit 6926ebab1c
5 changed files with 111 additions and 0 deletions

83
Test/Math__Mod.cpp Normal file
View File

@@ -0,0 +1,83 @@
#include "CppUnitTest.h"
#include "../Eule/Math.h"
#include <stdexcept>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Eule;
/** Equivalence classes:
* a -> numerator
* b -> denominator
* -- a > 0 && b > 0
* -- a < 0 && b > 0
* -- a > 0 && b < 0
* -- a < 0 && b < 0
*
* -- a > 0 && b = 0
* -- a = 0 && b > 0
* * -- a < 0 && b = 0
* -- a = 0 && b < 0
* -- a = 0 && b = 0
*/
namespace _Math
{
TEST_CLASS(_Mod)
{
public:
// a > 0 && b > 0
TEST_METHOD(a_gt_0_and_b_gt_0)
{
Assert::AreEqual(7, Math::Mod(199, 32));
return;
}
// a < 0 && b > 0
TEST_METHOD(a_lt_0_and_b_gt_0)
{
Assert::AreEqual(25, Math::Mod(-199, 32));
return;
}
// a > 0 && b < 0
TEST_METHOD(a_gt_0_and_b_lt_0)
{
Assert::AreEqual(-25, Math::Mod(199, -32));
return;
}
// a > 0 && b = 0
TEST_METHOD(a_gt_0_and_b_eq_0)
{
// Exppect divide-by-zero
Assert::ExpectException<std::logic_error&>([]() {
Assert::AreEqual(0, Math::Mod(199, 0));
});
return;
}
// a = 0 && b > 0
TEST_METHOD(a_eq_0_and_b_gt_0)
{
Assert::AreEqual(0, Math::Mod(0, 32));
return;
}
// a < 0 && b = 0
TEST_METHOD(a_lt_0_and_b_eq_0)
{
// Exppect divide-by-zero
Assert::ExpectException<std::logic_error&>([]() {
Assert::AreEqual(0, Math::Mod(-199, 0));
});
return;
}
// a = 0 && b < 0
TEST_METHOD(a_eq_0_and_b_lt_0)
{
Assert::AreEqual(0, Math::Mod(0, -32));
return;
}
};
}

View File

@@ -33,6 +33,7 @@
<ClCompile Include="Math_RandomInteger.cpp" />
<ClCompile Include="Math_RandomIntRange.cpp" />
<ClCompile Include="Math_Similar.cpp" />
<ClCompile Include="Math__Mod.cpp" />
<ClCompile Include="Math__Oscillate.cpp" />
<ClCompile Include="Math__RandomRange.cpp" />
<ClCompile Include="Matrix4x4.cpp" />

View File

@@ -75,5 +75,8 @@
<ClCompile Include="TrapazoidalPrismCollider.cpp">
<Filter>Tests</Filter>
</ClCompile>
<ClCompile Include="Math__Mod.cpp">
<Filter>Tests\Math</Filter>
</ClCompile>
</ItemGroup>
</Project>