diff --git a/src/main/java/org/toop/game/tictactoe/MinMaxTicTacToe.java b/src/main/java/org/toop/game/tictactoe/ai/MinMaxTicTacToe.java similarity index 98% rename from src/main/java/org/toop/game/tictactoe/MinMaxTicTacToe.java rename to src/main/java/org/toop/game/tictactoe/ai/MinMaxTicTacToe.java index a8dc2e1..b3b96b6 100644 --- a/src/main/java/org/toop/game/tictactoe/MinMaxTicTacToe.java +++ b/src/main/java/org/toop/game/tictactoe/ai/MinMaxTicTacToe.java @@ -1,8 +1,9 @@ -package org.toop.game.tictactoe; +package org.toop.game.tictactoe.ai; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.toop.game.*; +import org.toop.game.tictactoe.TicTacToe; public class MinMaxTicTacToe { diff --git a/src/test/java/org/toop/frontend/math/BoundsTest.java b/src/test/java/org/toop/frontend/math/BoundsTest.java new file mode 100644 index 0000000..c58fa5f --- /dev/null +++ b/src/test/java/org/toop/frontend/math/BoundsTest.java @@ -0,0 +1,60 @@ +package org.toop.frontend.math; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class BoundsTest { + + private Bounds bounds; + + @BeforeEach + void setUp() { + bounds = new Bounds(10, 20, 100, 50); + } + + @Test + void testConstructorAndGetters() { + assertEquals(10, bounds.getX()); + assertEquals(20, bounds.getY()); + assertEquals(100, bounds.getWidth()); + assertEquals(50, bounds.getHeight()); + } + + @Test + void testSetUpdatesFields() { + bounds.set(5, 15, 50, 25); + + assertEquals(5, bounds.getX()); + assertEquals(15, bounds.getY()); + assertEquals(50, bounds.getWidth()); + assertEquals(25, bounds.getHeight()); + } + + @Test + void testCheckInsideBounds() { + // Points inside the bounds + assertTrue(bounds.check(10, 20)); // top-left corner + assertTrue(bounds.check(110, 70)); // bottom-right corner + assertTrue(bounds.check(60, 45)); // inside + } + + @Test + void testCheckOutsideBounds() { + // Points outside the bounds + assertFalse(bounds.check(9, 20)); // left + assertFalse(bounds.check(10, 19)); // above + assertFalse(bounds.check(111, 70)); // right + assertFalse(bounds.check(110, 71)); // below + } + + @Test + void testCheckOnEdgeBounds() { + // Points on the edges should be considered inside + assertTrue(bounds.check(10, 20)); // top-left + assertTrue(bounds.check(110, 20)); // top-right + assertTrue(bounds.check(10, 70)); // bottom-left + assertTrue(bounds.check(110, 70)); // bottom-right + } +} \ No newline at end of file diff --git a/src/test/java/org/toop/frontend/math/ColorTest.java b/src/test/java/org/toop/frontend/math/ColorTest.java new file mode 100644 index 0000000..ab979e0 --- /dev/null +++ b/src/test/java/org/toop/frontend/math/ColorTest.java @@ -0,0 +1,32 @@ +package org.toop.frontend.math; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ColorTest { + + private Color color; + + @BeforeEach + void setUp() { + color = new Color(0.1f, 0.5f, 0.9f); + } + + @Test + void testConstructorAndGetters() { + assertEquals(0.1f, color.r(), 0.0001, "Red component should match"); + assertEquals(0.5f, color.g(), 0.0001, "Green component should match"); + assertEquals(0.9f, color.b(), 0.0001, "Blue component should match"); + } + + @Test + void testDifferentColorValues() { + Color c = new Color(1.0f, 0.0f, 0.5f); + + assertEquals(1.0f, c.r(), 0.0001); + assertEquals(0.0f, c.g(), 0.0001); + assertEquals(0.5f, c.b(), 0.0001); + } +} diff --git a/src/test/java/MinMaxTicTacToeTest.java b/src/test/java/org/toop/game/tictactoe/ai/MinMaxTicTacToeTest.java similarity index 98% rename from src/test/java/MinMaxTicTacToeTest.java rename to src/test/java/org/toop/game/tictactoe/ai/MinMaxTicTacToeTest.java index 4becc7d..a8beaf3 100644 --- a/src/test/java/MinMaxTicTacToeTest.java +++ b/src/test/java/org/toop/game/tictactoe/ai/MinMaxTicTacToeTest.java @@ -1,9 +1,10 @@ +package org.toop.game.tictactoe.ai; + import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.toop.game.GameBase; -import org.toop.game.tictactoe.MinMaxTicTacToe; import org.toop.game.tictactoe.TicTacToe; /** Unit tests for MinMaxTicTacToe AI. */