Translated Math/Oscillate tests
This commit is contained in:
parent
ebdf8b85dd
commit
d17993a322
@ -1,22 +1,13 @@
|
|||||||
#include "CppUnitTest.h"
|
|
||||||
#include "../_TestingUtilities/Testutil.h"
|
#include "../_TestingUtilities/Testutil.h"
|
||||||
#include "../Eule/Random.h"
|
#include "Catch2.h"
|
||||||
#include "../Eule/Math.h"
|
#include <Eule/Random.h>
|
||||||
#include "../Eule/Constants.h"
|
#include <Eule/Math.h>
|
||||||
#include <array>
|
#include <Eule/Constants.h>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
||||||
using namespace Eule;
|
using namespace Eule;
|
||||||
|
|
||||||
namespace _Math
|
|
||||||
{
|
|
||||||
TEST_CLASS(_Oscillate)
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Checks that an oscillation of speed 1 between -1 and 1 is just equal to sin(counter*pi-pi/2)
|
// Checks that an oscillation of speed 1 between -1 and 1 is just equal to sin(counter*pi-pi/2)
|
||||||
TEST_METHOD(Oracle_Sin)
|
TEST_CASE("Oracle_Sin", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
// Test 1000 random floats
|
// Test 1000 random floats
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
@ -29,14 +20,14 @@ namespace _Math
|
|||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
const double expected = sin(rnd * PI - HALF_PI);
|
const double expected = sin(rnd * PI - HALF_PI);
|
||||||
Assert::IsTrue(Math::Similar(expected, result));
|
REQUIRE(Math::Similar(expected, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the result is a, if the counter is 0 or a whole, even integer
|
// Tests that the result is a, if the counter is 0 or a whole, even integer
|
||||||
TEST_METHOD(Returns_a_For_Counter_0)
|
TEST_CASE("Returns_a_For_Counter_0", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
// Test 1000 random floats
|
// Test 1000 random floats
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
@ -52,20 +43,19 @@ namespace _Math
|
|||||||
// Verify
|
// Verify
|
||||||
const double expected = a;
|
const double expected = a;
|
||||||
|
|
||||||
std::wstringstream wss;
|
INFO(
|
||||||
wss << std::endl
|
"a: " << a << '\n'
|
||||||
<< "a: " << a << std::endl
|
<< "b: " << b << '\n'
|
||||||
<< "b: " << b << std::endl
|
<< "expected: " << expected << '\n'
|
||||||
<< "expected: " << expected << std::endl
|
<< "result: " << result << '\n'
|
||||||
<< "result: " << result << std::endl
|
);
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
Assert::IsTrue(Math::Similar(expected, result), wss.str().c_str());
|
REQUIRE(Math::Similar(expected, result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the result is b, if the counter is a whole, uneven integer
|
// Tests that the result is b, if the counter is a whole, uneven integer
|
||||||
TEST_METHOD(Returns_b_For_Uneven_Whole_Counter)
|
TEST_CASE("Returns_b_For_Uneven_Whole_Counter", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
// Test 1000 random floats
|
// Test 1000 random floats
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
@ -80,12 +70,12 @@ namespace _Math
|
|||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
const double expected = b;
|
const double expected = b;
|
||||||
Assert::IsTrue(Math::Similar(expected, result));
|
REQUIRE(Math::Similar(expected, result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the result is (a+b)/2, when counter satisfies (int)x + 0.5
|
// Tests that the result is (a+b)/2, when counter satisfies (int)x + 0.5
|
||||||
TEST_METHOD(Returns_ab_mean_for_intx_plus_0p5)
|
TEST_CASE("Returns_ab_mean_for_intx_plus_0p5", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
// Test 1000 random floats
|
// Test 1000 random floats
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
@ -101,19 +91,20 @@ namespace _Math
|
|||||||
// Verify
|
// Verify
|
||||||
const double expected = (a+b) / 2.0;
|
const double expected = (a+b) / 2.0;
|
||||||
|
|
||||||
std::wstringstream wss;
|
INFO(
|
||||||
wss << std::endl
|
"a: " << a << '\n'
|
||||||
<< "a: " << a << std::endl
|
<< "b: " << b << '\n'
|
||||||
<< "b: " << b << std::endl
|
<< "expected: " << expected << '\n'
|
||||||
<< "expected: " << expected << std::endl
|
<< "result: " << result << '\n'
|
||||||
<< "result: " << result << std::endl
|
<< '\n'
|
||||||
<< std::endl;
|
);
|
||||||
Assert::IsTrue(Math::Similar(expected, result), wss.str().c_str());
|
|
||||||
|
REQUIRE(Math::Similar(expected, result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the result is (3a+b)/4, when counter satisfies 2(int)x + 0.25
|
// Tests that the result is (3a+b)/4, when counter satisfies 2(int)x + 0.25
|
||||||
TEST_METHOD(Returns_3ab_mean_for_intx_plus_0p25_counterbase_even)
|
TEST_CASE("Returns_3ab_mean_for_intx_plus_0p25_counterbase_even", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
// Test 1000 random floats
|
// Test 1000 random floats
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
@ -129,21 +120,20 @@ namespace _Math
|
|||||||
// Verify
|
// Verify
|
||||||
const double expected = (3*a + b) / 4.0;
|
const double expected = (3*a + b) / 4.0;
|
||||||
|
|
||||||
std::wstringstream wss;
|
INFO(
|
||||||
wss << std::endl
|
"a: " << a << '\n'
|
||||||
<< "a: " << a << std::endl
|
<< "b: " << b << '\n'
|
||||||
<< "b: " << b << std::endl
|
<< "expected: " << expected << '\n'
|
||||||
<< "expected: " << expected << std::endl
|
<< "result: " << result << '\n'
|
||||||
<< "result: " << result << std::endl
|
);
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
// Oscillate is not linear, we just want a really rough approximation
|
// Oscillate is not linear, we just want a really rough approximation
|
||||||
Assert::IsTrue(Math::Similar(expected, result, 0.4), wss.str().c_str());
|
REQUIRE(Math::Similar(expected, result, 0.4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the result is (a+3b)/4, when counter satisfies 2(int)x + 0.75
|
// Tests that the result is (a+3b)/4, when counter satisfies 2(int)x + 0.75
|
||||||
TEST_METHOD(Returns_a3b_mean_for_intx_plus_0p75_counterbase_even)
|
TEST_CASE("Returns_a3b_mean_for_intx_plus_0p75_counterbase_even", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
// Test 1000 random floats
|
// Test 1000 random floats
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
@ -160,12 +150,12 @@ namespace _Math
|
|||||||
const double expected = (a + 3*b) / 4.0;
|
const double expected = (a + 3*b) / 4.0;
|
||||||
|
|
||||||
// Oscillate is not linear, we just want a really rough approximation
|
// Oscillate is not linear, we just want a really rough approximation
|
||||||
Assert::IsTrue(Math::Similar(expected, result, 0.4)); // Oscillate is not linear
|
REQUIRE(Math::Similar(expected, result, 0.4)); // Oscillate is not linear
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the result is (a+3b)/4, when counter satisfies 2(int)x+1 + 0.25
|
// Tests that the result is (a+3b)/4, when counter satisfies 2(int)x+1 + 0.25
|
||||||
TEST_METHOD(Returns_3ab_mean_for_intx_plus_0p25_counterbase_uneven)
|
TEST_CASE("Returns_3ab_mean_for_intx_plus_0p25_counterbase_uneven", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
// Test 1000 random floats
|
// Test 1000 random floats
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
@ -182,12 +172,12 @@ namespace _Math
|
|||||||
const double expected = (a + 3*b) / 4.0;
|
const double expected = (a + 3*b) / 4.0;
|
||||||
|
|
||||||
// Oscillate is not linear, we just want a really rough approximation
|
// Oscillate is not linear, we just want a really rough approximation
|
||||||
Assert::IsTrue(Math::Similar(expected, result, 0.4));
|
REQUIRE(Math::Similar(expected, result, 0.4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the result is (3a+b)/4, when counter satisfies 2(int)x+1 + 0.75
|
// Tests that the result is (3a+b)/4, when counter satisfies 2(int)x+1 + 0.75
|
||||||
TEST_METHOD(Returns_a3b_mean_for_intx_plus_0p75_counterbase_uneven)
|
TEST_CASE("Returns_a3b_mean_for_intx_plus_0p75_counterbase_uneven", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
// Test 1000 random floats
|
// Test 1000 random floats
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
@ -204,12 +194,12 @@ namespace _Math
|
|||||||
const double expected = (3*a + b) / 4.0;
|
const double expected = (3*a + b) / 4.0;
|
||||||
|
|
||||||
// Oscillate is not linear, we just want a really rough approximation
|
// Oscillate is not linear, we just want a really rough approximation
|
||||||
Assert::IsTrue(Math::Similar(expected, result, 0.4)); // Oscillate is not linear
|
REQUIRE(Math::Similar(expected, result, 0.4)); // Oscillate is not linear
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that doubling the speed will double the frequency
|
// Tests that doubling the speed will double the frequency
|
||||||
TEST_METHOD(Doubling_Speed_Doubles_Frequency)
|
TEST_CASE("Doubling_Speed_Doubles_Frequency", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
// Test 1000 random floats
|
// Test 1000 random floats
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
@ -223,10 +213,8 @@ namespace _Math
|
|||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
const double expected = b;
|
const double expected = b;
|
||||||
Assert::IsTrue(Math::Similar(expected, result));
|
REQUIRE(Math::Similar(expected, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user