Skip to content
Snippets Groups Projects
Commit ffa0ce1f authored by Edvard Berdal Eek's avatar Edvard Berdal Eek
Browse files

Explore game unit tests

parent 08a4b2c5
No related branches found
No related tags found
1 merge request!20Created test classes for Factory and FileReader. Created equals methods
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,org.mockito.MockitoAnnotations,openMocks" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
...@@ -42,7 +42,26 @@ ...@@ -42,7 +42,26 @@
<artifactId>javafx-media</artifactId> <artifactId>javafx-media</artifactId>
<version>21.0.2</version> <version>21.0.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.12.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.12.4</version>
<scope>test</scope>
</dependency>
<!-- Mockito JUnit Jupiter Dependency -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.11.2</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -42,8 +42,6 @@ public class ChaosGameFileHandler { ...@@ -42,8 +42,6 @@ public class ChaosGameFileHandler {
Vector2D maxCoords; Vector2D maxCoords;
try (BufferedReader reader = new BufferedReader(new FileReader(path))) { try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
String typeOfTransformation = skipComments(reader.readLine()); String typeOfTransformation = skipComments(reader.readLine());
System.out.println("Parsing type of transformation: " + typeOfTransformation);
minCoords = parseVector(reader.readLine().trim()); minCoords = parseVector(reader.readLine().trim());
maxCoords = parseVector(reader.readLine().trim()); maxCoords = parseVector(reader.readLine().trim());
...@@ -161,7 +159,6 @@ public class ChaosGameFileHandler { ...@@ -161,7 +159,6 @@ public class ChaosGameFileHandler {
*/ */
public Vector2D parseVector(String line) { public Vector2D parseVector(String line) {
String numbers = skipComments(line); String numbers = skipComments(line);
System.out.println("Parsing vector: " + numbers);
String[] vectorParts = numbers.split(","); String[] vectorParts = numbers.split(",");
double x = Double.parseDouble(vectorParts[0].trim()); double x = Double.parseDouble(vectorParts[0].trim());
double y = Double.parseDouble(vectorParts[1].trim()); double y = Double.parseDouble(vectorParts[1].trim());
...@@ -176,7 +173,6 @@ public class ChaosGameFileHandler { ...@@ -176,7 +173,6 @@ public class ChaosGameFileHandler {
*/ */
public Transform2D parseAffine(String line) { public Transform2D parseAffine(String line) {
String numbers = skipComments(line); String numbers = skipComments(line);
System.out.println("Parsing transform: " + numbers);
String[] transformParts = numbers.split(","); String[] transformParts = numbers.split(",");
double a = Double.parseDouble(transformParts[0].trim()); double a = Double.parseDouble(transformParts[0].trim());
double b = Double.parseDouble(transformParts[1].trim()); double b = Double.parseDouble(transformParts[1].trim());
...@@ -195,7 +191,6 @@ public class ChaosGameFileHandler { ...@@ -195,7 +191,6 @@ public class ChaosGameFileHandler {
*/ */
public Transform2D parseJulia(String line) { public Transform2D parseJulia(String line) {
String numbers = skipComments(line); String numbers = skipComments(line);
System.out.println("Parsing transform: " + numbers);
String[] parts = numbers.split(","); String[] parts = numbers.split(",");
double r = Double.parseDouble(parts[0].trim()); double r = Double.parseDouble(parts[0].trim());
double i = Double.parseDouble(parts[1].trim()); double i = Double.parseDouble(parts[1].trim());
......
package org.example.chaosgame.model.chaos; package org.example.chaosgame.model.chaos;
import org.junit.jupiter.api.AfterEach; import org.example.chaosgame.model.linalg.Complex;
import org.junit.jupiter.api.BeforeEach; import org.example.chaosgame.model.linalg.Vector2D;
import org.junit.jupiter.api.Test; import org.example.chaosgame.model.transformations.ExploreJulia;
import org.example.chaosgame.model.transformations.Transform2D;
import org.example.chaosgame.controller.interfaces.Observer;
import org.junit.jupiter.api.*;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
class ExploreGameTest { class ExploreGameTest {
private ExploreGame exploreGame;
private ChaosGameDescription description;
private static final int WIDTH = 100;
private static final int HEIGHT = 100;
private List<Transform2D> transforms;
private ExploreJulia exploreJulia;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
Vector2D minCoords = new Vector2D(-1.6, -1);
Vector2D maxCoords = new Vector2D(1.6, 1);
transforms = new ArrayList<>();
exploreJulia = new ExploreJulia(new Complex(0, 1));
transforms.add(exploreJulia);
description = new ChaosGameDescription(minCoords, maxCoords, transforms);
exploreGame = new ExploreGame(description, WIDTH, HEIGHT);
} }
@AfterEach @AfterEach
void tearDown() { void tearDown() {
transforms = null;
exploreJulia = null;
exploreGame = null;
description = null;
} }
@Test @Test
void exploreFractals() { void testSetExploreGame() {
} Vector2D newMinCoords = new Vector2D(-1.6, -1);
Vector2D newMaxCoords = new Vector2D(1.6, 1);
List<Transform2D> newTransforms = new ArrayList<>();
newTransforms.add(new ExploreJulia(new Complex(1, 1)));
ChaosGameDescription newDescription = new ChaosGameDescription(newMinCoords, newMaxCoords, newTransforms);
@Test exploreGame.setExploreGame(newDescription, 200, 200);
void setChaosCanvas() {
}
@Test assertEquals(newDescription, exploreGame.getDescription());
void setExploreGame() { ChaosCanvas canvas = exploreGame.getCanvas();
assertEquals(200, canvas.getWidth());
assertEquals(200, canvas.getHeight());
assertEquals(newMinCoords, canvas.getMinCoords());
assertEquals(newMaxCoords, canvas.getMaxCoords());
} }
@Test @Test
void getCanvas() { void testGetCanvas() {
ChaosCanvas canvas = exploreGame.getCanvas();
assertNotNull(canvas);
assertEquals(WIDTH, canvas.getWidth());
assertEquals(HEIGHT, canvas.getHeight());
} }
@Test @Test
void getDescription() { void testGetDescription() {
assertEquals(description, exploreGame.getDescription());
} }
@Test @Test
void registerObserver() { void testSetChaosCanvas() {
} Vector2D newMinCoords = new Vector2D(-2, -2);
Vector2D newMaxCoords = new Vector2D(2, 2);
exploreGame.setChaosCanvas(newMinCoords, newMaxCoords, 300, 300);
@Test ChaosCanvas canvas = exploreGame.getCanvas();
void removeObserver() { assertEquals(300, canvas.getWidth());
assertEquals(300, canvas.getHeight());
assertEquals(newMinCoords, canvas.getMinCoords());
assertEquals(newMaxCoords, canvas.getMaxCoords());
} }
@Test @Test
void notifyObservers() { void testExploreFractals() {
exploreGame.exploreFractals();
ChaosCanvas canvas = exploreGame.getCanvas();
for (int i = 0; i < canvas.getHeight(); i++) {
for (int j = 0; j < canvas.getWidth(); j++) {
assertTrue(canvas.getPixel(new Vector2D(i, j)) >= 0);
}
}
} }
@Test @Test
void call() { void testRemoveObserver() {
Observer observer = () -> fail("Observer should not be notified");
exploreGame.registerObserver(observer);
exploreGame.removeObserver(observer);
// exploreGame.notifyObservers();
} }
@Test @Test
void stopTask() { void testRegisterAndNotifyObservers() {
Observer observer1 = () -> assertTrue(true,"Observer should be notified");
Observer observer2 = () -> assertTrue(true,"Observer should be notified");
exploreGame.registerObserver(observer1);
exploreGame.registerObserver(observer2);
exploreGame.notifyObservers();
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment