diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000000000000000000000000000000000000..45f76e0205cae24a7ffb39876099e3d534ab39e9 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ +<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 diff --git a/pom.xml b/pom.xml index 5425b77710f09a22f07dbeb5d1f53e768242bf55..250218dcad301f8f9f114f237cb1409fd19eb9c5 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,26 @@ <artifactId>javafx-media</artifactId> <version>21.0.2</version> </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> <build> diff --git a/src/main/java/org/example/chaosgame/model/chaos/ChaosGameFileHandler.java b/src/main/java/org/example/chaosgame/model/chaos/ChaosGameFileHandler.java index 8ff74ce16dfc92c236c24edee7b745534e30d58a..7b0256d51506f800c03eaccc50371cae118bad96 100644 --- a/src/main/java/org/example/chaosgame/model/chaos/ChaosGameFileHandler.java +++ b/src/main/java/org/example/chaosgame/model/chaos/ChaosGameFileHandler.java @@ -42,8 +42,6 @@ public class ChaosGameFileHandler { Vector2D maxCoords; try (BufferedReader reader = new BufferedReader(new FileReader(path))) { String typeOfTransformation = skipComments(reader.readLine()); - System.out.println("Parsing type of transformation: " + typeOfTransformation); - minCoords = parseVector(reader.readLine().trim()); maxCoords = parseVector(reader.readLine().trim()); @@ -161,7 +159,6 @@ public class ChaosGameFileHandler { */ public Vector2D parseVector(String line) { String numbers = skipComments(line); - System.out.println("Parsing vector: " + numbers); String[] vectorParts = numbers.split(","); double x = Double.parseDouble(vectorParts[0].trim()); double y = Double.parseDouble(vectorParts[1].trim()); @@ -176,7 +173,6 @@ public class ChaosGameFileHandler { */ public Transform2D parseAffine(String line) { String numbers = skipComments(line); - System.out.println("Parsing transform: " + numbers); String[] transformParts = numbers.split(","); double a = Double.parseDouble(transformParts[0].trim()); double b = Double.parseDouble(transformParts[1].trim()); @@ -195,7 +191,6 @@ public class ChaosGameFileHandler { */ public Transform2D parseJulia(String line) { String numbers = skipComments(line); - System.out.println("Parsing transform: " + numbers); String[] parts = numbers.split(","); double r = Double.parseDouble(parts[0].trim()); double i = Double.parseDouble(parts[1].trim()); diff --git a/src/test/java/org/example/chaosgame/model/chaos/ExploreGameTest.java b/src/test/java/org/example/chaosgame/model/chaos/ExploreGameTest.java index 7c6d541308d46f50c26dad2d103cb24b0249f8af..00df0981b9b3f59bb362e539cb2faae5d7e84f10 100644 --- a/src/test/java/org/example/chaosgame/model/chaos/ExploreGameTest.java +++ b/src/test/java/org/example/chaosgame/model/chaos/ExploreGameTest.java @@ -1,58 +1,116 @@ package org.example.chaosgame.model.chaos; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.example.chaosgame.model.linalg.Complex; +import org.example.chaosgame.model.linalg.Vector2D; +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.mockito.Mockito.*; 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 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 void tearDown() { + transforms = null; + exploreJulia = null; + exploreGame = null; + description = null; } @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 - void setChaosCanvas() { - } + exploreGame.setExploreGame(newDescription, 200, 200); - @Test - void setExploreGame() { + assertEquals(newDescription, exploreGame.getDescription()); + ChaosCanvas canvas = exploreGame.getCanvas(); + assertEquals(200, canvas.getWidth()); + assertEquals(200, canvas.getHeight()); + assertEquals(newMinCoords, canvas.getMinCoords()); + assertEquals(newMaxCoords, canvas.getMaxCoords()); } @Test - void getCanvas() { + void testGetCanvas() { + ChaosCanvas canvas = exploreGame.getCanvas(); + assertNotNull(canvas); + assertEquals(WIDTH, canvas.getWidth()); + assertEquals(HEIGHT, canvas.getHeight()); } @Test - void getDescription() { + void testGetDescription() { + assertEquals(description, exploreGame.getDescription()); } @Test - void registerObserver() { - } + void testSetChaosCanvas() { + Vector2D newMinCoords = new Vector2D(-2, -2); + Vector2D newMaxCoords = new Vector2D(2, 2); + exploreGame.setChaosCanvas(newMinCoords, newMaxCoords, 300, 300); - @Test - void removeObserver() { + ChaosCanvas canvas = exploreGame.getCanvas(); + assertEquals(300, canvas.getWidth()); + assertEquals(300, canvas.getHeight()); + assertEquals(newMinCoords, canvas.getMinCoords()); + assertEquals(newMaxCoords, canvas.getMaxCoords()); } @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 - void call() { + void testRemoveObserver() { + Observer observer = () -> fail("Observer should not be notified"); + exploreGame.registerObserver(observer); + exploreGame.removeObserver(observer); +// exploreGame.notifyObservers(); } @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 +}