소스 검색

test: add a unit test of real::cbrt() and fix the camera unit test.

legacy
Sam Hocevar 5 년 전
부모
커밋
fcfafa2035
2개의 변경된 파일149개의 추가작업 그리고 99개의 파일을 삭제
  1. +108
    -97
      src/t/entity/camera.cpp
  2. +41
    -2
      src/t/math/real.cpp

+ 108
- 97
src/t/entity/camera.cpp 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests for the camera object
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// © 2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
//
// Lol Engine is free software. It comes without any warranty, to
@@ -15,12 +15,14 @@

#include <lolunit.h>

#include <memory>

namespace lol
{

lolunit_declare_fixture(camera_test)
{
Camera tc;
Camera *tc; // FIXME: this should be a shared ptr or something
vec3 eye, target, up;
mat4 m_lookat;
quat q_lookat;
@@ -30,6 +32,9 @@ lolunit_declare_fixture(camera_test)

void setup()
{
ticker::setup(60.f);
tc = new Camera();

eye = vec3(0.f, 0.f, 50.f);
target = vec3::zero;
up = vec3::axis_y;
@@ -44,6 +49,12 @@ lolunit_declare_fixture(camera_test)
is_shifted = false;
}

void teardown()
{
//ticker::Unref(tc.get());
ticker::teardown();
}

#define TEST_VECTOR(v0, v1) \
lolunit_assert_doubles_equal(v0.x, v1.x, 1.e-5f); \
lolunit_assert_doubles_equal(v0.y, v1.y, 1.e-5f); \
@@ -51,28 +62,28 @@ lolunit_declare_fixture(camera_test)

lolunit_declare_test(set_view_test)
{
tc.SetView(eye, target, up);
TEST_VECTOR(eye, tc.GetPosition());
TEST_VECTOR(target, tc.GetTarget());
TEST_VECTOR(up, tc.GetUp());
tc.SetView(eye, q_lookat);
TEST_VECTOR(eye, tc.GetPosition());
TEST_VECTOR(target, tc.GetTarget());
TEST_VECTOR(up, tc.GetUp());
tc.SetView(eye, v_lookat);
TEST_VECTOR(eye, tc.GetPosition());
TEST_VECTOR(target, tc.GetTarget());
TEST_VECTOR(up, tc.GetUp());
tc.SetView(m_lookat);
TEST_VECTOR(eye, tc.GetPosition());
TEST_VECTOR(target, tc.GetTarget());
TEST_VECTOR(up, tc.GetUp());
tc.UseTarget(false);
TEST_VECTOR(vec3(0.f, 0.f, 49.f), tc.GetTarget());
tc->SetView(eye, target, up);
TEST_VECTOR(eye, tc->GetPosition());
TEST_VECTOR(target, tc->GetTarget());
TEST_VECTOR(up, tc->GetUp());
tc->SetView(eye, q_lookat);
TEST_VECTOR(eye, tc->GetPosition());
TEST_VECTOR(target, tc->GetTarget());
TEST_VECTOR(up, tc->GetUp());
tc->SetView(eye, v_lookat);
TEST_VECTOR(eye, tc->GetPosition());
TEST_VECTOR(target, tc->GetTarget());
TEST_VECTOR(up, tc->GetUp());
tc->SetView(m_lookat);
TEST_VECTOR(eye, tc->GetPosition());
TEST_VECTOR(target, tc->GetTarget());
TEST_VECTOR(up, tc->GetUp());
tc->UseTarget(false);
TEST_VECTOR(vec3(0.f, 0.f, 49.f), tc->GetTarget());
}

#define TEST_MATRIX(m0, m1) \
@@ -101,83 +112,83 @@ lolunit_declare_fixture(camera_test)
{
mat4 refmx = mat4::perspective(fov, screen_size, screen_size * screen_ratio, near, far);

tc.SetProjection(fov, near, far, screen_size, screen_ratio);
TEST_MATRIX(refmx, tc.GetProjection());
lolunit_assert_doubles_equal(fov, tc.GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc.GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc.GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc.GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc.GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc.IsShifted());
tc.SetProjection(fov, near, far);
TEST_MATRIX(refmx, tc.GetProjection());
lolunit_assert_doubles_equal(fov, tc.GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc.GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc.GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc.GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc.GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc.IsShifted());
tc.SetProjection(refmx);
TEST_MATRIX(refmx, tc.GetProjection());
tc.SetFov(fov);
TEST_MATRIX(refmx, tc.GetProjection());
lolunit_assert_doubles_equal(fov, tc.GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc.GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc.GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc.GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc.GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc.IsShifted());
tc.SetScreenInfos(screen_size);
TEST_MATRIX(refmx, tc.GetProjection());
lolunit_assert_doubles_equal(fov, tc.GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc.GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc.GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc.GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc.GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc.IsShifted());
tc.SetScreenInfos(screen_size, screen_ratio);
TEST_MATRIX(refmx, tc.GetProjection());
lolunit_assert_doubles_equal(fov, tc.GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc.GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc.GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc.GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc.GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc.IsShifted());
tc.SetDrawInfos(far);
TEST_MATRIX(refmx, tc.GetProjection());
lolunit_assert_doubles_equal(fov, tc.GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc.GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc.GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc.GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc.GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc.IsShifted());
tc.SetDrawInfos(near, far);
TEST_MATRIX(refmx, tc.GetProjection());
lolunit_assert_doubles_equal(fov, tc.GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc.GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc.GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc.GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc.GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc.IsShifted());
tc->SetProjection(fov, near, far, screen_size, screen_ratio);
TEST_MATRIX(refmx, tc->GetProjection());
lolunit_assert_doubles_equal(fov, tc->GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc->GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc->GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc->GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc->GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc->IsShifted());
tc->SetProjection(fov, near, far);
TEST_MATRIX(refmx, tc->GetProjection());
lolunit_assert_doubles_equal(fov, tc->GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc->GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc->GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc->GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc->GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc->IsShifted());
tc->SetProjection(refmx);
TEST_MATRIX(refmx, tc->GetProjection());
tc->SetFov(fov);
TEST_MATRIX(refmx, tc->GetProjection());
lolunit_assert_doubles_equal(fov, tc->GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc->GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc->GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc->GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc->GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc->IsShifted());
tc->SetScreenInfos(screen_size);
TEST_MATRIX(refmx, tc->GetProjection());
lolunit_assert_doubles_equal(fov, tc->GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc->GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc->GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc->GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc->GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc->IsShifted());
tc->SetScreenInfos(screen_size, screen_ratio);
TEST_MATRIX(refmx, tc->GetProjection());
lolunit_assert_doubles_equal(fov, tc->GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc->GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc->GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc->GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc->GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc->IsShifted());
tc->SetDrawInfos(far);
TEST_MATRIX(refmx, tc->GetProjection());
lolunit_assert_doubles_equal(fov, tc->GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc->GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc->GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc->GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc->GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc->IsShifted());
tc->SetDrawInfos(near, far);
TEST_MATRIX(refmx, tc->GetProjection());
lolunit_assert_doubles_equal(fov, tc->GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc->GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc->GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc->GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc->GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc->IsShifted());

is_shifted = true;
refmx = mat4::shifted_perspective(fov, screen_size, screen_ratio, near, far);

tc.UseShift(is_shifted);
TEST_MATRIX(refmx, tc.GetProjection());
lolunit_assert_doubles_equal(fov, tc.GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc.GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc.GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc.GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc.GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc.IsShifted());
tc->UseShift(is_shifted);
TEST_MATRIX(refmx, tc->GetProjection());
lolunit_assert_doubles_equal(fov, tc->GetFov(), 1.e-5f);
lolunit_assert_doubles_equal(screen_size, tc->GetScreenSize(), 1.e-5f);
lolunit_assert_doubles_equal(screen_ratio, tc->GetScreenRatio(), 1.e-5f);
lolunit_assert_doubles_equal(near, tc->GetNear(), 1.e-5f);
lolunit_assert_doubles_equal(far, tc->GetFar(), 1.e-5f);
lolunit_assert(is_shifted == tc->IsShifted());
}
};



+ 41
- 2
src/t/math/real.cpp 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -316,7 +316,7 @@ lolunit_declare_fixture(real_test)
lolunit_assert_lequal((double)fabs(b), 1.0);
}

