From 6f5c15b165979a4fcf5dbc99bdd065311f77a4dd Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Wed, 19 Nov 2014 22:22:57 +0000 Subject: [PATCH] simplex_interpolator: adding first test on 2D samples --- src/lol/math/all.h | 1 + src/t/math/simplex_interpolator.cpp | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lol/math/all.h b/src/lol/math/all.h index d24d3802..0a0320dd 100644 --- a/src/lol/math/all.h +++ b/src/lol/math/all.h @@ -22,4 +22,5 @@ #include #include #include +#include diff --git a/src/t/math/simplex_interpolator.cpp b/src/t/math/simplex_interpolator.cpp index 735fd4d0..2686f1df 100644 --- a/src/t/math/simplex_interpolator.cpp +++ b/src/t/math/simplex_interpolator.cpp @@ -2,6 +2,8 @@ // Lol Engine // // Copyright: (c) 2010-2014 Sam Hocevar +// (c) 2013-2014 Benjamin "Touky" Huet +// (c) 2013-2014 Guillaume Bittoun // This program is free software; you can redistribute it and/or // modify it under the terms of the Do What The Fuck You Want To // Public License, Version 2, as published by Sam Hocevar. See @@ -12,10 +14,6 @@ #include -// To be removed when fully tested -#include -#include - namespace lol { @@ -25,13 +23,18 @@ lolunit_declare_fixture(SimplexInterpolatorTest) void TearDown() {} - lolunit_declare_test(Interp2D) + lolunit_declare_test(Interp2D9PointsTest) { - simplex_interpolator<2> interpolator; + simplex_interpolator<2> interpolator; - interpolator.GetSamples() = arraynd<2, float>({{1, 1, 2}, {1, 1, 2}, {2, 2, 2}}); + interpolator.GetSamples() = arraynd<2, float>({{1, 1, 2}, {1, 2, 2}, {2, 2, 2}}); - std::cout << interpolator.Interp(vec_t{0, 0}) << std::endl; + lolunit_assert_equal(interpolator.Interp(vec_t{0, 0}), 1); + lolunit_assert_equal(interpolator.Interp(vec_t{1, 0}), 1); + lolunit_assert_doubles_equal(interpolator.Interp(vec_t{(float)cos(3.14159/3), (float)sin(3.14159/3)}), 1, 1e-5f); + + lolunit_assert(interpolator.Interp(vec_t{0, 0.5}) > 1); + lolunit_assert(interpolator.Interp(vec_t{0, 0.5}) < 2); } };