| 6 | #include "test.h" |
| 7 | |
| 8 | FL_TEST_FILE(FL_FILEPATH) { |
| 9 | using namespace fl; |
| 10 | FL_TEST_CASE("TimeWarp basic functionality") { |
| 11 | |
| 12 | FL_SUBCASE("Initialization and normal time progression") { |
| 13 | TimeWarp tw(1000, 1.0f); // 1000 ms is the start time, speed is set at 1x |
| 14 | FL_CHECK(tw.time() == 0); |
| 15 | FL_CHECK(tw.scale() == 1.0f); |
| 16 | |
| 17 | tw.update(2000); |
| 18 | FL_CHECK(tw.time() == 1000); |
| 19 | } |
| 20 | |
| 21 | FL_SUBCASE("Time scaling") { |
| 22 | TimeWarp tw(1000); |
| 23 | tw.setSpeed(2.0f); // now we are at 2x speed. |
| 24 | FL_CHECK(tw.time() == 0); // at t0 = 1000ms |
| 25 | |
| 26 | tw.update(1500); // we give 500 at 2x => add 1000 to time counter. |
| 27 | FL_CHECK(tw.time() == 1000); |
| 28 | |
| 29 | tw.setSpeed(0.5f); // Set half speed: 500ms. |
| 30 | FL_CHECK(tw.scale() == 0.5f); |
| 31 | |
| 32 | tw.update(2500); |
| 33 | FL_CHECK(tw.time() == 1500); |
| 34 | } |
| 35 | |
| 36 | FL_SUBCASE("Reset functionality") { |
| 37 | TimeWarp tw(1000, 1.0f); |
| 38 | tw.update(2000); |
| 39 | FL_CHECK(tw.time() == 1000); |
| 40 | |
| 41 | tw.reset(3000); |
| 42 | FL_CHECK(tw.time() == 0); |
| 43 | |
| 44 | tw.update(4000); |
| 45 | FL_CHECK(tw.time() == 1000); |
| 46 | } |
| 47 | |
| 48 | FL_SUBCASE("Wrap-around protection - prevent from going below start time") { |
| 49 | TimeWarp tw(1000, 1.0f); |
| 50 | tw.update(1001); |
| 51 | FL_CHECK(tw.time() == 1); |
| 52 | tw.setSpeed(-1.0f); |
| 53 | tw.update(2000); |
| 54 | FL_CHECK_EQ(tw.time(), 0); |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | |
| 59 | } // FL_TEST_FILE |