Added Math::Mod method
This commit is contained in:
83
Test/Math__Mod.cpp
Normal file
83
Test/Math__Mod.cpp
Normal 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;
|
||||
}
|
||||
};
|
||||
}
|
@@ -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" />
|
||||
|
@@ -75,5 +75,8 @@
|
||||
<ClCompile Include="TrapazoidalPrismCollider.cpp">
|
||||
<Filter>Tests</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Math__Mod.cpp">
|
||||
<Filter>Tests\Math</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user