lolunit_declare_test(sqrt_cbrt)
lolunit_declare_test(real_sqrt)
{
double sqrt0 = sqrt(real(0));
double sqrt1 = sqrt(real(1));
@@ -339,6 +339,45 @@ lolunit_declare_fixture(real_test)
lolunit_assert_doubles_equal(sqrt8, sqrt(8.0), 1e-8);
}

lolunit_declare_test(real_cbrt)
{
double cbrtm8 = cbrt(real(-8));
double cbrtm7 = cbrt(real(-7));
double cbrtm6 = cbrt(real(-6));
double cbrtm5 = cbrt(real(-5));
double cbrtm4 = cbrt(real(-4));
double cbrtm3 = cbrt(real(-3));
double cbrtm2 = cbrt(real(-2));
double cbrtm1 = cbrt(real(-1));
double cbrt0 = cbrt(real(0));
double cbrt1 = cbrt(real(1));
double cbrt2 = cbrt(real(2));
double cbrt3 = cbrt(real(3));
double cbrt4 = cbrt(real(4));
double cbrt5 = cbrt(real(5));
double cbrt6 = cbrt(real(6));
double cbrt7 = cbrt(real(7));
double cbrt8 = cbrt(real(8));

lolunit_assert_doubles_equal(cbrtm8, cbrt(-8.0), 1e-8);
lolunit_assert_doubles_equal(cbrtm7, cbrt(-7.0), 1e-8);
lolunit_assert_doubles_equal(cbrtm6, cbrt(-6.0), 1e-8);
lolunit_assert_doubles_equal(cbrtm5, cbrt(-5.0), 1e-8);
lolunit_assert_doubles_equal(cbrtm4, cbrt(-4.0), 1e-8);
lolunit_assert_doubles_equal(cbrtm3, cbrt(-3.0), 1e-8);
lolunit_assert_doubles_equal(cbrtm2, cbrt(-2.0), 1e-8);
lolunit_assert_doubles_equal(cbrtm1, cbrt(-1.0), 1e-8);
lolunit_assert_doubles_equal(cbrt0, cbrt(0.0), 1e-8);
lolunit_assert_doubles_equal(cbrt1, cbrt(1.0), 1e-8);
lolunit_assert_doubles_equal(cbrt2, cbrt(2.0), 1e-8);
lolunit_assert_doubles_equal(cbrt3, cbrt(3.0), 1e-8);
lolunit_assert_doubles_equal(cbrt4, cbrt(4.0), 1e-8);
lolunit_assert_doubles_equal(cbrt5, cbrt(5.0), 1e-8);
lolunit_assert_doubles_equal(cbrt6, cbrt(6.0), 1e-8);
lolunit_assert_doubles_equal(cbrt7, cbrt(7.0), 1e-8);
lolunit_assert_doubles_equal(cbrt8, cbrt(8.0), 1e-8);
}

lolunit_declare_test(real_ldexp)
{
real a1(1.5);


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