From ace11d18d64a3beb2b5b1eb25dd064a8b192728d Mon Sep 17 00:00:00 2001 From: Almas Baim Date: Sun, 24 Mar 2024 08:35:35 +0000 Subject: [PATCH] test: added WaypointComponentTest --- .../components/WaypointMoveComponentTest.kt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 fxgl/src/test/kotlin/com/almasb/fxgl/dsl/components/WaypointMoveComponentTest.kt diff --git a/fxgl/src/test/kotlin/com/almasb/fxgl/dsl/components/WaypointMoveComponentTest.kt b/fxgl/src/test/kotlin/com/almasb/fxgl/dsl/components/WaypointMoveComponentTest.kt new file mode 100644 index 000000000..d10054285 --- /dev/null +++ b/fxgl/src/test/kotlin/com/almasb/fxgl/dsl/components/WaypointMoveComponentTest.kt @@ -0,0 +1,43 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.dsl.components + +import com.almasb.fxgl.entity.Entity +import javafx.geometry.Point2D +import org.hamcrest.CoreMatchers.`is` +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test + +/** + * + * + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class WaypointMoveComponentTest { + + @Test + fun `Moving via WaypointComponent`() { + val comp = WaypointMoveComponent(100.0, listOf(Point2D(20.0, 50.0), Point2D(40.0, 50.0))) + + val e = Entity() + e.addComponent(comp) + + assertFalse(comp.atDestinationProperty().value) + + comp.onUpdate(5.0) + assertThat(e.position, `is`(Point2D(20.0, 50.0))) + + assertFalse(comp.atDestinationProperty().value) + + comp.onUpdate(5.0) + assertThat(e.position, `is`(Point2D(40.0, 50.0))) + + assertTrue(comp.atDestinationProperty().value) + } +} \ No newline at end of file