Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
srcimon committed Feb 21, 2024
1 parent abb0c41 commit 7d729fd
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.List;

import static io.github.srcimon.screwbox.core.Duration.ofMillis;
import static io.github.srcimon.screwbox.core.test.TestUtil.sleep;
import static org.assertj.core.api.Assertions.*;

Expand Down Expand Up @@ -158,7 +159,7 @@ void unlockFps_setsTargetFps_toIntegerMax() {
@Test
void updateDuration_oneSystemNeedsAtLeast10ms_isBetween10and100ms() {
updatables.add(stopAfterOneFrameUpdatable());
updatables.add(() -> sleep(Duration.ofMillis(10)));
updatables.add(() -> sleep(ofMillis(10)));
loop.start();

var updateDuration = loop.updateDuration();
Expand All @@ -169,14 +170,24 @@ void updateDuration_oneSystemNeedsAtLeast10ms_isBetween10and100ms() {
@Test
void updateDuration_oneSystemNeedsAtLeast100ms_isGreaterThan100ms() {
updatables.add(stopAfterOneFrameUpdatable());
updatables.add(() -> sleep(Duration.ofMillis(100)));
updatables.add(() -> sleep(ofMillis(100)));
loop.start();

var updateDuration = loop.updateDuration();

assertThat(updateDuration.milliseconds()).isGreaterThan(100);
}

@Test
void lastUpdate_onlyOneSystem_isAfterStartingLoop() {
updatables.add(stopAfterOneFrameUpdatable());

Time before = Time.now();
loop.start();

assertThat(loop.lastUpdate().isAfter(before)).isTrue();
}

private Updatable stopAfterOneFrameUpdatable() {
return () -> loop.stop();
}
Expand Down

0 comments on commit 7d729fd

Please sign in to comment.