Translated Math/Oscillate tests
This commit is contained in:
parent
ebdf8b85dd
commit
d17993a322
@ -1,232 +1,220 @@
|
|||||||
#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
|
// Checks that an oscillation of speed 1 between -1 and 1 is just equal to sin(counter*pi-pi/2)
|
||||||
|
TEST_CASE("Oracle_Sin", "[Math][Oscillate]")
|
||||||
{
|
{
|
||||||
TEST_CLASS(_Oscillate)
|
// Test 1000 random floats
|
||||||
{
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
public:
|
{
|
||||||
|
// Setup
|
||||||
|
const double rnd = Random::RandomRange(-1000, 1000);
|
||||||
|
|
||||||
// Checks that an oscillation of speed 1 between -1 and 1 is just equal to sin(counter*pi-pi/2)
|
// Exercise
|
||||||
TEST_METHOD(Oracle_Sin)
|
const double result = Math::Oscillate(-1, 1, rnd, 1);
|
||||||
{
|
|
||||||
// Test 1000 random floats
|
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
|
||||||
{
|
|
||||||
// Setup
|
|
||||||
const double rnd = Random::RandomRange(-1000, 1000);
|
|
||||||
|
|
||||||
// Exercise
|
// Verify
|
||||||
const double result = Math::Oscillate(-1, 1, rnd, 1);
|
const double expected = sin(rnd * PI - HALF_PI);
|
||||||
|
REQUIRE(Math::Similar(expected, result));
|
||||||
|
}
|
||||||
|
|
||||||
// Verify
|
return;
|
||||||
const double expected = sin(rnd * PI - HALF_PI);
|
}
|
||||||
Assert::IsTrue(Math::Similar(expected, result));
|
|
||||||
}
|
// Tests that the result is a, if the counter is 0 or a whole, even integer
|
||||||
|
TEST_CASE("Returns_a_For_Counter_0", "[Math][Oscillate]")
|
||||||
return;
|
{
|
||||||
}
|
// Test 1000 random floats
|
||||||
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
// Tests that the result is a, if the counter is 0 or a whole, even integer
|
{
|
||||||
TEST_METHOD(Returns_a_For_Counter_0)
|
// Setup
|
||||||
{
|
const double a = Random::RandomRange(-1000, 1000);
|
||||||
// Test 1000 random floats
|
const double b = Random::RandomRange(-1000, 1000);
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
const int even = Random::RandomIntRange(-1000, 1000) & ~1;
|
||||||
{
|
|
||||||
// Setup
|
// Exercise
|
||||||
const double a = Random::RandomRange(-1000, 1000);
|
const double result = Math::Oscillate(a, b, even, 1);
|
||||||
const double b = Random::RandomRange(-1000, 1000);
|
|
||||||
const int even = Random::RandomIntRange(-1000, 1000) & ~1;
|
// Verify
|
||||||
|
const double expected = a;
|
||||||
// Exercise
|
|
||||||
const double result = Math::Oscillate(a, b, even, 1);
|
INFO(
|
||||||
|
"a: " << a << '\n'
|
||||||
// Verify
|
<< "b: " << b << '\n'
|
||||||
const double expected = a;
|
<< "expected: " << expected << '\n'
|
||||||
|
<< "result: " << result << '\n'
|
||||||
std::wstringstream wss;
|
);
|
||||||
wss << std::endl
|
|
||||||
<< "a: " << a << std::endl
|
REQUIRE(Math::Similar(expected, result));
|
||||||
<< "b: " << b << std::endl
|
}
|
||||||
<< "expected: " << expected << std::endl
|
}
|
||||||
<< "result: " << result << std::endl
|
|
||||||
<< std::endl;
|
// Tests that the result is b, if the counter is a whole, uneven integer
|
||||||
|
TEST_CASE("Returns_b_For_Uneven_Whole_Counter", "[Math][Oscillate]")
|
||||||
Assert::IsTrue(Math::Similar(expected, result), wss.str().c_str());
|
{
|
||||||
}
|
// Test 1000 random floats
|
||||||
}
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
// Tests that the result is b, if the counter is a whole, uneven integer
|
// Setup
|
||||||
TEST_METHOD(Returns_b_For_Uneven_Whole_Counter)
|
const double a = Random::RandomRange(-1000, 1000);
|
||||||
{
|
const double b = Random::RandomRange(-1000, 1000);
|
||||||
// Test 1000 random floats
|
const int uneven = Random::RandomIntRange(-1000, 1000) | 1;
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
|
||||||
{
|
// Exercise
|
||||||
// Setup
|
const double result = Math::Oscillate(a, b, uneven, 1);
|
||||||
const double a = Random::RandomRange(-1000, 1000);
|
|
||||||
const double b = Random::RandomRange(-1000, 1000);
|
// Verify
|
||||||
const int uneven = Random::RandomIntRange(-1000, 1000) | 1;
|
const double expected = b;
|
||||||
|
REQUIRE(Math::Similar(expected, result));
|
||||||
// Exercise
|
}
|
||||||
const double result = Math::Oscillate(a, b, uneven, 1);
|
}
|
||||||
|
|
||||||
// Verify
|
// Tests that the result is (a+b)/2, when counter satisfies (int)x + 0.5
|
||||||
const double expected = b;
|
TEST_CASE("Returns_ab_mean_for_intx_plus_0p5", "[Math][Oscillate]")
|
||||||
Assert::IsTrue(Math::Similar(expected, result));
|
{
|
||||||
}
|
// Test 1000 random floats
|
||||||
}
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
// Tests that the result is (a+b)/2, when counter satisfies (int)x + 0.5
|
// Setup
|
||||||
TEST_METHOD(Returns_ab_mean_for_intx_plus_0p5)
|
const double a = Random::RandomRange(-1000, 1000);
|
||||||
{
|
const double b = Random::RandomRange(-1000, 1000);
|
||||||
// Test 1000 random floats
|
const int anInt = Random::RandomIntRange(-1000, 1000);
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
|
||||||
{
|
// Exercise
|
||||||
// Setup
|
const double result = Math::Oscillate(a, b, anInt + 0.5, 1);
|
||||||
const double a = Random::RandomRange(-1000, 1000);
|
|
||||||
const double b = Random::RandomRange(-1000, 1000);
|
// Verify
|
||||||
const int anInt = Random::RandomIntRange(-1000, 1000);
|
const double expected = (a+b) / 2.0;
|
||||||
|
|
||||||
// Exercise
|
INFO(
|
||||||
const double result = Math::Oscillate(a, b, anInt + 0.5, 1);
|
"a: " << a << '\n'
|
||||||
|
<< "b: " << b << '\n'
|
||||||
// Verify
|
<< "expected: " << expected << '\n'
|
||||||
const double expected = (a+b) / 2.0;
|
<< "result: " << result << '\n'
|
||||||
|
<< '\n'
|
||||||
std::wstringstream wss;
|
);
|
||||||
wss << std::endl
|
|
||||||
<< "a: " << a << std::endl
|
REQUIRE(Math::Similar(expected, result));
|
||||||
<< "b: " << b << std::endl
|
}
|
||||||
<< "expected: " << expected << std::endl
|
}
|
||||||
<< "result: " << result << std::endl
|
|
||||||
<< std::endl;
|
// Tests that the result is (3a+b)/4, when counter satisfies 2(int)x + 0.25
|
||||||
Assert::IsTrue(Math::Similar(expected, result), wss.str().c_str());
|
TEST_CASE("Returns_3ab_mean_for_intx_plus_0p25_counterbase_even", "[Math][Oscillate]")
|
||||||
}
|
{
|
||||||
}
|
// Test 1000 random floats
|
||||||
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
// 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)
|
// Setup
|
||||||
{
|
const double a = Random::RandomRange(-1, 1);
|
||||||
// Test 1000 random floats
|
const double b = Random::RandomRange(-1, 1);
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
const int even = Random::RandomIntRange(-1000, 1000) & ~1;
|
||||||
{
|
|
||||||
// Setup
|
// Exercise
|
||||||
const double a = Random::RandomRange(-1, 1);
|
const double result = Math::Oscillate(a, b, even + 0.25, 1);
|
||||||
const double b = Random::RandomRange(-1, 1);
|
|
||||||
const int even = Random::RandomIntRange(-1000, 1000) & ~1;
|
// Verify
|
||||||
|
const double expected = (3*a + b) / 4.0;
|
||||||
// Exercise
|
|
||||||
const double result = Math::Oscillate(a, b, even + 0.25, 1);
|
INFO(
|
||||||
|
"a: " << a << '\n'
|
||||||
// Verify
|
<< "b: " << b << '\n'
|
||||||
const double expected = (3*a + b) / 4.0;
|
<< "expected: " << expected << '\n'
|
||||||
|
<< "result: " << result << '\n'
|
||||||
std::wstringstream wss;
|
);
|
||||||
wss << std::endl
|
|
||||||
<< "a: " << a << std::endl
|
// Oscillate is not linear, we just want a really rough approximation
|
||||||
<< "b: " << b << std::endl
|
REQUIRE(Math::Similar(expected, result, 0.4));
|
||||||
<< "expected: " << expected << std::endl
|
}
|
||||||
<< "result: " << result << std::endl
|
}
|
||||||
<< std::endl;
|
|
||||||
|
// Tests that the result is (a+3b)/4, when counter satisfies 2(int)x + 0.75
|
||||||
// Oscillate is not linear, we just want a really rough approximation
|
TEST_CASE("Returns_a3b_mean_for_intx_plus_0p75_counterbase_even", "[Math][Oscillate]")
|
||||||
Assert::IsTrue(Math::Similar(expected, result, 0.4), wss.str().c_str());
|
{
|
||||||
}
|
// Test 1000 random floats
|
||||||
}
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
// Tests that the result is (a+3b)/4, when counter satisfies 2(int)x + 0.75
|
// Setup
|
||||||
TEST_METHOD(Returns_a3b_mean_for_intx_plus_0p75_counterbase_even)
|
const double a = Random::RandomRange(-1, 1);
|
||||||
{
|
const double b = Random::RandomRange(-1, 1);
|
||||||
// Test 1000 random floats
|
const int even = Random::RandomIntRange(-1000, 1000) & ~1;
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
|
||||||
{
|
// Exercise
|
||||||
// Setup
|
const double result = Math::Oscillate(a, b, even + 0.75, 1);
|
||||||
const double a = Random::RandomRange(-1, 1);
|
|
||||||
const double b = Random::RandomRange(-1, 1);
|
// Verify
|
||||||
const int even = Random::RandomIntRange(-1000, 1000) & ~1;
|
const double expected = (a + 3*b) / 4.0;
|
||||||
|
|
||||||
// Exercise
|
// Oscillate is not linear, we just want a really rough approximation
|
||||||
const double result = Math::Oscillate(a, b, even + 0.75, 1);
|
REQUIRE(Math::Similar(expected, result, 0.4)); // Oscillate is not linear
|
||||||
|
}
|
||||||
// Verify
|
}
|
||||||
const double expected = (a + 3*b) / 4.0;
|
|
||||||
|
// Tests that the result is (a+3b)/4, when counter satisfies 2(int)x+1 + 0.25
|
||||||
// Oscillate is not linear, we just want a really rough approximation
|
TEST_CASE("Returns_3ab_mean_for_intx_plus_0p25_counterbase_uneven", "[Math][Oscillate]")
|
||||||
Assert::IsTrue(Math::Similar(expected, result, 0.4)); // Oscillate is not linear
|
{
|
||||||
}
|
// Test 1000 random floats
|
||||||
}
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
// Tests that the result is (a+3b)/4, when counter satisfies 2(int)x+1 + 0.25
|
// Setup
|
||||||
TEST_METHOD(Returns_3ab_mean_for_intx_plus_0p25_counterbase_uneven)
|
const double a = Random::RandomRange(-1, 1);
|
||||||
{
|
const double b = Random::RandomRange(-1, 1);
|
||||||
// Test 1000 random floats
|
const int uneven = Random::RandomIntRange(-1000, 1000) | 1;
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
|
||||||
{
|
// Exercise
|
||||||
// Setup
|
const double result = Math::Oscillate(a, b, uneven + 0.25, 1);
|
||||||
const double a = Random::RandomRange(-1, 1);
|
|
||||||
const double b = Random::RandomRange(-1, 1);
|
// Verify
|
||||||
const int uneven = Random::RandomIntRange(-1000, 1000) | 1;
|
const double expected = (a + 3*b) / 4.0;
|
||||||
|
|
||||||
// Exercise
|
// Oscillate is not linear, we just want a really rough approximation
|
||||||
const double result = Math::Oscillate(a, b, uneven + 0.25, 1);
|
REQUIRE(Math::Similar(expected, result, 0.4));
|
||||||
|
}
|
||||||
// Verify
|
}
|
||||||
const double expected = (a + 3*b) / 4.0;
|
|
||||||
|
// Tests that the result is (3a+b)/4, when counter satisfies 2(int)x+1 + 0.75
|
||||||
// Oscillate is not linear, we just want a really rough approximation
|
TEST_CASE("Returns_a3b_mean_for_intx_plus_0p75_counterbase_uneven", "[Math][Oscillate]")
|
||||||
Assert::IsTrue(Math::Similar(expected, result, 0.4));
|
{
|
||||||
}
|
// Test 1000 random floats
|
||||||
}
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
// Tests that the result is (3a+b)/4, when counter satisfies 2(int)x+1 + 0.75
|
// Setup
|
||||||
TEST_METHOD(Returns_a3b_mean_for_intx_plus_0p75_counterbase_uneven)
|
const double a = Random::RandomRange(-1, 1);
|
||||||
{
|
const double b = Random::RandomRange(-1, 1);
|
||||||
// Test 1000 random floats
|
const int uneven = Random::RandomIntRange(-1000, 1000) | 1;
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
|
||||||
{
|
// Exercise
|
||||||
// Setup
|
const double result = Math::Oscillate(a, b, uneven + 0.75, 1);
|
||||||
const double a = Random::RandomRange(-1, 1);
|
|
||||||
const double b = Random::RandomRange(-1, 1);
|
// Verify
|
||||||
const int uneven = Random::RandomIntRange(-1000, 1000) | 1;
|
const double expected = (3*a + b) / 4.0;
|
||||||
|
|
||||||
// Exercise
|
// Oscillate is not linear, we just want a really rough approximation
|
||||||
const double result = Math::Oscillate(a, b, uneven + 0.75, 1);
|
REQUIRE(Math::Similar(expected, result, 0.4)); // Oscillate is not linear
|
||||||
|
}
|
||||||
// Verify
|
}
|
||||||
const double expected = (3*a + b) / 4.0;
|
|
||||||
|
// Tests that doubling the speed will double the frequency
|
||||||
// Oscillate is not linear, we just want a really rough approximation
|
TEST_CASE("Doubling_Speed_Doubles_Frequency", "[Math][Oscillate]")
|
||||||
Assert::IsTrue(Math::Similar(expected, result, 0.4)); // Oscillate is not linear
|
{
|
||||||
}
|
// Test 1000 random floats
|
||||||
}
|
for (std::size_t i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
// Tests that doubling the speed will double the frequency
|
// Setup
|
||||||
TEST_METHOD(Doubling_Speed_Doubles_Frequency)
|
const double a = Random::RandomRange(-1000, 1000);
|
||||||
{
|
const double b = Random::RandomRange(-1000, 1000);
|
||||||
// Test 1000 random floats
|
|
||||||
for (std::size_t i = 0; i < 1000; i++)
|
// Exercise
|
||||||
{
|
const double result = Math::Oscillate(a, b, 0.5, 2);
|
||||||
// Setup
|
|
||||||
const double a = Random::RandomRange(-1000, 1000);
|
// Verify
|
||||||
const double b = Random::RandomRange(-1000, 1000);
|
const double expected = b;
|
||||||
|
REQUIRE(Math::Similar(expected, result));
|
||||||
// Exercise
|
}
|
||||||
const double result = Math::Oscillate(a, b, 0.5, 2);
|
|
||||||
|
return;
|
||||||
// Verify
|
|
||||||
const double expected = b;
|
|
||||||
Assert::IsTrue(Math::Similar(expected, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user