Browse Source

fix: update test cases in math/graphics to use vector/matrix updates

Sam Jaffe 1 year ago
parent
commit
d36725c9c9

+ 16 - 16
graphics/test/manager_test.cxx

@@ -5,12 +5,12 @@
 //  Created by Sam Jaffe on 6/6/19.
 //  Copyright © 2019 Sam Jaffe. All rights reserved.
 //
+#include "game/graphics/manager.hpp"
 
-#include <gmock/gmock.h>
+#include <testing/xcode_gtest_helper.h>
 
 #include "../src/helper.hpp"
 #include "game/graphics/exception.h"
-#include "game/graphics/manager.hpp"
 #include "game/graphics/material.hpp"
 #include "game/graphics/shader.hpp"
 #include "game/graphics/shader_program.hpp"
@@ -112,39 +112,39 @@ TEST_F(TextureTest, ThrowsOnNonExistantFile) {
 }
 
 TEST_F(TextureTest, NoExceptIfFileExists) {
-  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(1);
+  EXPECT_CALL(mock, compile(_, math::vec2i(1, 1), _)).Times(1);
   EXPECT_NO_THROW(mock.get("resources/black.bmp"));
 }
 
 TEST_F(TextureTest, CreatedTextureCanBeRefetched) {
-  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(1);
+  EXPECT_CALL(mock, compile(_, math::vec2i(1, 1), _)).Times(1);
   auto id_1 = mock.get("resources/black.bmp");
   auto id_2 = mock.get("resources/black.bmp");
   EXPECT_THAT(id_1, Eq(id_2));
 }
 
 TEST_F(TextureTest, CanGetTextureFromId) {
-  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(1);
+  EXPECT_CALL(mock, compile(_, math::vec2i(1, 1), _)).Times(1);
   auto texture_id = mock.get("resources/black.bmp");
   auto texture = mock.get(texture_id);
   EXPECT_THAT(texture, Eq(texture_id));
 }
 
 TEST_F(TextureTest, SizeOfTexturePassedIntoCompile) {
-  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(0);
-  EXPECT_CALL(mock, compile(_, make_vector(2, 2), _)).Times(1);
+  EXPECT_CALL(mock, compile(_, math::vec2i(1, 1), _)).Times(0);
+  EXPECT_CALL(mock, compile(_, math::vec2i(2, 2), _)).Times(1);
   mock.get("resources/black2.bmp");
 }
 
 TEST_F(TextureTest, CanReadRGBFormat) {
   using graphics::textures::format;
-  EXPECT_CALL(mock, compile(format::RGB, make_vector(1, 1), _)).Times(1);
+  EXPECT_CALL(mock, compile(format::RGB, math::vec2i(1, 1), _)).Times(1);
   mock.get("resources/black_rgb.png");
 }
 
 TEST_F(TextureTest, CanReadRGBAFormat) {
   using graphics::textures::format;
-  EXPECT_CALL(mock, compile(format::RGBA, make_vector(1, 1), _)).Times(1);
+  EXPECT_CALL(mock, compile(format::RGBA, math::vec2i(1, 1), _)).Times(1);
   mock.get("resources/black_rgba.png");
 }
 
