소스 검색

simplex_interpolator: more unit tests, including some failing ones.

undefined
Sam Hocevar 10 년 전
부모
커밋
3a4682a976
1개의 변경된 파일89개의 추가작업 그리고 7개의 파일을 삭제
  1. +89
    -7
      src/t/math/simplex_interpolator.cpp

+ 89
- 7
src/t/math/simplex_interpolator.cpp 파일 보기

@@ -23,16 +23,98 @@ lolunit_declare_fixture(SimplexInterpolatorTest)

void TearDown() {}

lolunit_declare_test(Interp2D9PointsTest)
lolunit_declare_test(GridPoints2D2x2)
{
simplex_interpolator<2> interpolator({{1, 1, 2}, {1, 2, 2}, {2, 2, 2}});
simplex_interpolator<2> s({{1.f, 1.f}, {1.f, 2.f}});
float val;

lolunit_assert_equal(interpolator.Interp(vec_t<float, 2>{0, 0}), 1);
lolunit_assert_equal(interpolator.Interp(vec_t<float, 2>{1, 0}), 1);
lolunit_assert_doubles_equal(interpolator.Interp(vec_t<float, 2>{(float)cos(3.14159/3), (float)sin(3.14159/3)}), 1, 1e-5f);
val = s.Interp(GridPoint2D(0, 0));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(1, 0));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(0, 1));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(1, 1));
lolunit_assert_doubles_equal(2.f, val, 1e-5f);
}

lolunit_declare_test(MoreGridPoints2D2x2)
{
simplex_interpolator<2> s({{1.f, 1.f}, {1.f, 2.f}});
float val;

val = s.Interp(GridPoint2D(-1, -1));
lolunit_assert_doubles_equal(2.f, val, 1e-5f);
val = s.Interp(GridPoint2D(0, -1));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(1, -1));
lolunit_assert_doubles_equal(2.f, val, 1e-5f);
val = s.Interp(GridPoint2D(2, -1));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(2, 0));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(2, 1));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(2, 2));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(1, 2));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(0, 2));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(-1, 2));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(-1, 1));
lolunit_assert_doubles_equal(2.f, val, 1e-5f);
val = s.Interp(GridPoint2D(-1, 0));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
}

lolunit_declare_test(GridPoints2D3x3)
{
simplex_interpolator<2> s({{1, 1, 2}, {1, 2, 2}, {2, 2, 2}});
float val;

val = s.Interp(GridPoint2D(0, 0));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(1, 0));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(0, 1));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);
val = s.Interp(GridPoint2D(1, 1));
lolunit_assert_doubles_equal(2.f, val, 1e-5f);
}

lolunit_declare_test(OtherPoints2D3x3)
{
simplex_interpolator<2> s({{1, 1, 2}, {1, 2, 2}, {2, 2, 2}});
float val;

/* 1/1 triangle edge */
val = s.Interp(vec2(1.f, lol::sin(F_PI / 3)));
lolunit_assert_doubles_equal(1.5f, val, 1e-5f);

/* 1/1/1 triangle interior */
val = s.Interp(vec2(0.5f, 0.5f));
lolunit_assert_doubles_equal(1.f, val, 1e-5f);

/* 1/1/2 triangle interior */
val = s.Interp(vec2(0.f, 0.5f));
lolunit_assert(val < 2.f);
lolunit_assert(val > 1.f);

/* Another 1/1/2 triangle interior */
val = s.Interp(vec2(1.f, 0.5f));
lolunit_assert(val < 2.f);
lolunit_assert(val > 1.f);
}

private:
vec2 GridPoint2D(int i, int j)
{
static vec2 vi(1.f, 0.f);
static vec2 vj(lol::cos(F_PI / 3), lol::sin(F_PI / 3));

lolunit_assert(interpolator.Interp(vec_t<float, 2>{0, 0.5}) > 1);
lolunit_assert(interpolator.Interp(vec_t<float, 2>{0, 0.5}) < 2);
return (float)i * vi + (float)j * vj;
}
};



불러오는 중...
취소
저장