Skip to content

Commit

Permalink
Add runner test.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregersn committed Nov 19, 2024
1 parent d0e7c27 commit 11e8d96
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 43 deletions.
88 changes: 45 additions & 43 deletions screenshot-tests/test-curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,51 @@ using namespace Pyro;

TEST_CASE("Test curvepoint", "[shapes]")
{
std::filesystem::path filename = "curve_curvepoints.png";

size(400,400);

nofill();
curve(20, 104, 20, 104, 292, 96, 292, 244);
curve(20, 104, 292, 96, 292, 244, 60, 260);

fill(255);
ellipsemode(CENTER);
int steps = 6;
for (int i = 0; i <= steps; i++) {
float t = i / float(steps);
float x = curvepoint(20.f, 20.f, 292.f, 292.f, t);
float y = curvepoint(104.f, 104.f, 96.f, 244.f, t);
ellipse(x, y, 10, 10);
x = curvepoint(20, 292, 292, 60, t);
y = curvepoint(104, 96, 244, 260, t);
ellipse(x, y, 10, 10);
std::filesystem::path filename = "curve_curvepoints.png";

size(400, 400);

nofill();
curve(20, 104, 20, 104, 292, 96, 292, 244);
curve(20, 104, 292, 96, 292, 244, 60, 260);

fill(255);
ellipsemode(CENTER);
int steps = 6;
for (int i = 0; i <= steps; i++)
{
float t = i / float(steps);
float x = curvepoint(20.f, 20.f, 292.f, 292.f, t);
float y = curvepoint(104.f, 104.f, 96.f, 244.f, t);
ellipse(x, y, 10, 10);
x = curvepoint(20, 292, 292, 60, t);
y = curvepoint(104, 96, 244, 260, t);
ellipse(x, y, 10, 10);
}

save(current_folder / filename);

CHECK_THAT(current_folder / filename, LooksLike(actual_folder / filename));
}

save(current_folder / filename);

CHECK_THAT(current_folder / filename, LooksLike(actual_folder / filename));

}

TEST_CASE("Test beierpoint", "[sahpes]") {
std::filesystem::path filename = "curve_bezierpoint.png";

size(400,400);
nofill();
bezier(340, 80, 40, 40, 360, 360, 60, 320);
fill(255);
ellipsemode(CENTER);
int steps = 10;
for (int i = 0; i <= steps; i++) {
float t = i / float(steps);
float x = bezierpoint(340, 40, 360, 60, t);
float y = bezierpoint(80, 40, 360, 320, t);
ellipse(x, y, 10, 10);
TEST_CASE("Test beierpoint", "[shapes]")
{
std::filesystem::path filename = "curve_bezierpoint.png";

size(400, 400);
nofill();
bezier(340, 80, 40, 40, 360, 360, 60, 320);
fill(255);
ellipsemode(CENTER);
int steps = 10;
for (int i = 0; i <= steps; i++)
{
float t = i / float(steps);
float x = bezierpoint(340, 40, 360, 60, t);
float y = bezierpoint(80, 40, 360, 320, t);
ellipse(x, y, 10, 10);
}
save(current_folder / filename);

CHECK_THAT(current_folder / filename, LooksLike(actual_folder / filename));
}
save(current_folder / filename);

CHECK_THAT(current_folder / filename, LooksLike(actual_folder / filename));
}
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test_sources = [
'test-noise.cpp',
'test-pyro.cpp',
'test-vector.cpp',
'test-runner.cpp',
'test-string.cpp',
'test-transformer2d.cpp',
'test-shape.cpp']
Expand Down
26 changes: 26 additions & 0 deletions tests/test-runner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#include <catch2/catch_all.hpp>

#include "pyro/pyro.h"
#include "pyro/runner.h"
#include <SDL2/SDL_events.h>

using namespace Pyro;

int test_setup_result{0};

void test_setup_setup()
{
test_setup_result = 1;
}

void test_setup_draw()
{
quit();
}

TEST_CASE("Test the realtime runner", "[runner]")
{
run(test_setup_setup, test_setup_draw, true);
REQUIRE(test_setup_result == 1);
}

0 comments on commit 11e8d96

Please sign in to comment.