Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/test/function_test.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/test/function_test.cpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/test/function_test.cpp')
-rw-r--r--source/test/function_test.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/source/test/function_test.cpp b/source/test/function_test.cpp
new file mode 100644
index 0000000..94e6157
--- /dev/null
+++ b/source/test/function_test.cpp
@@ -0,0 +1,57 @@
+#include "StarStoredFunctions.hpp"
+
+#include "gtest/gtest.h"
+
+using namespace Star;
+
+TEST(StoredFunctionTest, All) {
+ List<pair<double, double>> values = {{0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 4.0f}, {3.0f, 9.0f}, {4.0f, 16.0f}};
+ ParametricFunction<double, double> function(values, InterpolationMode::Linear, BoundMode::Clamp);
+ StoredFunction levelingFunction(function);
+
+ EXPECT_LT(fabs(function.interpolate(2.5f) - 6.5f), 0.001f);
+
+ auto result = levelingFunction.search(16.0f);
+ EXPECT_TRUE(result.found);
+ EXPECT_LT(fabs(result.value - 16.0f), 0.001f);
+ EXPECT_LT(fabs(result.solution - 4.0f), 0.001f);
+
+ result = levelingFunction.search(0.0f);
+ EXPECT_TRUE(result.found);
+ EXPECT_LT(fabs(result.value - 0.0f), 0.001f);
+ EXPECT_LT(fabs(result.solution - 0.0f), 0.001f);
+
+ result = levelingFunction.search(6.5f);
+ EXPECT_TRUE(result.found);
+ EXPECT_LT(fabs(result.value - 6.5f), 0.001f);
+ EXPECT_LT(fabs(result.solution - 2.5f), 0.001f);
+
+ List<pair<double, double>> swordsValues = {{0.0f, 0.0f}, {1.0f, 10.0f}, {100.0f, 500.0f}, {9999.0f, 9999999.0f}};
+ ParametricFunction<double, double> swordsFunction(swordsValues, InterpolationMode::Linear, BoundMode::Clamp);
+ StoredFunction swordsLevelingFunction(swordsFunction);
+
+ result = swordsLevelingFunction.search(0.0f);
+ EXPECT_TRUE(result.found);
+ EXPECT_LT(fabs(result.value - 0.0f), 0.001f);
+ EXPECT_LT(fabs(result.solution - 0.0f), 0.001f);
+
+ result = swordsLevelingFunction.search(10.0f);
+ EXPECT_TRUE(result.found);
+ EXPECT_LT(fabs(result.value - 10.0f), 0.001f);
+ EXPECT_LT(fabs(result.solution - 1.0f), 0.001f);
+
+ result = swordsLevelingFunction.search(500.0f);
+ EXPECT_TRUE(result.found);
+ EXPECT_LT(fabs(result.value - 500.0f), 0.001f);
+ EXPECT_LT(fabs(result.solution - 100.0f), 0.001f);
+
+ result = swordsLevelingFunction.search(501.0f);
+ EXPECT_TRUE(result.found);
+ EXPECT_LT(fabs(result.value - 501.0f), 0.001f);
+ EXPECT_LT(fabs(result.solution - 100.0f), 0.001f);
+
+ result = swordsLevelingFunction.search(500.01f);
+ EXPECT_TRUE(result.found);
+ EXPECT_LT(fabs(result.value - 500.01f), 0.001f);
+ EXPECT_LT(fabs(result.solution - 100.0f), 0.001f);
+}