Moved MinMaxTicTacToe.java to its own ai package. Added unittests for math classes.

This commit is contained in:
lieght
2025-09-20 17:26:12 +02:00
parent 804a803027
commit f378897769
4 changed files with 96 additions and 2 deletions

View File

@@ -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.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.toop.game.*; import org.toop.game.*;
import org.toop.game.tictactoe.TicTacToe;
public class MinMaxTicTacToe { public class MinMaxTicTacToe {

View File

@@ -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
}
}

View File

@@ -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);
}
}

View File

@@ -1,9 +1,10 @@
package org.toop.game.tictactoe.ai;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.toop.game.GameBase; import org.toop.game.GameBase;
import org.toop.game.tictactoe.MinMaxTicTacToe;
import org.toop.game.tictactoe.TicTacToe; import org.toop.game.tictactoe.TicTacToe;
/** Unit tests for MinMaxTicTacToe AI. */ /** Unit tests for MinMaxTicTacToe AI. */