Skip to content

Commit

Permalink
Add unittest for std::format with jngl::Vec2
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Oct 3, 2024
1 parent 97cfe39 commit c51cea1
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/unittest/Vec2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,36 @@ boost::ut::suite _ = [] {
using namespace boost::ut; // NOLINT

"Vec2"_test = [] {
//
// o-->
//
jngl::Vec2 a{ 1., 0. };
//
// o-->
//
jngl::Vec2 a{ 1., 0. };

a.rotate(M_PI / 2);
//
// o
// |
// v
//
expect(approx(a.x, 0., 1e-6));
expect(approx(a.y, 1., 1e-6)); // JNGL uses negative y for up and positive for down.
expect(eq(std::format("{}", a), std::string("[x=1, y=0]")));

a.rotate(-M_PI / 4);
//
// o
//
//
//
expect(approx(a.x, sqrt(2) / 2., 1e-6));
expect(approx(a.y, sqrt(2) / 2., 1e-6));
a.rotate(0);
expect(approx(a.x, sqrt(2) / 2., 1e-6));
expect(approx(a.y, sqrt(2) / 2., 1e-6));
a.rotate(M_PI * 8);
expect(approx(a.x, sqrt(2) / 2., 1e-6));
expect(approx(a.y, sqrt(2) / 2., 1e-6));
a.rotate(M_PI / 2);
//
// o
// |
// v
//
expect(approx(a.x, 0., 1e-6));
expect(approx(a.y, 1., 1e-6)); // JNGL uses negative y for up and positive for down.

a.rotate(-M_PI / 4);
//
// o
//
//
//
expect(approx(a.x, sqrt(2) / 2., 1e-6));
expect(approx(a.y, sqrt(2) / 2., 1e-6));
a.rotate(0);
expect(approx(a.x, sqrt(2) / 2., 1e-6));
expect(approx(a.y, sqrt(2) / 2., 1e-6));
a.rotate(M_PI * 8);
expect(approx(a.x, sqrt(2) / 2., 1e-6));
expect(approx(a.y, sqrt(2) / 2., 1e-6));
};
};
} // namespace

0 comments on commit c51cea1

Please sign in to comment.