From 4d86a65233726797a45bfc8978cbf99cde49989b Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 7 Feb 2024 15:58:39 +0100 Subject: [PATCH] Added tests for FindPath function --- src/test/java/pacmanTests/MapTest.java | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/test/java/pacmanTests/MapTest.java b/src/test/java/pacmanTests/MapTest.java index 7fc442d..723fa63 100644 --- a/src/test/java/pacmanTests/MapTest.java +++ b/src/test/java/pacmanTests/MapTest.java @@ -57,4 +57,58 @@ class MapTest { assertThat(expectedMiddle).isEqualTo(middle); assertThat(expectedBottomRight).isEqualTo(bottomRight); } + + @Test + void Map_getPath_returnCorrectPathSimple() { + // arrange + String[] mapTest = { + "wwwww", + "w...w", + "w.w.w", + "w.w.w", + "wwwww" + }; + GameManager gameManager = new GameManager(); + gameManager.map = new Map(mapTest, gameManager); + + Vector2 from = new Vector2(1, 1); + Vector2 to = new Vector2(3, 1); + + String expectedPath = "uurrdd"; + + // act + + String path = gameManager.map.FindPath(from, to); + + // assert + assertThat(path).isEqualTo(expectedPath); + } + + @Test + void Map_getPath_returnCorrectPathComplex() { + // arrange + String[] mapTest = { + "wwwwwwwww", + "w.....w.w", + "w.www.w.w", + "w.w...w.w", + "w.w.www.w", + "w.w.....w", + "wwwwwwwww" + }; + GameManager gameManager = new GameManager(); + gameManager.map = new Map(mapTest, gameManager); + + Vector2 from = new Vector2(4, 3); + Vector2 to = new Vector2(1, 1); + + String expectedPath = "ruulllldddd"; + + // act + + String path = gameManager.map.FindPath(from, to); + + // assert + assertThat(path).isEqualTo(expectedPath); + } }