@@ -158,13 +158,13 @@ TEST_F(MaterialTest, ThrowsExceptionIfNoTexOrUniform) {
 
 TEST_F(MaterialTest, GeneratesUniformTexturesIfNoTexFile) {
   using graphics::materials::uniform;
-  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
+  EXPECT_CALL(mock, compile(_, math::vec2i(1, 1), _)).Times(3);
   EXPECT_NO_THROW(mock.get(cast_p(1), "", "u_normalMap"));
 }
 
 TEST_F(MaterialTest, CreatedMaterialCanBeRefetched) {
   // Three times and no more
-  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
+  EXPECT_CALL(mock, compile(_, math::vec2i(1, 1), _)).Times(3);
   auto id_1 = mock.get(cast_p(1), "", "u_normalMap");
   auto id_2 = mock.get(cast_p(1), "", "u_normalMap");
   EXPECT_THAT(id_1, Eq(id_2));
@@ -181,13 +181,13 @@ TEST_F(MaterialTest, CanGetMaterialFromId) {
 TEST_F(MaterialTest, UniformMaterialIsOneByOne) {
   auto material = mock.get(mock.get(cast_p(1), "", "u_normalMap"));
   // Uniforms are always sized 1x1
-  EXPECT_THAT(material.size, Eq(make_vector(1, 1)));
+  EXPECT_THAT(material.size, Eq(math::vec2i(1, 1)));
 }
 
 TEST_F(MaterialTest, SizeCapturesTextureSize) {
   auto material =
       mock.get(mock.get(cast_p(1), "resources/black2.bmp", "u_normalMap"));
-  EXPECT_THAT(material.size, Eq(make_vector(2, 2)));
+  EXPECT_THAT(material.size, Eq(math::vec2i(2, 2)));
 }
 
 TEST_F(MaterialTest, UniformMaterialHasDataBindingToNormalTex) {
@@ -202,14 +202,14 @@ TEST_F(MaterialTest, UniformMaterialHasDataBindingToNormalTex) {
 }
 
 TEST_F(MaterialTest, DifferentProgramMakesDifferentMaterial) {
-  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
+  EXPECT_CALL(mock, compile(_, math::vec2i(1, 1), _)).Times(3);
   auto id_1 = mock.get(cast_p(1), "", "u_normalMap");
   auto id_2 = mock.get(cast_p(2), "", "u_normalMap");
   EXPECT_THAT(id_1, Ne(id_2));
 }
 
 TEST_F(MaterialTest, DifferentProgramDoesntChangeUniformId) {
-  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
+  EXPECT_CALL(mock, compile(_, math::vec2i(1, 1), _)).Times(3);
   auto mat_1 = mock.get(mock.get(cast_p(1), "", "u_normalMap"));
   auto mat_2 = mock.get(mock.get(cast_p(2), "", "u_normalMap"));
   EXPECT_THAT(mat_1.uniforms[0].texture, Eq(mat_2.uniforms[0].texture));
@@ -217,7 +217,7 @@ TEST_F(MaterialTest, DifferentProgramDoesntChangeUniformId) {
 
 TEST_F(MaterialTest, TexFileSkipsUniformLoad) {
   using graphics::materials::uniform;
-  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(1);
+  EXPECT_CALL(mock, compile(_, math::vec2i(1, 1), _)).Times(1);
   auto material =
       mock.get(mock.get(cast_p(1), "resources/black.bmp", "u_normalMap"));
   EXPECT_THAT(material.uniforms, SizeIs(1));

+ 1 - 1
graphics/test/renderer_test.cxx

@@ -8,7 +8,7 @@
 
 #include "game/graphics/renderer.hpp"
 
-#include <gmock/gmock.h>
+#include <testing/xcode_gtest_helper.h>
 
 #include <game/math/shape.hpp>
 #include <math/matrix/matrix.hpp>

+ 5 - 4
math/test/angle_test.cxx

@@ -7,7 +7,8 @@
 //
 
 #include "game/math/angle.hpp"
-#include <gmock/gmock.h>
+
+#include <testing/xcode_gtest_helper.h>
 
 using testing::DoubleNear;
 using testing::Eq;
@@ -89,6 +90,6 @@ TEST_P(TrigonometryTest, TanRadianIsTanDouble) {
 }
 
 using testing::Values;
-INSTANTIATE_TEST_CASE_P(MapsToRawValue, TrigonometryTest,
-                        Values(0.0, M_PI_4, M_PI_2, 3 * M_PI_4, M_PI,
-                               5 * M_PI_4, 3 * M_PI_2, 7 * M_PI_4, 2 * M_PI));
+INSTANTIATE_TEST_SUITE_P(MapsToRawValue, TrigonometryTest,
+                         Values(0.0, M_PI_4, M_PI_2, 3 * M_PI_4, M_PI,
+                                5 * M_PI_4, 3 * M_PI_2, 7 * M_PI_4, 2 * M_PI));

+ 23 - 21
math/test/common_test.cxx

@@ -7,7 +7,8 @@
 //
 
 #include <cmath>
-#include <gmock/gmock.h>
+
+#include <testing/xcode_gtest_helper.h>
 
 #include "game/math/angle.hpp"
 #include "game/math/common.hpp"
@@ -55,9 +56,9 @@ TEST_P(LineTest, ColinearOutsideDoesNotContain) {
 std::vector<point> const line_ends{{{1, 1}},   {{0, 1}},  {{1, 0}},
                                    {{-1, -1}}, {{0, -1}}, {{-1, 0}}};
 
-INSTANTIATE_TEST_CASE_P(Contains, LineTest,
-                        Combine(ValuesIn(line_ends),
-                                ValuesIn(generate(0, 100, 10))));
+INSTANTIATE_TEST_SUITE_P(Contains, LineTest,
+                         Combine(ValuesIn(line_ends),
+                                 ValuesIn(generate(0, 100, 10))));
 
 struct UnitCircleTest : TestWithParam<point> {};
 
@@ -72,11 +73,12 @@ TEST_P(UnitCircleTest, OutsideSmallerCircle) {
 }
 
 point unit_circle_angle(math::degree degs) {
-  return point(make_vector(math::sin(degs), math::cos(degs)));
+  return point(math::sin(degs), math::cos(degs));
 }
 
-INSTANTIATE_TEST_CASE_P(Contains, UnitCircleTest,
-                        ValuesIn(generate(0.0, 360.0, 5.0, unit_circle_angle)));
+INSTANTIATE_TEST_SUITE_P(Contains, UnitCircleTest,
+                         ValuesIn(generate(0.0, 360.0, 5.0,
+                                           unit_circle_angle)));
 
 struct UnitSquareTest : TestWithParam<std::tuple<float, float>> {};
 
@@ -94,9 +96,9 @@ TEST_F(UnitSquareTest, PointOutsideSquare) {
   EXPECT_FALSE(math::contains(unit, {{1.1f, 0.0f}}));
 }
 
-INSTANTIATE_TEST_CASE_P(Contains, UnitSquareTest,
-                        Combine(ValuesIn(generate(0.f, 1.f, 0.25f)),
-                                ValuesIn(generate(0.f, 1.f, 0.25f))));
+INSTANTIATE_TEST_SUITE_P(Contains, UnitSquareTest,
+                         Combine(ValuesIn(generate(0.f, 1.f, 0.25f)),
+                                 ValuesIn(generate(0.f, 1.f, 0.25f))));
 
 struct LineQuadTest : TestWithParam<point> {};
 
@@ -143,7 +145,7 @@ TEST_F(LineQuadTest, OutsideByAnInch) {
   EXPECT_FALSE(math::intersects(unit, ln));
 }
 
-INSTANTIATE_TEST_CASE_P(Intersects, LineQuadTest, ValuesIn(line_ends));
+INSTANTIATE_TEST_SUITE_P(Intersects, LineQuadTest, ValuesIn(line_ends));
 
 TEST(CircleTest, CircleIntersectsSelf) {
   circle const c1{{{0, 0}}, 1};
@@ -302,25 +304,25 @@ TEST(QuadTest, NoIntersection) {
 TEST(RotateTest, RotatingSquareAroundOrigin) {
   math::degree degrees{90.0};
   // A square with a side-length of 2 and a center at the origin
-  math::vec2 const origin = make_vector(0.f, 0.f);
+  math::vec2 const origin{0.f, 0.f};
   quad const object = square{{{-1, -1}}, 2};
   quad const rotated = math::rotate(origin, object, degrees);
-  EXPECT_THAT(rotated.ll, Eq(make_vector(1.f, -1.f)));
-  EXPECT_THAT(rotated.lr, Eq(make_vector(1.f, 1.f)));
-  EXPECT_THAT(rotated.ur, Eq(make_vector(-1.f, 1.f)));
-  EXPECT_THAT(rotated.ul, Eq(make_vector(-1.f, -1.f)));
+  EXPECT_THAT(rotated.ll, Eq(math::vec2(1.f, -1.f)));
+  EXPECT_THAT(rotated.lr, Eq(math::vec2(1.f, 1.f)));
+  EXPECT_THAT(rotated.ur, Eq(math::vec2(-1.f, 1.f)));
+  EXPECT_THAT(rotated.ul, Eq(math::vec2(-1.f, -1.f)));
   EXPECT_THAT(math::rotate(origin, rotated, -degrees), Eq(object));
 }
 
 TEST(RotateTest, RotatingSquareAroundOwnPoint) {
   math::degree degrees{90.0};
   // A square with a side-length of 2 and a center at the origin
-  math::vec2 const axis = make_vector(-1.f, -1.f);
+  math::vec2 const axis{-1.f, -1.f};
   quad const object = square{{{-1, -1}}, 2};
   quad const rotated = math::rotate(axis, object, degrees);
-  EXPECT_THAT(rotated.ll, Eq(make_vector(-1.f, -1.f)));
-  EXPECT_THAT(rotated.lr, Eq(make_vector(-1.f, 1.f)));
-  EXPECT_THAT(rotated.ur, Eq(make_vector(-3.f, 1.f)));
-  EXPECT_THAT(rotated.ul, Eq(make_vector(-3.f, -1.f)));
+  EXPECT_THAT(rotated.ll, Eq(math::vec2(-1.f, -1.f)));
+  EXPECT_THAT(rotated.lr, Eq(math::vec2(-1.f, 1.f)));
+  EXPECT_THAT(rotated.ur, Eq(math::vec2(-3.f, 1.f)));
+  EXPECT_THAT(rotated.ul, Eq(math::vec2(-3.f, -1.f)));
   EXPECT_THAT(math::rotate(axis, rotated, -degrees), Eq(object));
 }

+ 9 - 10
math/test/shape_test.cxx

@@ -5,11 +5,10 @@
 //  Created by Sam Jaffe on 5/4/19.
 //  Copyright © 2019 Sam Jaffe. All rights reserved.
 //
-
-#include <gmock/gmock.h>
-
 #include "game/math/shape.hpp"
 
+#include <testing/xcode_gtest_helper.h>
+
 #include "test_printers.h"
 
 using namespace math::dim2;
@@ -39,8 +38,8 @@ std::vector<line> const point_pairs{
     {{{1, 1}}, {{-1, 1}}},  // -90deg
 };
 
-INSTANTIATE_TEST_CASE_P(LineIntersection, FromOriginTest,
-                        ValuesIn(point_pairs));
+INSTANTIATE_TEST_SUITE_P(LineIntersection, FromOriginTest,
+                         ValuesIn(point_pairs));
 
 struct UnitLineTest : TestWithParam<point> {};
 
@@ -74,7 +73,7 @@ std::vector<point> x_orthos{
     {{0, 2}}, {{2, 2}}, {{2, 0}},  {{-2, 0}}, {{0, -2}}, {{-2, -2}},
     {{2, 1}}, {{1, 2}}, {{-2, 1}}, {{-1, 2}}, {{1, -2}}, {{2, -1}}};
 
-INSTANTIATE_TEST_CASE_P(LineOrthogonal, UnitLineTest, ValuesIn(x_orthos));
+INSTANTIATE_TEST_SUITE_P(LineOrthogonal, UnitLineTest, ValuesIn(x_orthos));
 
 struct DiagonalTest : TestWithParam<std::pair<point, float>> {};
 
@@ -93,7 +92,7 @@ std::vector<std::pair<point, float>> diag_orthos{
     {{{2, 1}}, 1.5f},   {{{1, 2}}, 1.5f},   {{{-2, 1}}, -0.5f},
     {{{-1, 2}}, 0.5f},  {{{1, -2}}, -0.5f}, {{{2, -1}}, 0.5f}};
 
-INSTANTIATE_TEST_CASE_P(LineOrthogonal, DiagonalTest, ValuesIn(diag_orthos));
+INSTANTIATE_TEST_SUITE_P(LineOrthogonal, DiagonalTest, ValuesIn(diag_orthos));
 
 struct QuadTest : TestWithParam<std::tuple<float, float>> {};
 
@@ -128,6 +127,6 @@ TEST_P(QuadTest, RectProducesQuadWithCornersAtXY) {
   EXPECT_THAT(quad(square), Eq(expected));
 }
 
-INSTANTIATE_TEST_CASE_P(Upcast, QuadTest,
-                        Combine(Values(0.5, 1.0, 1.5, 2.0),
-                                Values(0.5, 1.0, 1.5, 2.0)));
+INSTANTIATE_TEST_SUITE_P(Upcast, QuadTest,
+                         Combine(Values(0.5, 1.0, 1.5, 2.0),
+                                 Values(0.5, 1.0, 1.5, 2.0)));