From 497996c047abc05ee31ce0114e648970f6289576 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Thu, 17 Apr 2025 14:01:39 +0200 Subject: [PATCH 01/21] build: update gradle config to support testing with JUnit --- chessevolved_model/build.gradle | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/chessevolved_model/build.gradle b/chessevolved_model/build.gradle index 4c1eac9d..e4a137a2 100644 --- a/chessevolved_model/build.gradle +++ b/chessevolved_model/build.gradle @@ -60,4 +60,11 @@ dependencies { // Needed to access shared classes like DTO implementation project(":chessevolved_shared") + + // Testing with kotlin.test and JUnit + testImplementation 'org.jetbrains.kotlin:kotlin-test' +} + +test { + useJUnitPlatform() } From 9f8ae07b51f1ddf64fce8f497dc64e8f0bed6560 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Thu, 17 Apr 2025 14:02:03 +0200 Subject: [PATCH 02/21] build: update gradle config to support testing with JUnit --- chessevolved_presenter/build.gradle | 7 +++++++ chessevolved_view/build.gradle | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/chessevolved_presenter/build.gradle b/chessevolved_presenter/build.gradle index a578f450..c01295d4 100644 --- a/chessevolved_presenter/build.gradle +++ b/chessevolved_presenter/build.gradle @@ -42,4 +42,11 @@ dependencies { // Needed to access shared classes like DTO implementation project(":chessevolved_shared") + + // Testing with kotlin.test and JUnit + testImplementation 'org.jetbrains.kotlin:kotlin-test' +} + +test { + useJUnitPlatform() } diff --git a/chessevolved_view/build.gradle b/chessevolved_view/build.gradle index a2100032..22368dea 100644 --- a/chessevolved_view/build.gradle +++ b/chessevolved_view/build.gradle @@ -40,4 +40,11 @@ dependencies { // Needed to access shared classes like DTO implementation project(":chessevolved_shared") + + // Testing with kotlin.test and JUnit + testImplementation 'org.jetbrains.kotlin:kotlin-test' +} + +test { + useJUnitPlatform() } From 415f8546401d2e15731b5d12fdeef67bad299329 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Thu, 17 Apr 2025 14:43:43 +0200 Subject: [PATCH 03/21] build: update gradle config to support testing with JUnit, create LobbyTest.kt --- chessevolved_model/build.gradle | 1 + .../chessevolved/singletons/LobbyTest.kt | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt diff --git a/chessevolved_model/build.gradle b/chessevolved_model/build.gradle index e4a137a2..aeb59506 100644 --- a/chessevolved_model/build.gradle +++ b/chessevolved_model/build.gradle @@ -63,6 +63,7 @@ dependencies { // Testing with kotlin.test and JUnit testImplementation 'org.jetbrains.kotlin:kotlin-test' + testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.1" } test { diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt new file mode 100644 index 00000000..133f4136 --- /dev/null +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt @@ -0,0 +1,63 @@ +package io.github.chessevolved.singletons + +import kotlinx.coroutines.test.runTest +import org.junit.jupiter.api.Assertions.* + +import org.junit.jupiter.api.Test +import kotlin.test.assertFailsWith + +class LobbyTest { + + /** + * Attempt to join a lobby that does not exists + */ + suspend fun joinLobby() { + Lobby.joinLobby("") + } + + // Required to test suspend functions + @Test + fun testJoinLobby() = runTest { + try { + val lobbyTest = joinLobby() + } catch (e : Exception) { + println(e.message) + } + } + + @Test + fun createLobby() { + } + + @Test + fun leaveLobby() { + } + + @Test + fun setLobbySettings() { + } + + @Test + fun getLobby() { + } + + @Test + fun startGame() { + } + + @Test + fun isInLobby() { + } + + @Test + fun getLobbyId() { + } + + @Test + fun subscribeToLobbyUpdates() { + } + + @Test + fun unsubscribeFromLobbyUpdates() { + } +} From ae285ccc6927d957c300e5105fde97747c69c06d Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Thu, 17 Apr 2025 15:00:20 +0200 Subject: [PATCH 04/21] build: update LobbyTest.kt --- .../chessevolved/singletons/LobbyTest.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt index 133f4136..522bd221 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt @@ -1,32 +1,33 @@ package io.github.chessevolved.singletons import kotlinx.coroutines.test.runTest -import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test -import kotlin.test.assertFailsWith +import kotlin.test.assertFails class LobbyTest { + //TODO: update current tests, write test for the rest of the methods (Unit test) + /** * Attempt to join a lobby that does not exists */ suspend fun joinLobby() { Lobby.joinLobby("") } - // Required to test suspend functions @Test fun testJoinLobby() = runTest { - try { - val lobbyTest = joinLobby() - } catch (e : Exception) { - println(e.message) - } + assertFails({ joinLobby() }) + } + + suspend fun createLobby() { + Lobby.createLobby() } @Test - fun createLobby() { + fun testCreateLobby() = runTest { + assertFails({ createLobby() }) } @Test From b06b04bdb0d17e57d7c057e1bfcfadd4d0b3500c Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Thu, 17 Apr 2025 15:08:21 +0200 Subject: [PATCH 05/21] build: create GameSettingsTest.kt --- .../singletons/GameSettingsTest.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt new file mode 100644 index 00000000..bc86b7ae --- /dev/null +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt @@ -0,0 +1,32 @@ +package io.github.chessevolved.singletons + +import io.github.chessevolved.shared.SettingsDTO +import org.junit.jupiter.api.Assertions.* + +import org.junit.jupiter.api.Test + +class GameSettingsTest { + + @Test + fun isFOWEnabled() { + assertEquals(false, GameSettings.isFOWEnabled()) + } + + @Test + fun getBoardSize() { + assertEquals(8, GameSettings.getBoardSize()) + } + + @Test + fun getGameSettings() { + val settingsDTO: SettingsDTO = SettingsDTO(false, 8) + assertEquals(settingsDTO, GameSettings.getGameSettings()) + } + + @Test + fun setGameSettings() { + val settingsDTO: SettingsDTO = SettingsDTO(true, 16) + GameSettings.setGameSettings(settingsDTO) + assertEquals(settingsDTO, GameSettings.getGameSettings()) + } +} From ba76adab536280c165bb468919316ed79a705dc5 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Thu, 17 Apr 2025 15:11:07 +0200 Subject: [PATCH 06/21] build: create GameSettingsTest.kt --- .../io/github/chessevolved/singletons/GameSettingsTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt index bc86b7ae..c20a45a6 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt @@ -28,5 +28,7 @@ class GameSettingsTest { val settingsDTO: SettingsDTO = SettingsDTO(true, 16) GameSettings.setGameSettings(settingsDTO) assertEquals(settingsDTO, GameSettings.getGameSettings()) + assertEquals(true, GameSettings.isFOWEnabled()) + assertEquals(16, GameSettings.getBoardSize()) } } From 0c4a512288b8175ea0da01c8bc536f96da4416f4 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Thu, 17 Apr 2025 15:53:57 +0200 Subject: [PATCH 07/21] build: create BoardSquareFactoryTest.kt --- chessevolved_model/build.gradle | 1 + .../entities/BoardSquareFactory.kt | 2 +- .../entities/BoardSquareFactoryTest.kt | 34 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt diff --git a/chessevolved_model/build.gradle b/chessevolved_model/build.gradle index aeb59506..08b3cfb4 100644 --- a/chessevolved_model/build.gradle +++ b/chessevolved_model/build.gradle @@ -68,4 +68,5 @@ dependencies { test { useJUnitPlatform() + workingDir = rootProject.file('assets').path } diff --git a/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/BoardSquareFactory.kt b/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/BoardSquareFactory.kt index ba8ff1f4..3feb43cf 100644 --- a/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/BoardSquareFactory.kt +++ b/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/BoardSquareFactory.kt @@ -17,7 +17,7 @@ class BoardSquareFactory( private val engine: Engine, private val assetManager: AssetManager, ) { - private fun getBoardSquareTextureRegion(playerColor: PlayerColor): TextureRegion { + fun getBoardSquareTextureRegion(playerColor: PlayerColor): TextureRegion { val colorStr = playerColor.name.lowercase() val filename = "board/$colorStr-tile.png" diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt new file mode 100644 index 00000000..954bf475 --- /dev/null +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt @@ -0,0 +1,34 @@ +package io.github.chessevolved.entities + +import com.badlogic.ashley.core.Engine +import com.badlogic.gdx.assets.AssetManager +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.TextureRegion +import io.github.chessevolved.components.PlayerColor +import io.github.chessevolved.components.Position +import io.github.chessevolved.components.WeatherEvent +import io.github.chessevolved.singletons.ECSEngine +import org.junit.jupiter.api.Assertions.* + +import org.junit.jupiter.api.Test + +class BoardSquareFactoryTest { + private val engine: Engine = ECSEngine + private val assetManager: AssetManager = AssetManager() + private val boardSquareFactory: BoardSquareFactory = BoardSquareFactory(engine, assetManager) + + @Test + fun createBoardSquare() { + assetManager.load("board/black-tile.png", Texture::class.java) + assetManager.finishLoading() + + boardSquareFactory.createBoardSquare( + Position(1,1), + WeatherEvent.NONE, + PlayerColor.BLACK + ) + val texture: TextureRegion = TextureRegion(Texture("board/black-tile.png")) + assertEquals(texture, boardSquareFactory.getBoardSquareTextureRegion(PlayerColor.BLACK)) + } + +} From 56cedfe979df381cf6ef04c9e7109b3ee308d013 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Thu, 17 Apr 2025 16:00:09 +0200 Subject: [PATCH 08/21] build: create PieceFactoryTest.kt --- .../chessevolved/entities/PieceFactory.kt | 2 +- .../chessevolved/entities/PieceFactoryTest.kt | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt diff --git a/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/PieceFactory.kt b/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/PieceFactory.kt index a27eb40b..269330cd 100644 --- a/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/PieceFactory.kt +++ b/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/PieceFactory.kt @@ -18,7 +18,7 @@ class PieceFactory( private val engine: Engine, private val assetManager: AssetManager, ) { - private fun getPieceTextureRegion( + fun getPieceTextureRegion( pieceType: PieceType, playerColor: PlayerColor, ): TextureRegion { diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt new file mode 100644 index 00000000..712f8a28 --- /dev/null +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt @@ -0,0 +1,53 @@ +package io.github.chessevolved.entities + +import com.badlogic.ashley.core.Engine +import com.badlogic.gdx.assets.AssetManager +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.TextureRegion +import io.github.chessevolved.components.PieceType +import io.github.chessevolved.components.PlayerColor +import io.github.chessevolved.components.Position +import io.github.chessevolved.components.WeatherEvent +import io.github.chessevolved.singletons.ECSEngine +import org.junit.jupiter.api.Assertions.* + +import org.junit.jupiter.api.Test + +class PieceFactoryTest { + private val engine: Engine = ECSEngine + private val assetManager: AssetManager = AssetManager() + private val pieceFactory: PieceFactory = PieceFactory(engine, assetManager) + + @Test + fun createPawn() { + } + + @Test + fun createKnight() { + } + + @Test + fun createBishop() { + } + + @Test + fun createRook() { + assetManager.load("pieces/black-rook.png", Texture::class.java) + assetManager.finishLoading() + + pieceFactory.createRook( + Position(1,1), + PlayerColor.BLACK + ) + val texture: TextureRegion = TextureRegion(Texture("pieces/black-rook.png")) + assertEquals(texture, pieceFactory.getPieceTextureRegion(PieceType.ROOK, PlayerColor.BLACK)) + } + + @Test + fun createQueen() { + } + + @Test + fun createKing() { + } +} From 798e64041cc288a6eb30e69a7b2ce250587bf699 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Thu, 17 Apr 2025 20:35:53 +0200 Subject: [PATCH 09/21] build: ktlint --- .../entities/BoardSquareFactoryTest.kt | 6 ++---- .../chessevolved/entities/PieceFactoryTest.kt | 6 ++---- .../singletons/GameSettingsTest.kt | 2 -- .../chessevolved/singletons/LobbyTest.kt | 19 ++++++++++--------- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt index 954bf475..5a4f7c7d 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt @@ -9,7 +9,6 @@ import io.github.chessevolved.components.Position import io.github.chessevolved.components.WeatherEvent import io.github.chessevolved.singletons.ECSEngine import org.junit.jupiter.api.Assertions.* - import org.junit.jupiter.api.Test class BoardSquareFactoryTest { @@ -23,12 +22,11 @@ class BoardSquareFactoryTest { assetManager.finishLoading() boardSquareFactory.createBoardSquare( - Position(1,1), + Position(1, 1), WeatherEvent.NONE, - PlayerColor.BLACK + PlayerColor.BLACK, ) val texture: TextureRegion = TextureRegion(Texture("board/black-tile.png")) assertEquals(texture, boardSquareFactory.getBoardSquareTextureRegion(PlayerColor.BLACK)) } - } diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt index 712f8a28..c52f6cb7 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt @@ -7,10 +7,8 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion import io.github.chessevolved.components.PieceType import io.github.chessevolved.components.PlayerColor import io.github.chessevolved.components.Position -import io.github.chessevolved.components.WeatherEvent import io.github.chessevolved.singletons.ECSEngine import org.junit.jupiter.api.Assertions.* - import org.junit.jupiter.api.Test class PieceFactoryTest { @@ -36,8 +34,8 @@ class PieceFactoryTest { assetManager.finishLoading() pieceFactory.createRook( - Position(1,1), - PlayerColor.BLACK + Position(1, 1), + PlayerColor.BLACK, ) val texture: TextureRegion = TextureRegion(Texture("pieces/black-rook.png")) assertEquals(texture, pieceFactory.getPieceTextureRegion(PieceType.ROOK, PlayerColor.BLACK)) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt index c20a45a6..f468bcbe 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt @@ -2,11 +2,9 @@ package io.github.chessevolved.singletons import io.github.chessevolved.shared.SettingsDTO import org.junit.jupiter.api.Assertions.* - import org.junit.jupiter.api.Test class GameSettingsTest { - @Test fun isFOWEnabled() { assertEquals(false, GameSettings.isFOWEnabled()) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt index 522bd221..1c0e0935 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt @@ -1,13 +1,11 @@ package io.github.chessevolved.singletons import kotlinx.coroutines.test.runTest - import org.junit.jupiter.api.Test import kotlin.test.assertFails class LobbyTest { - - //TODO: update current tests, write test for the rest of the methods (Unit test) + // TODO: update current tests, write test for the rest of the methods (Unit test) /** * Attempt to join a lobby that does not exists @@ -15,20 +13,23 @@ class LobbyTest { suspend fun joinLobby() { Lobby.joinLobby("") } + // Required to test suspend functions @Test - fun testJoinLobby() = runTest { - assertFails({ joinLobby() }) - } + fun testJoinLobby() = + runTest { + assertFails({ joinLobby() }) + } suspend fun createLobby() { Lobby.createLobby() } @Test - fun testCreateLobby() = runTest { - assertFails({ createLobby() }) - } + fun testCreateLobby() = + runTest { + assertFails({ createLobby() }) + } @Test fun leaveLobby() { From 6b317a7c946eab3a2683ea76ea05972bd280827b Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Fri, 18 Apr 2025 17:54:58 +0200 Subject: [PATCH 10/21] build: Add basic UI test --- .../singletons/GameSettingsTest.kt | 2 +- lwjgl3/build.gradle | 7 +++++ .../chessevolved/lwjgl3/Lwjgl3LauncherTest.kt | 28 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 lwjgl3/src/test/kotlin/io/github/chessevolved/lwjgl3/Lwjgl3LauncherTest.kt diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt index f468bcbe..ffd85870 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt @@ -2,7 +2,7 @@ package io.github.chessevolved.singletons import io.github.chessevolved.shared.SettingsDTO import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Test +import kotlin.test.Test class GameSettingsTest { @Test diff --git a/lwjgl3/build.gradle b/lwjgl3/build.gradle index 869d7f74..b55bbd4b 100644 --- a/lwjgl3/build.gradle +++ b/lwjgl3/build.gradle @@ -37,6 +37,9 @@ dependencies { implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" implementation project(':chessevolved_presenter') + // Testing with kotlin.test and JUnit + testImplementation 'org.jetbrains.kotlin:kotlin-test' + if(enableGraalNative == 'true') { implementation "io.github.berstanio:gdx-svmhelper-backend-lwjgl3:$graalHelperVersion" implementation "io.github.berstanio:gdx-svmhelper-extension-freetype:$graalHelperVersion" @@ -44,6 +47,10 @@ dependencies { } +test { + useJUnitPlatform() +} + def os = System.properties['os.name'].toLowerCase() run { diff --git a/lwjgl3/src/test/kotlin/io/github/chessevolved/lwjgl3/Lwjgl3LauncherTest.kt b/lwjgl3/src/test/kotlin/io/github/chessevolved/lwjgl3/Lwjgl3LauncherTest.kt new file mode 100644 index 00000000..04b43cf6 --- /dev/null +++ b/lwjgl3/src/test/kotlin/io/github/chessevolved/lwjgl3/Lwjgl3LauncherTest.kt @@ -0,0 +1,28 @@ +package io.github.chessevolved.lwjgl3 + +import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application +import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration +import io.github.chessevolved.ChessEvolvedGame +import org.junit.jupiter.api.assertDoesNotThrow +import kotlin.test.Test + +class Lwjgl3LauncherTest { + + @Test + fun testUI() { + val config: Lwjgl3ApplicationConfiguration = Lwjgl3ApplicationConfiguration().apply { + setTitle("Chess Evolved") + setWindowedMode(360, 800) + setWindowIcon( + *( + arrayOf(128, 64, 32, 16) + .map { "libgdx$it.png" } + .toTypedArray() + ), + ) + } + config.disableAudio(true) + val testApplication: Lwjgl3Application = Lwjgl3Application(ChessEvolvedGame(), config) + assertDoesNotThrow({ testApplication.exit() }) + } +} From adc374a4f7c8fac1d18e852aff2b422ea399c61b Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Fri, 18 Apr 2025 18:51:23 +0200 Subject: [PATCH 11/21] build: update tests --- .../entities/BoardSquareFactoryTest.kt | 26 +++---- .../chessevolved/entities/PieceFactoryTest.kt | 74 ++++++++++++++++--- .../chessevolved/singletons/LobbyTest.kt | 45 +---------- 3 files changed, 79 insertions(+), 66 deletions(-) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt index 5a4f7c7d..a1da4300 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt @@ -2,31 +2,31 @@ package io.github.chessevolved.entities import com.badlogic.ashley.core.Engine import com.badlogic.gdx.assets.AssetManager -import com.badlogic.gdx.graphics.Texture -import com.badlogic.gdx.graphics.g2d.TextureRegion +import com.badlogic.gdx.scenes.scene2d.Stage import io.github.chessevolved.components.PlayerColor import io.github.chessevolved.components.Position import io.github.chessevolved.components.WeatherEvent import io.github.chessevolved.singletons.ECSEngine -import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test +import kotlin.test.assertFails class BoardSquareFactoryTest { private val engine: Engine = ECSEngine private val assetManager: AssetManager = AssetManager() private val boardSquareFactory: BoardSquareFactory = BoardSquareFactory(engine, assetManager) + /** + * Attempt to create a square at an invalid location + */ @Test fun createBoardSquare() { - assetManager.load("board/black-tile.png", Texture::class.java) - assetManager.finishLoading() - - boardSquareFactory.createBoardSquare( - Position(1, 1), - WeatherEvent.NONE, - PlayerColor.BLACK, - ) - val texture: TextureRegion = TextureRegion(Texture("board/black-tile.png")) - assertEquals(texture, boardSquareFactory.getBoardSquareTextureRegion(PlayerColor.BLACK)) + assertFails({ + boardSquareFactory.createBoardSquare( + Position(1000, 1000), + WeatherEvent.NONE, + PlayerColor.BLACK, + Stage(), + ) + }) } } diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt index c52f6cb7..117850c8 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt @@ -4,48 +4,104 @@ import com.badlogic.ashley.core.Engine import com.badlogic.gdx.assets.AssetManager import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.TextureRegion +import com.badlogic.gdx.scenes.scene2d.Stage import io.github.chessevolved.components.PieceType import io.github.chessevolved.components.PlayerColor import io.github.chessevolved.components.Position +import io.github.chessevolved.components.WeatherEvent import io.github.chessevolved.singletons.ECSEngine import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test +import kotlin.test.assertFails class PieceFactoryTest { private val engine: Engine = ECSEngine private val assetManager: AssetManager = AssetManager() private val pieceFactory: PieceFactory = PieceFactory(engine, assetManager) + /** + * Attempt to create a pawn at an invalid location + */ @Test fun createPawn() { + assertFails({ + pieceFactory.createPawn( + false, + Position(1000, 1000), + PlayerColor.BLACK, + Stage(), + ) + }) } + /** + * Attempt to create a knight at an invalid location + */ @Test fun createKnight() { + assertFails({ + pieceFactory.createKnight( + Position(1000, 1000), + PlayerColor.BLACK, + Stage(), + ) + }) } + /** + * Attempt to create a bishop at an invalid location + */ @Test fun createBishop() { + assertFails({ + pieceFactory.createBishop( + Position(1000, 1000), + PlayerColor.BLACK, + Stage(), + ) + }) } + + /** + * Attempt to create a rook at an invalid location + */ @Test fun createRook() { - assetManager.load("pieces/black-rook.png", Texture::class.java) - assetManager.finishLoading() - - pieceFactory.createRook( - Position(1, 1), - PlayerColor.BLACK, - ) - val texture: TextureRegion = TextureRegion(Texture("pieces/black-rook.png")) - assertEquals(texture, pieceFactory.getPieceTextureRegion(PieceType.ROOK, PlayerColor.BLACK)) + assertFails({ + pieceFactory.createRook( + Position(1000, 1000), + PlayerColor.BLACK, + Stage(), + ) + }) } + /** + * Attempt to create a queen at an invalid location + */ @Test fun createQueen() { + assertFails({ + pieceFactory.createQueen( + Position(1000, 1000), + PlayerColor.BLACK, + Stage(), + ) + }) } + /** + * Attempt to create a king at an invalid location + */ @Test fun createKing() { + assertFails({ + pieceFactory.createKing( + Position(1000, 1000), + PlayerColor.BLACK, + Stage(), + ) + }) } } diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt index 1c0e0935..8a89ba32 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt @@ -5,13 +5,12 @@ import org.junit.jupiter.api.Test import kotlin.test.assertFails class LobbyTest { - // TODO: update current tests, write test for the rest of the methods (Unit test) /** * Attempt to join a lobby that does not exists */ suspend fun joinLobby() { - Lobby.joinLobby("") + Lobby.joinLobby("E6U5Y5GTRFEZE45") } // Required to test suspend functions @@ -20,46 +19,4 @@ class LobbyTest { runTest { assertFails({ joinLobby() }) } - - suspend fun createLobby() { - Lobby.createLobby() - } - - @Test - fun testCreateLobby() = - runTest { - assertFails({ createLobby() }) - } - - @Test - fun leaveLobby() { - } - - @Test - fun setLobbySettings() { - } - - @Test - fun getLobby() { - } - - @Test - fun startGame() { - } - - @Test - fun isInLobby() { - } - - @Test - fun getLobbyId() { - } - - @Test - fun subscribeToLobbyUpdates() { - } - - @Test - fun unsubscribeFromLobbyUpdates() { - } } From 1e04df7c17f333306bdf50c7e848db6d12e18e5b Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Fri, 18 Apr 2025 20:56:19 +0200 Subject: [PATCH 12/21] build: Add tests for PresenterManager --- .../chessevolved/presenters/MockPresenter.kt | 23 +++++++++ .../chessevolved/PresenterManagerTest.kt | 50 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt create mode 100644 chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt diff --git a/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt b/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt new file mode 100644 index 00000000..1965d3a1 --- /dev/null +++ b/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt @@ -0,0 +1,23 @@ +package io.github.chessevolved.presenters + +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import io.github.chessevolved.Navigator +import io.github.chessevolved.views.LobbyView + +class MockPresenter ( + private val lobbyView: LobbyView, + private val navigator: Navigator, +) : IPresenter { + + override fun render(sb: SpriteBatch) { + } + + override fun resize(width: Int, height: Int) { + } + + override fun dispose() { + } + + override fun setInputProcessor() { + } +} diff --git a/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt b/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt new file mode 100644 index 00000000..9cd7c6d8 --- /dev/null +++ b/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt @@ -0,0 +1,50 @@ +package io.github.chessevolved + +import com.badlogic.gdx.assets.AssetManager +import io.github.chessevolved.presenters.IPresenter +import io.github.chessevolved.presenters.MockPresenter +import io.github.chessevolved.views.LobbyView +import java.util.ArrayDeque +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class PresenterManagerTest { + private var presenters = ArrayDeque() + private val presenter = MockPresenter(LobbyView(""), Navigator(AssetManager())) + + @Test + fun push() { + presenters.push(presenter) + PresenterManager.push(presenter) + assertEquals(presenters.peekFirst(), PresenterManager.getCurrent()) + presenters = ArrayDeque() + } + + @Test + fun pop() { + presenters.push(presenter) + PresenterManager.push(presenter) + presenters.pop() + PresenterManager.pop() + assertEquals(presenters.peekFirst(), PresenterManager.getCurrent()) + presenters = ArrayDeque() + } + + @Test + fun set() { + presenters.push(presenter) + PresenterManager.set(presenter) + assertEquals(presenters.peekFirst(), PresenterManager.getCurrent()) + presenters = ArrayDeque() + } + + @Test + fun isEmpty() { + while (!PresenterManager.isEmpty()) { + PresenterManager.pop() + } + assertTrue { PresenterManager.isEmpty() } + } + +} From 61d35919bc96450becb639ea74b59a867a77b07d Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Fri, 18 Apr 2025 21:49:43 +0200 Subject: [PATCH 13/21] build: Create GameTest, update LobbyTest --- .../chessevolved/singletons/GameTest.kt | 60 ++++++++++++++ .../chessevolved/singletons/LobbyTest.kt | 78 +++++++++++++++++-- 2 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt new file mode 100644 index 00000000..064ed6b0 --- /dev/null +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt @@ -0,0 +1,60 @@ +package io.github.chessevolved.singletons + +import kotlinx.coroutines.test.runTest +import org.junit.jupiter.api.Assertions.* + +import kotlin.test.Test +import kotlin.test.assertFails + + +class GameTest { + + suspend fun joinGame() { + Game.joinGame("HY76UYTERFRGET") + } + + /** + * Attempt to join a game that does not exists + */ + @Test + fun testJoinGame() = + runTest { // Required to test suspend functions + assertFails({ joinGame() }) + } + + suspend fun leaveGame() { + Game.leaveGame() + } + + /** + * Attempt to leave a game despite not being in a game + */ + @Test + fun testLeaveGame() = + runTest { + assertFails({ leaveGame() }) + } + + suspend fun askForRematch() { + Game.askForRematch() + } + + /** + * Attempt to ask for a rematch despite not being in a game + */ + @Test + fun testAskForRematch() = + runTest { + assertFails({ askForRematch() }) + } + + @Test + fun getWantsRematch() { + assertFalse(Game.getWantsRematch()) + } + + @Test + fun isInGame() { + assertFalse(Game.isInGame()) + } +} diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt index 8a89ba32..737f3189 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt @@ -1,22 +1,88 @@ package io.github.chessevolved.singletons import kotlinx.coroutines.test.runTest -import org.junit.jupiter.api.Test + +import org.junit.jupiter.api.assertThrows +import kotlin.test.Test import kotlin.test.assertFails class LobbyTest { - /** - * Attempt to join a lobby that does not exists - */ suspend fun joinLobby() { Lobby.joinLobby("E6U5Y5GTRFEZE45") } - // Required to test suspend functions + /** + * Attempt to join a lobby that does not exists + */ @Test fun testJoinLobby() = - runTest { + runTest { // Required to test suspend functions assertFails({ joinLobby() }) } + + suspend fun joinRematchLobbyAsHost() { + Lobby.joinRematchLobbyAsHost() + } + + /** + * Attempt to join a rematch lobby as a host that does not exists + */ + @Test + fun testJoinRematchLobbyAsHost() = + runTest { // Required to test suspend functions + assertFails({ joinRematchLobbyAsHost() }) + } + + suspend fun joinRematchLobbyNonHost() { + Lobby.joinRematchLobbyNonHost() + } + + /** + * Attempt to join a rematch lobby as a non-host that does not exists + */ + @Test + fun testJoinRematchLobbyNonHost() = + runTest { // Required to test suspend functions + assertFails({ joinRematchLobbyNonHost() }) + } + + suspend fun leaveLobby() { + Lobby.leaveLobby() + } + + /** + * Attempt to leave a lobby despite not being in a lobby + */ + @Test + fun testLeaveLobby() = + runTest { // Required to test suspend functions + assertFails({ leaveLobby() }) + } + + suspend fun leaveLobbyWithoutUpdating() { + Lobby.leaveLobbyWithoutUpdating() + } + + /** + * Attempt to leave a lobby as a second player despite not being in a lobby + */ + @Test + fun testLeaveLobbyWithoutUpdating() = + runTest { // Required to test suspend functions + assertFails({ leaveLobbyWithoutUpdating() }) + } + + suspend fun setLobbySettings() { + Lobby.setLobbySettings() + } + + /** + * Attempt to change lobby settings despite not being in a lobby + */ + @Test + fun testSetLobbySettings() = + runTest { // Required to test suspend functions + assertThrows({ setLobbySettings() }) + } } From 17d7cb887ab9aced4c8a6ea9e6abb192356bbed2 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Fri, 18 Apr 2025 22:24:56 +0200 Subject: [PATCH 14/21] build: ktlinting autofix --- .../chessevolved/entities/PieceFactoryTest.kt | 5 ----- .../chessevolved/singletons/GameTest.kt | 5 +---- .../chessevolved/singletons/LobbyTest.kt | 2 -- .../chessevolved/presenters/MockPresenter.kt | 8 ++++--- .../chessevolved/PresenterManagerTest.kt | 1 - .../chessevolved/lwjgl3/Lwjgl3LauncherTest.kt | 22 +++++++++---------- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt index 117850c8..4a2c0000 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt @@ -2,13 +2,9 @@ package io.github.chessevolved.entities import com.badlogic.ashley.core.Engine import com.badlogic.gdx.assets.AssetManager -import com.badlogic.gdx.graphics.Texture -import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.scenes.scene2d.Stage -import io.github.chessevolved.components.PieceType import io.github.chessevolved.components.PlayerColor import io.github.chessevolved.components.Position -import io.github.chessevolved.components.WeatherEvent import io.github.chessevolved.singletons.ECSEngine import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test @@ -62,7 +58,6 @@ class PieceFactoryTest { }) } - /** * Attempt to create a rook at an invalid location */ diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt index 064ed6b0..979bf244 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt @@ -2,13 +2,10 @@ package io.github.chessevolved.singletons import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.* - import kotlin.test.Test import kotlin.test.assertFails - class GameTest { - suspend fun joinGame() { Game.joinGame("HY76UYTERFRGET") } @@ -45,7 +42,7 @@ class GameTest { @Test fun testAskForRematch() = runTest { - assertFails({ askForRematch() }) + assertFails({ askForRematch() }) } @Test diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt index 737f3189..866d7aca 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/LobbyTest.kt @@ -1,13 +1,11 @@ package io.github.chessevolved.singletons import kotlinx.coroutines.test.runTest - import org.junit.jupiter.api.assertThrows import kotlin.test.Test import kotlin.test.assertFails class LobbyTest { - suspend fun joinLobby() { Lobby.joinLobby("E6U5Y5GTRFEZE45") } diff --git a/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt b/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt index 1965d3a1..c47c02b6 100644 --- a/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt +++ b/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt @@ -4,15 +4,17 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import io.github.chessevolved.Navigator import io.github.chessevolved.views.LobbyView -class MockPresenter ( +class MockPresenter( private val lobbyView: LobbyView, private val navigator: Navigator, ) : IPresenter { - override fun render(sb: SpriteBatch) { } - override fun resize(width: Int, height: Int) { + override fun resize( + width: Int, + height: Int, + ) { } override fun dispose() { diff --git a/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt b/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt index 9cd7c6d8..71faeed4 100644 --- a/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt +++ b/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt @@ -46,5 +46,4 @@ class PresenterManagerTest { } assertTrue { PresenterManager.isEmpty() } } - } diff --git a/lwjgl3/src/test/kotlin/io/github/chessevolved/lwjgl3/Lwjgl3LauncherTest.kt b/lwjgl3/src/test/kotlin/io/github/chessevolved/lwjgl3/Lwjgl3LauncherTest.kt index 04b43cf6..94155359 100644 --- a/lwjgl3/src/test/kotlin/io/github/chessevolved/lwjgl3/Lwjgl3LauncherTest.kt +++ b/lwjgl3/src/test/kotlin/io/github/chessevolved/lwjgl3/Lwjgl3LauncherTest.kt @@ -7,20 +7,20 @@ import org.junit.jupiter.api.assertDoesNotThrow import kotlin.test.Test class Lwjgl3LauncherTest { - @Test fun testUI() { - val config: Lwjgl3ApplicationConfiguration = Lwjgl3ApplicationConfiguration().apply { - setTitle("Chess Evolved") - setWindowedMode(360, 800) - setWindowIcon( - *( - arrayOf(128, 64, 32, 16) - .map { "libgdx$it.png" } - .toTypedArray() + val config: Lwjgl3ApplicationConfiguration = + Lwjgl3ApplicationConfiguration().apply { + setTitle("Chess Evolved") + setWindowedMode(360, 800) + setWindowIcon( + *( + arrayOf(128, 64, 32, 16) + .map { "libgdx$it.png" } + .toTypedArray() ), - ) - } + ) + } config.disableAudio(true) val testApplication: Lwjgl3Application = Lwjgl3Application(ChessEvolvedGame(), config) assertDoesNotThrow({ testApplication.exit() }) From 23244967b1dc6fdc435b1abcac9ce5d1cac62e6d Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Fri, 18 Apr 2025 22:26:18 +0200 Subject: [PATCH 15/21] build: ktlinting --- .../kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt | 1 - .../io/github/chessevolved/singletons/GameSettingsTest.kt | 2 +- .../test/kotlin/io/github/chessevolved/singletons/GameTest.kt | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt index 4a2c0000..dac84b19 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt @@ -6,7 +6,6 @@ import com.badlogic.gdx.scenes.scene2d.Stage import io.github.chessevolved.components.PlayerColor import io.github.chessevolved.components.Position import io.github.chessevolved.singletons.ECSEngine -import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import kotlin.test.assertFails diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt index ffd85870..80b1be43 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt @@ -1,7 +1,7 @@ package io.github.chessevolved.singletons import io.github.chessevolved.shared.SettingsDTO -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals import kotlin.test.Test class GameSettingsTest { diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt index 979bf244..f565f462 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameTest.kt @@ -1,7 +1,7 @@ package io.github.chessevolved.singletons import kotlinx.coroutines.test.runTest -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertFalse import kotlin.test.Test import kotlin.test.assertFails From 7c3fc936f626679b38243c74cf8f6214ea4eed38 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Sun, 20 Apr 2025 00:32:14 +0200 Subject: [PATCH 16/21] build: Add jacoco package --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index ffdf1779..896b73be 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,7 @@ plugins { allprojects { apply plugin: 'eclipse' apply plugin: 'idea' + apply plugin: 'jacoco' // This allows you to "Build and run using IntelliJ IDEA", an option in IDEA's Settings. idea { From 4652323ee38bc90bb8b0bbb0558b16cdd860d253 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Sun, 20 Apr 2025 01:09:30 +0200 Subject: [PATCH 17/21] build: Update README.md --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bfdd07d3..bba577be 100644 --- a/README.md +++ b/README.md @@ -123,8 +123,6 @@ For VSCode or Neovim users, you know what you are doing. ### Debug and Testing -This is not setup yet! Remove this when setup is complete and add GitHub action. - Run unit tests: ```bash @@ -137,6 +135,17 @@ Run unit tests with coverage: ./gradlew test jacocoTestReport ``` +The test coverage reports for each subproject can be found at: +- [Chessevolved model](chessevolved_model/build/reports/jacoco/test/html/index.html) +- [Chessevolved presenter](chessevolved_presenter/build/reports/jacoco/test/html/index.html) +- [Lwjgl3 (Desktop launcher)](lwjgl3/build/reports/jacoco/test/html/index.html) + +If Jacoco does not generate coverage reports when running the previous command, run the following: + +```bash +./gradlew test --rerun jacocoTestReport +``` + ### Dependencies - [KTX](https://libktx.github.io/) - Kotlin extensions for LibGDX From a3e7224e408fdfac09c6453f1e22ab11360ad5c6 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Sun, 20 Apr 2025 14:31:50 +0200 Subject: [PATCH 18/21] build: Create MockView.kt --- .../io/github/chessevolved/views/MockView.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 chessevolved_view/src/main/kotlin/io/github/chessevolved/views/MockView.kt diff --git a/chessevolved_view/src/main/kotlin/io/github/chessevolved/views/MockView.kt b/chessevolved_view/src/main/kotlin/io/github/chessevolved/views/MockView.kt new file mode 100644 index 00000000..eac63060 --- /dev/null +++ b/chessevolved_view/src/main/kotlin/io/github/chessevolved/views/MockView.kt @@ -0,0 +1,20 @@ +package io.github.chessevolved.views + +class MockView( + private val lobbyCode: String, +) : IView { + override fun init() { + } + + override fun render() { + } + + override fun resize(width: Int, height: Int) { + } + + override fun dispose() { + } + + override fun setInputProcessor() { + } +} From 64a29e7d99ec420be2b056db4594aad400a728d8 Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Sun, 20 Apr 2025 14:52:12 +0200 Subject: [PATCH 19/21] build: Update PresenterManagerTest tests --- .../kotlin/io/github/chessevolved/presenters/MockPresenter.kt | 4 ++-- .../kotlin/io/github/chessevolved/PresenterManagerTest.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt b/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt index c47c02b6..e252d111 100644 --- a/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt +++ b/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/MockPresenter.kt @@ -2,10 +2,10 @@ package io.github.chessevolved.presenters import com.badlogic.gdx.graphics.g2d.SpriteBatch import io.github.chessevolved.Navigator -import io.github.chessevolved.views.LobbyView +import io.github.chessevolved.views.IView class MockPresenter( - private val lobbyView: LobbyView, + private val view: IView, private val navigator: Navigator, ) : IPresenter { override fun render(sb: SpriteBatch) { diff --git a/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt b/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt index 71faeed4..97ff8a77 100644 --- a/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt +++ b/chessevolved_presenter/src/test/kotlin/io/github/chessevolved/PresenterManagerTest.kt @@ -3,7 +3,7 @@ package io.github.chessevolved import com.badlogic.gdx.assets.AssetManager import io.github.chessevolved.presenters.IPresenter import io.github.chessevolved.presenters.MockPresenter -import io.github.chessevolved.views.LobbyView +import io.github.chessevolved.views.MockView import java.util.ArrayDeque import kotlin.test.Test import kotlin.test.assertEquals @@ -11,7 +11,7 @@ import kotlin.test.assertTrue class PresenterManagerTest { private var presenters = ArrayDeque() - private val presenter = MockPresenter(LobbyView(""), Navigator(AssetManager())) + private val presenter = MockPresenter(MockView(""), Navigator(AssetManager())) @Test fun push() { From 4c064cd23f425a0f8b9edda373c15a6a30552ebc Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Sun, 20 Apr 2025 15:00:58 +0200 Subject: [PATCH 20/21] build: Update model tests --- .../chessevolved/entities/BoardSquareFactoryTest.kt | 10 +++++----- .../github/chessevolved/entities/PieceFactoryTest.kt | 8 ++++---- .../github/chessevolved/singletons/GameSettingsTest.kt | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt index a1da4300..dfdf511e 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/BoardSquareFactoryTest.kt @@ -3,15 +3,15 @@ package io.github.chessevolved.entities import com.badlogic.ashley.core.Engine import com.badlogic.gdx.assets.AssetManager import com.badlogic.gdx.scenes.scene2d.Stage -import io.github.chessevolved.components.PlayerColor -import io.github.chessevolved.components.Position -import io.github.chessevolved.components.WeatherEvent -import io.github.chessevolved.singletons.ECSEngine +import io.github.chessevolved.data.Position +import io.github.chessevolved.enums.PlayerColor +import io.github.chessevolved.enums.WeatherEvent +import io.github.chessevolved.singletons.EcsEngine import org.junit.jupiter.api.Test import kotlin.test.assertFails class BoardSquareFactoryTest { - private val engine: Engine = ECSEngine + private val engine: Engine = EcsEngine private val assetManager: AssetManager = AssetManager() private val boardSquareFactory: BoardSquareFactory = BoardSquareFactory(engine, assetManager) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt index dac84b19..54216544 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/entities/PieceFactoryTest.kt @@ -3,14 +3,14 @@ package io.github.chessevolved.entities import com.badlogic.ashley.core.Engine import com.badlogic.gdx.assets.AssetManager import com.badlogic.gdx.scenes.scene2d.Stage -import io.github.chessevolved.components.PlayerColor -import io.github.chessevolved.components.Position -import io.github.chessevolved.singletons.ECSEngine +import io.github.chessevolved.data.Position +import io.github.chessevolved.enums.PlayerColor +import io.github.chessevolved.singletons.EcsEngine import org.junit.jupiter.api.Test import kotlin.test.assertFails class PieceFactoryTest { - private val engine: Engine = ECSEngine + private val engine: Engine = EcsEngine private val assetManager: AssetManager = AssetManager() private val pieceFactory: PieceFactory = PieceFactory(engine, assetManager) diff --git a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt index 80b1be43..73f35562 100644 --- a/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt +++ b/chessevolved_model/src/test/kotlin/io/github/chessevolved/singletons/GameSettingsTest.kt @@ -1,6 +1,6 @@ package io.github.chessevolved.singletons -import io.github.chessevolved.shared.SettingsDTO +import io.github.chessevolved.dtos.SettingsDto import org.junit.jupiter.api.Assertions.assertEquals import kotlin.test.Test @@ -17,13 +17,13 @@ class GameSettingsTest { @Test fun getGameSettings() { - val settingsDTO: SettingsDTO = SettingsDTO(false, 8) + val settingsDTO: SettingsDto = SettingsDto(false, 8) assertEquals(settingsDTO, GameSettings.getGameSettings()) } @Test fun setGameSettings() { - val settingsDTO: SettingsDTO = SettingsDTO(true, 16) + val settingsDTO: SettingsDto = SettingsDto(true, 16) GameSettings.setGameSettings(settingsDTO) assertEquals(settingsDTO, GameSettings.getGameSettings()) assertEquals(true, GameSettings.isFOWEnabled()) From b09f74152c85e4b3ca06f9360f6e927bb6aaeb5f Mon Sep 17 00:00:00 2001 From: William Tjonndal Date: Sun, 20 Apr 2025 15:05:40 +0200 Subject: [PATCH 21/21] build: ktlint --- .../src/main/kotlin/io/github/chessevolved/views/MockView.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chessevolved_view/src/main/kotlin/io/github/chessevolved/views/MockView.kt b/chessevolved_view/src/main/kotlin/io/github/chessevolved/views/MockView.kt index eac63060..490008ca 100644 --- a/chessevolved_view/src/main/kotlin/io/github/chessevolved/views/MockView.kt +++ b/chessevolved_view/src/main/kotlin/io/github/chessevolved/views/MockView.kt @@ -9,7 +9,10 @@ class MockView( override fun render() { } - override fun resize(width: Int, height: Int) { + override fun resize( + width: Int, + height: Int, + ) { } override fun dispose() {