shape_test.cxx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // shape_test.cxx
  3. // math
  4. //
  5. // Created by Sam Jaffe on 5/4/19.
  6. // Copyright © 2019 Sam Jaffe. All rights reserved.
  7. //
  8. #include <gmock/gmock.h>
  9. #include "game/math/shape.hpp"
  10. namespace math { namespace vector {
  11. std::ostream & operator<<(std::ostream & os, math::vec2 const & p) {
  12. return os << '[' << p[0] << ',' << p[1] << ']';
  13. }
  14. } }
  15. namespace math { namespace dim2 {
  16. std::ostream & operator<<(std::ostream & os, line const & l) {
  17. return os << '[' << l.first << ',' << l.second << ']';
  18. }
  19. } }
  20. struct FromOriginTest : testing::TestWithParam<math::dim2::line> {};
  21. TEST_P(FromOriginTest, IntersectsAtOrigin) {
  22. math::dim2::line l1 = { GetParam().first, {{0, 0}} };
  23. math::dim2::line l2 = { {{0, 0}}, GetParam().second };
  24. EXPECT_THAT(math::lines::intersection(l1, l2),
  25. testing::Eq(math::dim2::point{{0, 0}}));
  26. }
  27. std::vector<math::dim2::line> const point_pairs{
  28. {{{1, 1}}, {{0, 0}}},
  29. {{{1, 1}}, {{1, 0}}},
  30. {{{1, 1}}, {{0, 1}}},
  31. {{{1, 1}}, {{1, 1}}},
  32. {{{1, 1}}, {{2, 1}}},
  33. {{{2, 3}}, {{1, 2}}},
  34. {{{1, 1}}, {{-1, 0}}},
  35. {{{1, 1}}, {{ 0, -1}}},
  36. {{{1, 1}}, {{-1, -1}}},
  37. };
  38. INSTANTIATE_TEST_CASE_P(LineIntersection, FromOriginTest,
  39. testing::ValuesIn(point_pairs));