mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Moved MinMaxTicTacToe.java to its own ai package. Added unittests for math classes.
This commit is contained in:
@@ -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 {
|
||||||
|
|
||||||
60
src/test/java/org/toop/frontend/math/BoundsTest.java
Normal file
60
src/test/java/org/toop/frontend/math/BoundsTest.java
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/test/java/org/toop/frontend/math/ColorTest.java
Normal file
32
src/test/java/org/toop/frontend/math/ColorTest.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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. */
|
||||||
Reference in New Issue
Block a user