|
|
@@ -0,0 +1,51 @@
|
|
|
+//
|
|
|
+// common_test.cxx
|
|
|
+// math-test
|
|
|
+//
|
|
|
+// Created by Sam Jaffe on 5/5/19.
|
|
|
+// Copyright © 2019 Sam Jaffe. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#include <cmath>
|
|
|
+#include <gmock/gmock.h>
|
|
|
+
|
|
|
+#include "game/math/angle.hpp"
|
|
|
+#include "game/math/common.hpp"
|
|
|
+#include "game/math/shape.hpp"
|
|
|
+
|
|
|
+#include "test_printers.h"
|
|
|
+
|
|
|
+using namespace math::dim2;
|
|
|
+
|
|
|
+struct UnitCircleTest : testing::TestWithParam<point> {};
|
|
|
+
|
|
|
+TEST_P(UnitCircleTest, PointExistsInCircle) {
|
|
|
+ circle unit{{{0, 0}}, 1};
|
|
|
+ EXPECT_TRUE(math::contains(unit, GetParam()));
|
|
|
+}
|
|
|
+
|
|
|
+TEST_P(UnitCircleTest, PointExistsOutsideCircle) {
|
|
|
+ circle subunit{{{0, 0}}, 0.9999};
|
|
|
+ EXPECT_FALSE(math::contains(subunit, GetParam()));
|
|
|
+}
|
|
|
+
|
|
|
+struct unit_circle_angle {
|
|
|
+ using value_type = point;
|
|
|
+ unit_circle_angle(int degrees) : degs({static_cast<double>(degrees)}) {}
|
|
|
+ point operator*() const {
|
|
|
+ return point(make_vector(math::sin(degs), math::cos(degs)));
|
|
|
+ }
|
|
|
+ unit_circle_angle & operator++() { ++degs.value; return *this; }
|
|
|
+ math::degree degs;
|
|
|
+};
|
|
|
+
|
|
|
+std::vector<point> unit_circle_pts() {
|
|
|
+ std::vector<point> rval;
|
|
|
+ for (math::degree d{0.0}; d.value <= 360; d.value += 5.0) {
|
|
|
+ rval.emplace_back(point(make_vector(math::sin(d), math::cos(d))));
|
|
|
+ }
|
|
|
+ return rval;
|
|
|
+}
|
|
|
+
|
|
|
+INSTANTIATE_TEST_CASE_P(LiesOnEdge, UnitCircleTest,
|
|
|
+ testing::ValuesIn(unit_circle_pts()));
|