From 431ac5f01d0ded559676dab849383c2dd36bba4c Mon Sep 17 00:00:00 2001 From: Edvard <edvardee@stud.ntnu.no> Date: Mon, 20 May 2024 16:32:00 +0200 Subject: [PATCH] Refactoring and Google Checkstyle --- .idea/checkstyle-idea.xml | 2 +- .../java/org/example/chaosgame/MainApp.java | 5 +- .../controller/ChaosGameController.java | 34 +++-- .../ChaosGameDescriptionFactory.java | 4 +- .../ChaosGameFileHandler.java | 3 +- .../controller/ExploreGameController.java | 98 +++++++------- .../chaosgame/model/chaos/ChaosCanvas.java | 17 ++- .../model/chaos/ChaosGameDescription.java | 14 +- .../chaosgame/model/chaos/ExploreGame.java | 30 ++-- .../chaosgame/model/linalg/Matrix2x2.java | 13 +- .../chaosgame/model/linalg/Vector2D.java | 24 +++- .../transformations/AffineTransform2D.java | 10 +- .../model/transformations/JuliaTransform.java | 11 +- .../controller/ChaosGameControllerTest.java | 128 +++++++++--------- .../controller/ExploreGameControllerTest.java | 98 +++++++------- .../controller/HomeControllerTest.java | 14 +- .../controller/PageControllerTest.java | 18 +-- .../model/chaos/ChaosCanvasTest.java | 8 +- .../ChaosGameDescriptionFactoryTest.java | 28 ++-- .../model/chaos/ChaosGameDescriptionTest.java | 59 +++++--- .../model/chaos/ChaosGameFileHandlerTest.java | 72 ++++++---- .../chaosgame/model/chaos/ChaosGameTest.java | 44 ++++-- .../model/chaos/ExploreGameTest.java | 1 - 23 files changed, 431 insertions(+), 304 deletions(-) rename src/main/java/org/example/chaosgame/{model/chaos => controller}/ChaosGameDescriptionFactory.java (95%) rename src/main/java/org/example/chaosgame/{model/chaos => controller}/ChaosGameFileHandler.java (98%) diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml index 3bab646..5536a0d 100644 --- a/.idea/checkstyle-idea.xml +++ b/.idea/checkstyle-idea.xml @@ -2,7 +2,7 @@ <project version="4"> <component name="CheckStyle-IDEA" serialisationVersion="2"> <checkstyleVersion>10.13.0</checkstyleVersion> - <scanScope>JavaOnly</scanScope> + <scanScope>JavaOnlyWithTests</scanScope> <option name="thirdPartyClasspath" /> <option name="activeLocationIds" /> <option name="locations"> diff --git a/src/main/java/org/example/chaosgame/MainApp.java b/src/main/java/org/example/chaosgame/MainApp.java index afd7974..631385a 100644 --- a/src/main/java/org/example/chaosgame/MainApp.java +++ b/src/main/java/org/example/chaosgame/MainApp.java @@ -24,7 +24,10 @@ public class MainApp extends Application { new PageController(mainPane, chaosGameController, exploreGameController); Scene scene = new Scene(mainPane, 1200, 800); - scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/global.css")).toExternalForm()); + scene.getStylesheets().add( + Objects.requireNonNull(getClass() + .getResource("/global.css")) + .toExternalForm()); primaryStage.setMinWidth(1000); primaryStage.setMinHeight(650); diff --git a/src/main/java/org/example/chaosgame/controller/ChaosGameController.java b/src/main/java/org/example/chaosgame/controller/ChaosGameController.java index 065e5bd..cb8678b 100644 --- a/src/main/java/org/example/chaosgame/controller/ChaosGameController.java +++ b/src/main/java/org/example/chaosgame/controller/ChaosGameController.java @@ -2,8 +2,10 @@ package org.example.chaosgame.controller; import java.io.File; import java.io.IOException; -import java.util.*; - +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import javafx.scene.canvas.Canvas; import javafx.scene.control.TextField; import javafx.scene.layout.StackPane; @@ -15,12 +17,10 @@ import org.example.chaosgame.controller.interfaces.Observer; import org.example.chaosgame.controller.interfaces.Subject; import org.example.chaosgame.model.chaos.ChaosGame; import org.example.chaosgame.model.chaos.ChaosGameDescription; -import org.example.chaosgame.model.chaos.ChaosGameDescriptionFactory; -import org.example.chaosgame.model.chaos.ChaosGameFileHandler; import org.example.chaosgame.model.chaos.ChaosGameType; import org.example.chaosgame.model.linalg.Complex; -import org.example.chaosgame.model.linalg.Vector2D; import org.example.chaosgame.model.linalg.Matrix2x2; +import org.example.chaosgame.model.linalg.Vector2D; import org.example.chaosgame.model.transformations.AffineTransform2D; import org.example.chaosgame.model.transformations.JuliaTransform; import org.example.chaosgame.model.transformations.Transform2D; @@ -104,17 +104,20 @@ public class ChaosGameController implements Observer, Subject, GameController { try { int steps = Integer.parseInt(input); chaosGame.setSteps(steps); - if (chaosGame.getDescription().getTransforms().getFirst() instanceof JuliaTransform && steps > 250000) { - throw new IllegalArgumentException("Please enter a lower amount of steps for Julia transformations."); + if (chaosGame.getDescription().getTransforms().getFirst() + instanceof JuliaTransform && steps > 250000) { + throw new IllegalArgumentException( + "Please enter a lower amount of steps for Julia transformations."); } if (chaosGame.getTotalSteps() > Math.pow(10, 8)) { - throw new IllegalArgumentException("The total amount of steps is too high. Choose a lower amount."); + throw new IllegalArgumentException( + "The total amount of steps is too high. Choose a lower amount."); } chaosGame.addTotalSteps(steps); chaosGame.runSteps(); stepsField.getStyleClass().remove("text-field-invalid"); - } catch (NumberFormatException e){ + } catch (NumberFormatException e) { stepsField.clear(); stepsField.getStyleClass().add("text-field-invalid"); AlertUtility.showErrorDialog("Invalid input", "Please enter a valid number."); @@ -186,10 +189,12 @@ public class ChaosGameController implements Observer, Subject, GameController { } /** - * Method for creating a new fractal. + * Method for user creation of fractal. + * {@link org.example.chaosgame.view.components.CreateFractalDialog} returns either a + * {@link java.util.List}<{@link java.util.List}<{@link java.lang.String}>> + * or a {@link javafx.util.Pair}<{@link java.lang.String}, {@link java.lang.String}>. * * <p>Opens a dialog for the user to create a new fractal. - * */ public void createOwnFractal() { CreateFractalDialog dialog = new CreateFractalDialog(); @@ -200,7 +205,7 @@ public class ChaosGameController implements Observer, Subject, GameController { List<Transform2D> transforms = new ArrayList<>(); if (fractalData instanceof List) { List<List<String>> userInput = (List<List<String>>) fractalData; - for(List<String> input : userInput) { + for (List<String> input : userInput) { try { double a = Double.parseDouble(input.get(0)); double b = Double.parseDouble(input.get(1)); @@ -209,8 +214,8 @@ public class ChaosGameController implements Observer, Subject, GameController { double x = Double.parseDouble(input.get(4)); double y = Double.parseDouble(input.get(5)); - if (a < -5 || a > 5 || b < -5 || b > 5 || c < -5 || c > 5 || - d < -5 || d > 5 || x < -5 || x > 5 || y < -5 || y > 5) { + if (a < -5 || a > 5 || b < -5 || b > 5 || c < -5 || c > 5 + || d < -5 || d > 5 || x < -5 || x > 5 || y < -5 || y > 5) { throw new NumberFormatException(); } else { transforms.add(new AffineTransform2D(new Matrix2x2(a, b, c, d), new Vector2D(x, y))); @@ -223,7 +228,6 @@ public class ChaosGameController implements Observer, Subject, GameController { AlertUtility.showErrorDialog("Invalid input", "Please enter a valid number."); } } -// List<Transform2D> transforms = new ArrayList<>(transformations); } else if (fractalData instanceof Pair) { Pair<String, String> userInput = (Pair<String, String>) fractalData; try { // Check if the input is a valid number diff --git a/src/main/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionFactory.java b/src/main/java/org/example/chaosgame/controller/ChaosGameDescriptionFactory.java similarity index 95% rename from src/main/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionFactory.java rename to src/main/java/org/example/chaosgame/controller/ChaosGameDescriptionFactory.java index 6b774ad..db3de3d 100644 --- a/src/main/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionFactory.java +++ b/src/main/java/org/example/chaosgame/controller/ChaosGameDescriptionFactory.java @@ -1,6 +1,8 @@ -package org.example.chaosgame.model.chaos; +package org.example.chaosgame.controller; import java.util.List; +import org.example.chaosgame.model.chaos.ChaosGameDescription; +import org.example.chaosgame.model.chaos.ChaosGameType; import org.example.chaosgame.model.linalg.Complex; import org.example.chaosgame.model.linalg.Matrix2x2; import org.example.chaosgame.model.linalg.Vector2D; diff --git a/src/main/java/org/example/chaosgame/model/chaos/ChaosGameFileHandler.java b/src/main/java/org/example/chaosgame/controller/ChaosGameFileHandler.java similarity index 98% rename from src/main/java/org/example/chaosgame/model/chaos/ChaosGameFileHandler.java rename to src/main/java/org/example/chaosgame/controller/ChaosGameFileHandler.java index 7b0256d..050be3f 100644 --- a/src/main/java/org/example/chaosgame/model/chaos/ChaosGameFileHandler.java +++ b/src/main/java/org/example/chaosgame/controller/ChaosGameFileHandler.java @@ -1,4 +1,4 @@ -package org.example.chaosgame.model.chaos; +package org.example.chaosgame.controller; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -7,6 +7,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.example.chaosgame.model.chaos.ChaosGameDescription; import org.example.chaosgame.model.linalg.Complex; import org.example.chaosgame.model.linalg.Matrix2x2; import org.example.chaosgame.model.linalg.Vector2D; diff --git a/src/main/java/org/example/chaosgame/controller/ExploreGameController.java b/src/main/java/org/example/chaosgame/controller/ExploreGameController.java index 4e6152e..b6ae5e8 100644 --- a/src/main/java/org/example/chaosgame/controller/ExploreGameController.java +++ b/src/main/java/org/example/chaosgame/controller/ExploreGameController.java @@ -103,7 +103,8 @@ public class ExploreGameController implements Observer, Subject, GameController Vector2D dragDistance = new Vector2D(event.getX(), canvas.getHeight() - event.getY()).subtract(dragStartTemp); Vector2D fractalRange = description.getMaxCoords().subtract(description.getMinCoords()); - Vector2D adjustedDragDistance = dragDistance.multiply(fractalRange).divide(new Vector2D(canvas.getWidth(), canvas.getHeight())); + Vector2D adjustedDragDistance = dragDistance.multiply(fractalRange) + .divide(new Vector2D(canvas.getWidth(), canvas.getHeight())); minCoords = description.getMinCoords().subtract(adjustedDragDistance); maxCoords = description.getMaxCoords().subtract(adjustedDragDistance); updateExplorePage(); @@ -118,54 +119,59 @@ public class ExploreGameController implements Observer, Subject, GameController */ public void zoomButtonClicked(double scaleFactor) { cumulativeScaleFactor *= scaleFactor; - Vector2D canvasCenter = chaosCanvas.transformIndicesToCoords(chaosCanvas.getWidth() / 2, chaosCanvas.getHeight() / 2); - minCoords = canvasCenter.subtract(canvasCenter.subtract(description.getMinCoords()).scale(scaleFactor)); - maxCoords = canvasCenter.add(description.getMaxCoords().subtract(canvasCenter).scale(scaleFactor)); + Vector2D canvasCenter = chaosCanvas.transformIndicesToCoords( + chaosCanvas.getWidth() / 2, chaosCanvas.getHeight() / 2); + minCoords = canvasCenter.subtract(canvasCenter.subtract( + description.getMinCoords()).scale(scaleFactor)); + maxCoords = canvasCenter.add(description.getMaxCoords() + .subtract(canvasCenter).scale(scaleFactor)); updateExplorePage(); } - /** - * Method for handling scroll events. - * Zooms in or out based on the scroll direction. - * - * @param event ScrollEvent - */ - public void onScroll (ScrollEvent event){ - double mouseX = event.getX(); - double mouseY = event.getY(); - double scaleBase = event.isControlDown() ? 2 : 1.1; - double scaleFactor = 1; - double zoomInLimit = Math.pow(10, -15); - double zoomOutLimit = 8; - if (event.getDeltaY() > 0 && cumulativeScaleFactor > zoomInLimit) { - // Zoom in - scaleFactor = 1 / scaleBase; - } else if (event.getDeltaY() < 0 && cumulativeScaleFactor < zoomOutLimit) { - // Zoom out - scaleFactor = scaleBase; - } + /** + * Method for handling scroll events. + * Zooms in or out based on the scroll direction. + * + * @param event ScrollEvent + */ + public void onScroll(ScrollEvent event) { + double mouseX = event.getX(); + double mouseY = event.getY(); + double scaleBase = event.isControlDown() ? 2 : 1.1; + double scaleFactor = 1; + double zoomInLimit = Math.pow(10, -15); + double zoomOutLimit = 8; + if (event.getDeltaY() > 0 && cumulativeScaleFactor > zoomInLimit) { + // Zoom in + scaleFactor = 1 / scaleBase; + } else if (event.getDeltaY() < 0 && cumulativeScaleFactor < zoomOutLimit) { + // Zoom out + scaleFactor = scaleBase; + } - cumulativeScaleFactor *= scaleFactor; - double middleMouseX = mouseX - (double) chaosCanvas.getWidth() / 2; - double middleMouseY = mouseY - (double) chaosCanvas.getHeight() / 2; - double translateX = canvas.getTranslateX(); - double translateY = canvas.getTranslateY(); - - canvas.setScaleX(canvas.getScaleX() * scaleFactor); - canvas.setScaleY(canvas.getScaleY() * scaleFactor); - - double newTranslateX = (middleMouseX - translateX) * (scaleFactor - 1); - double newTranslateY = (middleMouseY - translateY) * (scaleFactor - 1); - double setTranslateX = translateX - newTranslateX; - double setTranslateY = translateY - newTranslateY; - canvas.setTranslateX(setTranslateX); - canvas.setTranslateY(setTranslateY); - - Vector2D canvasCenter = chaosCanvas.transformIndicesToCoords((int) mouseX, (int) mouseY); - minCoords = canvasCenter.subtract(canvasCenter.subtract(description.getMinCoords()).scale(scaleFactor)); - maxCoords = canvasCenter.add(description.getMaxCoords().subtract(canvasCenter).scale(scaleFactor)); - updateExplorePage(); + cumulativeScaleFactor *= scaleFactor; + double middleMouseX = mouseX - (double) chaosCanvas.getWidth() / 2; + double middleMouseY = mouseY - (double) chaosCanvas.getHeight() / 2; + double translateX = canvas.getTranslateX(); + double translateY = canvas.getTranslateY(); + + canvas.setScaleX(canvas.getScaleX() * scaleFactor); + canvas.setScaleY(canvas.getScaleY() * scaleFactor); + + double newTranslateX = (middleMouseX - translateX) * (scaleFactor - 1); + double newTranslateY = (middleMouseY - translateY) * (scaleFactor - 1); + double setTranslateX = translateX - newTranslateX; + double setTranslateY = translateY - newTranslateY; + canvas.setTranslateX(setTranslateX); + canvas.setTranslateY(setTranslateY); + + Vector2D canvasCenter = chaosCanvas.transformIndicesToCoords((int) mouseX, (int) mouseY); + minCoords = canvasCenter.subtract(canvasCenter.subtract( + description.getMinCoords()).scale(scaleFactor)); + maxCoords = canvasCenter.add(description.getMaxCoords() + .subtract(canvasCenter).scale(scaleFactor)); + updateExplorePage(); } @@ -173,7 +179,8 @@ public class ExploreGameController implements Observer, Subject, GameController this.description.setMinCoords(minCoords); this.description.setMaxCoords(maxCoords); this.description.setTransforms(trans); - this.exploreGame = new ExploreGame(description, (int) canvas.getWidth(),(int) canvas.getHeight()); + this.exploreGame = new ExploreGame( + description, (int) canvas.getWidth(), (int) canvas.getHeight()); this.exploreGame.registerObserver(this); this.chaosCanvas = exploreGame.getCanvas(); exploreGame.exploreFractals(); @@ -248,7 +255,6 @@ public class ExploreGameController implements Observer, Subject, GameController ? value : exploreTransform.getComplex().getY(); trans = List.of(new ExploreJulia(new Complex(realPart, imaginaryPart))); -// description.setTransforms(trans); updateExplorePage(); } diff --git a/src/main/java/org/example/chaosgame/model/chaos/ChaosCanvas.java b/src/main/java/org/example/chaosgame/model/chaos/ChaosCanvas.java index 6d1892f..ed700b4 100644 --- a/src/main/java/org/example/chaosgame/model/chaos/ChaosCanvas.java +++ b/src/main/java/org/example/chaosgame/model/chaos/ChaosCanvas.java @@ -165,13 +165,22 @@ public class ChaosCanvas { * Clears the canvas by setting all pixel values to 0. */ public void clearCanvas() { - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - canvas[i][j] = 0; - } + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + canvas[i][j] = 0; } + } } + + /** + * Returns the pixel value at the given point. + * If the point is outside the canvas, the method returns 0. + * + * @param point The point to get the pixel value at + * + * @return The pixel value at the given point + */ public double getPixel(Vector2D point) { Vector2D indices = transformCoordsToIndices.transform(point); int x = (int) indices.getX(); diff --git a/src/main/java/org/example/chaosgame/model/chaos/ChaosGameDescription.java b/src/main/java/org/example/chaosgame/model/chaos/ChaosGameDescription.java index 87e1665..8c7177f 100644 --- a/src/main/java/org/example/chaosgame/model/chaos/ChaosGameDescription.java +++ b/src/main/java/org/example/chaosgame/model/chaos/ChaosGameDescription.java @@ -2,7 +2,6 @@ package org.example.chaosgame.model.chaos; import java.util.List; import java.util.Objects; - import org.example.chaosgame.model.linalg.Vector2D; import org.example.chaosgame.model.transformations.Transform2D; @@ -77,7 +76,8 @@ public class ChaosGameDescription { || maxCoords.getX() < -50 || maxCoords.getY() < -50) { throw new IllegalArgumentException("Coordinates must be between -50 and 50"); } else if (minCoords.getX() > maxCoords.getX() || minCoords.getY() > maxCoords.getY()) { - throw new IllegalArgumentException("Minimum coordinates must be less than maximum coordinates"); + throw new IllegalArgumentException( + "Minimum coordinates must be less than maximum coordinates"); } if (minCoords.equals(maxCoords)) { throw new IllegalArgumentException("Minimum and maximum coordinates cannot be the same"); @@ -90,7 +90,7 @@ public class ChaosGameDescription { * @param transforms List of transformations to apply to the points */ private void validateTransforms(List<Transform2D> transforms) { - if (transforms == null){ + if (transforms == null) { throw new IllegalArgumentException("Transformations cannot be null"); } if (transforms.size() > 4 || transforms.isEmpty()) { @@ -129,8 +129,12 @@ public class ChaosGameDescription { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } ChaosGameDescription that = (ChaosGameDescription) o; return Objects.equals(minCoords, that.minCoords) && Objects.equals(maxCoords, that.maxCoords) diff --git a/src/main/java/org/example/chaosgame/model/chaos/ExploreGame.java b/src/main/java/org/example/chaosgame/model/chaos/ExploreGame.java index 8e046e0..16aa2be 100644 --- a/src/main/java/org/example/chaosgame/model/chaos/ExploreGame.java +++ b/src/main/java/org/example/chaosgame/model/chaos/ExploreGame.java @@ -1,17 +1,5 @@ package org.example.chaosgame.model.chaos; - -import javafx.application.Platform; -import javafx.concurrent.Task; -import javafx.scene.canvas.Canvas; -import org.example.chaosgame.model.linalg.Vector2D; -import org.example.chaosgame.model.transformations.Transform2D; -import org.example.chaosgame.view.components.AlertUtility; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.IntStream; -import java.util.stream.Stream; import java.util.ArrayList; import java.util.List; import java.util.stream.IntStream; @@ -20,12 +8,13 @@ import org.example.chaosgame.controller.interfaces.Subject; import org.example.chaosgame.model.linalg.Vector2D; + /** * Class for exploring julia sets. */ public class ExploreGame implements Subject { private static final int MAX_ITER = 256; - private ChaosCanvas canvas; + private final ChaosCanvas canvas; private ChaosGameDescription description; private Vector2D currentPoint = new Vector2D(0.0, 0.0); private final List<Observer> gameObservers; @@ -41,15 +30,28 @@ public class ExploreGame implements Subject { */ public ExploreGame(ChaosGameDescription description, int width, int height) { this.description = description; - this.canvas = new ChaosCanvas(width, height, description.getMinCoords(), description.getMaxCoords()); + this.canvas = new ChaosCanvas( + width, height, + description.getMinCoords(), + description.getMaxCoords()); this.gameObservers = new ArrayList<>(); } + /** + * Method for setting the chaos game. + * + * @param description Description of the chaos game + * + * @param width Width of the canvas + * + * @param height Height of the canvas + */ public void setExploreGame(ChaosGameDescription description, int width, int height) { this.description = description; setChaosCanvas(description.getMinCoords(), description.getMaxCoords(), width, height); } + public ChaosCanvas getCanvas() { return canvas; } diff --git a/src/main/java/org/example/chaosgame/model/linalg/Matrix2x2.java b/src/main/java/org/example/chaosgame/model/linalg/Matrix2x2.java index f24922c..ea2b491 100644 --- a/src/main/java/org/example/chaosgame/model/linalg/Matrix2x2.java +++ b/src/main/java/org/example/chaosgame/model/linalg/Matrix2x2.java @@ -50,10 +50,17 @@ public record Matrix2x2(double a, double b, double c, double d) { */ @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Matrix2x2 matrix2x2 = (Matrix2x2) o; - return Double.compare(a, matrix2x2.a) == 0 && Double.compare(b, matrix2x2.b) == 0 && Double.compare(c, matrix2x2.c) == 0 && Double.compare(d, matrix2x2.d) == 0; + return Double.compare(a, matrix2x2.a) == 0 + && Double.compare(b, matrix2x2.b) == 0 + && Double.compare(c, matrix2x2.c) == 0 + && Double.compare(d, matrix2x2.d) == 0; } /** diff --git a/src/main/java/org/example/chaosgame/model/linalg/Vector2D.java b/src/main/java/org/example/chaosgame/model/linalg/Vector2D.java index daed340..c06683a 100644 --- a/src/main/java/org/example/chaosgame/model/linalg/Vector2D.java +++ b/src/main/java/org/example/chaosgame/model/linalg/Vector2D.java @@ -102,14 +102,34 @@ public class Vector2D { } + /** + * Equals method for Vector2D. + * Compares two vectors for equality. + * Overrides the default equals method. + * Generated by IntelliJ IDEA. + * + * @param o Object to compare + * @return true if the vectors are equal, false otherwise + */ @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Vector2D vector2D = (Vector2D) o; return Double.compare(x, vector2D.x) == 0 && Double.compare(y, vector2D.y) == 0; } + /** + * Hashcode method for Vector2D. + * Overrides the default hashcode method. + * Generated by IntelliJ IDEA. + * + * @return the hashcode of the vector + */ @Override public int hashCode() { return Objects.hash(x, y); diff --git a/src/main/java/org/example/chaosgame/model/transformations/AffineTransform2D.java b/src/main/java/org/example/chaosgame/model/transformations/AffineTransform2D.java index 50563f3..da0db14 100644 --- a/src/main/java/org/example/chaosgame/model/transformations/AffineTransform2D.java +++ b/src/main/java/org/example/chaosgame/model/transformations/AffineTransform2D.java @@ -1,9 +1,9 @@ package org.example.chaosgame.model.transformations; +import java.util.Objects; import org.example.chaosgame.model.linalg.Matrix2x2; import org.example.chaosgame.model.linalg.Vector2D; -import java.util.Objects; /** * Record for 2D affine transformations. @@ -46,8 +46,12 @@ public record AffineTransform2D(Matrix2x2 matrix, Vector2D vector) implements Tr */ @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } AffineTransform2D that = (AffineTransform2D) o; return Objects.equals(vector, that.vector) && Objects.equals(matrix, that.matrix); } diff --git a/src/main/java/org/example/chaosgame/model/transformations/JuliaTransform.java b/src/main/java/org/example/chaosgame/model/transformations/JuliaTransform.java index 44c940e..98119ed 100644 --- a/src/main/java/org/example/chaosgame/model/transformations/JuliaTransform.java +++ b/src/main/java/org/example/chaosgame/model/transformations/JuliaTransform.java @@ -1,10 +1,9 @@ package org.example.chaosgame.model.transformations; +import java.util.Objects; import org.example.chaosgame.model.linalg.Complex; import org.example.chaosgame.model.linalg.Vector2D; -import java.util.Objects; - /** * Class for the Julia transformation. * This formula describes the transformation: @@ -63,8 +62,12 @@ public class JuliaTransform implements Transform2D { */ @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } JuliaTransform that = (JuliaTransform) o; return sign == that.sign && Objects.equals(point, that.point); } diff --git a/src/test/java/org/example/chaosgame/controller/ChaosGameControllerTest.java b/src/test/java/org/example/chaosgame/controller/ChaosGameControllerTest.java index b880269..1e16946 100644 --- a/src/test/java/org/example/chaosgame/controller/ChaosGameControllerTest.java +++ b/src/test/java/org/example/chaosgame/controller/ChaosGameControllerTest.java @@ -2,71 +2,69 @@ package org.example.chaosgame.controller; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - class ChaosGameControllerTest { - @Test - void gameSelection() { - } - - @Test - void runStepsValidation() { - } - - @Test - void openFromFile() { - } - - @Test - void updateFractalColor() { - } - - @Test - void createOwnJuliaFractal() { - } - - @Test - void createOwnAffineFractal() { - } - - @Test - void updateJuliaValue() { - } - - @Test - void isJuliaShowing() { - } - - @Test - void saveFractal() { - } - - @Test - void homeButtonClicked() { - } - - @Test - void update() { - } - - @Test - void registerObserver() { - } - - @Test - void removeObserver() { - } - - @Test - void notifyObservers() { - } - - @Test - void setCanvas() { - } - - @Test - void setBind() { - } + @Test + void gameSelection() { + } + + @Test + void runStepsValidation() { + } + + @Test + void openFromFile() { + } + + @Test + void updateFractalColor() { + } + + @Test + void createOwnJuliaFractal() { + } + + @Test + void createOwnAffineFractal() { + } + + @Test + void updateJuliaValue() { + } + + @Test + void isJuliaShowing() { + } + + @Test + void saveFractal() { + } + + @Test + void homeButtonClicked() { + } + + @Test + void update() { + } + + @Test + void registerObserver() { + } + + @Test + void removeObserver() { + } + + @Test + void notifyObservers() { + } + + @Test + void setCanvas() { + } + + @Test + void setBind() { + } } \ No newline at end of file diff --git a/src/test/java/org/example/chaosgame/controller/ExploreGameControllerTest.java b/src/test/java/org/example/chaosgame/controller/ExploreGameControllerTest.java index e999b1b..05f43e0 100644 --- a/src/test/java/org/example/chaosgame/controller/ExploreGameControllerTest.java +++ b/src/test/java/org/example/chaosgame/controller/ExploreGameControllerTest.java @@ -2,71 +2,69 @@ package org.example.chaosgame.controller; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - class ExploreGameControllerTest { - @Test - void mousePressed() { - } + @Test + void mousePressed() { + } - @Test - void mouseDragged() { - } + @Test + void mouseDragged() { + } - @Test - void mouseReleased() { - } + @Test + void mouseReleased() { + } - @Test - void zoomButtonClicked() { - } + @Test + void zoomButtonClicked() { + } - @Test - void onScroll() { - } + @Test + void onScroll() { + } - @Test - void homeButtonClicked() { - } + @Test + void homeButtonClicked() { + } - @Test - void getExplorePage() { - } + @Test + void getExplorePage() { + } - @Test - void updateFractalColor() { - } + @Test + void updateFractalColor() { + } - @Test - void update() { - } + @Test + void update() { + } - @Test - void registerObserver() { - } + @Test + void registerObserver() { + } - @Test - void removeObserver() { - } + @Test + void removeObserver() { + } - @Test - void notifyObservers() { - } + @Test + void notifyObservers() { + } - @Test - void updateExploreGame() { - } + @Test + void updateExploreGame() { + } - @Test - void resetImage() { - } + @Test + void resetImage() { + } - @Test - void setCanvas() { - } + @Test + void setCanvas() { + } - @Test - void updateJuliaValue() { - } + @Test + void updateJuliaValue() { + } } \ No newline at end of file diff --git a/src/test/java/org/example/chaosgame/controller/HomeControllerTest.java b/src/test/java/org/example/chaosgame/controller/HomeControllerTest.java index 6822a15..c32f31a 100644 --- a/src/test/java/org/example/chaosgame/controller/HomeControllerTest.java +++ b/src/test/java/org/example/chaosgame/controller/HomeControllerTest.java @@ -2,15 +2,13 @@ package org.example.chaosgame.controller; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - class HomeControllerTest { - @Test - void getHomePage() { - } + @Test + void getHomePage() { + } - @Test - void mouseEvent() { - } + @Test + void mouseEvent() { + } } \ No newline at end of file diff --git a/src/test/java/org/example/chaosgame/controller/PageControllerTest.java b/src/test/java/org/example/chaosgame/controller/PageControllerTest.java index 79fca41..7cc833b 100644 --- a/src/test/java/org/example/chaosgame/controller/PageControllerTest.java +++ b/src/test/java/org/example/chaosgame/controller/PageControllerTest.java @@ -6,15 +6,15 @@ import static org.junit.jupiter.api.Assertions.*; class PageControllerTest { - @Test - void goToPage() { - } + @Test + void goToPage() { + } - @Test - void exitGame() { - } + @Test + void exitGame() { + } - @Test - void update() { - } + @Test + void update() { + } } \ No newline at end of file diff --git a/src/test/java/org/example/chaosgame/model/chaos/ChaosCanvasTest.java b/src/test/java/org/example/chaosgame/model/chaos/ChaosCanvasTest.java index f40039f..a55ef4c 100644 --- a/src/test/java/org/example/chaosgame/model/chaos/ChaosCanvasTest.java +++ b/src/test/java/org/example/chaosgame/model/chaos/ChaosCanvasTest.java @@ -2,7 +2,11 @@ package org.example.chaosgame.model.chaos; import org.example.chaosgame.model.linalg.Vector2D; import org.example.chaosgame.model.transformations.AffineTransform2D; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterEach; import static org.junit.jupiter.api.Assertions.*; @@ -33,7 +37,7 @@ class ChaosCanvasTest { @Test @DisplayName("Test positive getPixel") void getPixel() { - double pixel = chaosCanvas.getPixel(new Vector2D(0, 0)); + double pixel = chaosCanvas.getPixel(new Vector2D(0.5, 0.5)); assertEquals(0.0, pixel); } diff --git a/src/test/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionFactoryTest.java b/src/test/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionFactoryTest.java index 8cf558d..00e0ad8 100644 --- a/src/test/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionFactoryTest.java +++ b/src/test/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionFactoryTest.java @@ -1,15 +1,21 @@ package org.example.chaosgame.model.chaos; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.List; +import org.example.chaosgame.controller.ChaosGameDescriptionFactory; import org.example.chaosgame.model.linalg.Complex; import org.example.chaosgame.model.linalg.Matrix2x2; import org.example.chaosgame.model.linalg.Vector2D; import org.example.chaosgame.model.transformations.AffineTransform2D; import org.example.chaosgame.model.transformations.JuliaTransform; -import org.junit.jupiter.api.*; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; class ChaosGameDescriptionFactoryTest { private static ChaosGameDescription expectedJulia; @@ -81,19 +87,22 @@ class ChaosGameDescriptionFactoryTest { class SierpinskiTests { @Test void testSierpinskiNotNull() { - ChaosGameDescription sierpinskiResult = ChaosGameDescriptionFactory.get(ChaosGameType.SIERPINSKI); + ChaosGameDescription sierpinskiResult = + ChaosGameDescriptionFactory.get(ChaosGameType.SIERPINSKI); assertNotNull(sierpinskiResult); } @Test void testSierpinskiInstanceOf() { - ChaosGameDescription sierpinskiResult = ChaosGameDescriptionFactory.get(ChaosGameType.SIERPINSKI); + ChaosGameDescription sierpinskiResult = + ChaosGameDescriptionFactory.get(ChaosGameType.SIERPINSKI); assertInstanceOf(ChaosGameDescription.class, sierpinskiResult); } @Test void testSierpinskiEquals() { - ChaosGameDescription sierpinskiResult = ChaosGameDescriptionFactory.get(ChaosGameType.SIERPINSKI); + ChaosGameDescription sierpinskiResult = + ChaosGameDescriptionFactory.get(ChaosGameType.SIERPINSKI); assertEquals(expectedSierpinski, sierpinskiResult); } } @@ -102,7 +111,8 @@ class ChaosGameDescriptionFactoryTest { class BarnsleyTests { @Test void testBarnsleyNotNull() { - ChaosGameDescription barnsleyResult = ChaosGameDescriptionFactory.get(ChaosGameType.BARNSLEY); + ChaosGameDescription barnsleyResult = + ChaosGameDescriptionFactory.get(ChaosGameType.BARNSLEY); assertNotNull(barnsleyResult); } diff --git a/src/test/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionTest.java b/src/test/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionTest.java index 7720f3b..c85c23b 100644 --- a/src/test/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionTest.java +++ b/src/test/java/org/example/chaosgame/model/chaos/ChaosGameDescriptionTest.java @@ -1,16 +1,22 @@ package org.example.chaosgame.model.chaos; -import org.example.chaosgame.model.linalg.Matrix2x2; -import org.example.chaosgame.model.linalg.Vector2D; -import org.example.chaosgame.model.transformations.Transform2D; -import org.example.chaosgame.model.transformations.AffineTransform2D; -import org.junit.jupiter.api.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Arrays; import java.util.List; -import java.util.Vector; - -import static org.junit.jupiter.api.Assertions.*; +import org.example.chaosgame.model.linalg.Matrix2x2; +import org.example.chaosgame.model.linalg.Vector2D; +import org.example.chaosgame.model.transformations.AffineTransform2D; +import org.example.chaosgame.model.transformations.Transform2D; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; class ChaosGameDescriptionTest { private ChaosGameDescription chaosGameDescription; @@ -32,9 +38,11 @@ class ChaosGameDescriptionTest { vectorPartA = new Vector2D(0.0, 0.0); matrixB = new Matrix2x2(0.5, 0.0, 0.0, 0.5); vectorPartB = new Vector2D(0.25, 0.50); - transforms = Arrays.asList(new AffineTransform2D(matrixA, vectorPartA), new AffineTransform2D(matrixB, vectorPartB)); + transforms = Arrays.asList(new AffineTransform2D(matrixA, vectorPartA), + new AffineTransform2D(matrixB, vectorPartB)); probabilities = Arrays.asList(50, 50); - chaosGameDescription = new ChaosGameDescription(minCoords, maxCoords, transforms, probabilities); + chaosGameDescription = new ChaosGameDescription( + minCoords, maxCoords, transforms, probabilities); } @AfterEach @@ -78,7 +86,8 @@ class ChaosGameDescriptionTest { @Test @DisplayName("Set empty transforms") void testSetEmptyTransforms() { - assertThrows(IllegalArgumentException.class, () -> chaosGameDescription.setTransforms(List.of())); + assertThrows(IllegalArgumentException.class, + () -> chaosGameDescription.setTransforms(List.of())); } @Test @@ -91,7 +100,8 @@ class ChaosGameDescriptionTest { new AffineTransform2D(matrixB, vectorPartB), new AffineTransform2D(matrixA, vectorPartA) ); - assertThrows(IllegalArgumentException.class, () -> chaosGameDescription.setTransforms(tooManyTransforms)); + assertThrows(IllegalArgumentException.class, + () -> chaosGameDescription.setTransforms(tooManyTransforms)); } @Test @@ -99,7 +109,7 @@ class ChaosGameDescriptionTest { void testSetValidTransforms() { Matrix2x2 newMatrix = new Matrix2x2(9.9, 9.9, 9.9, 9.9); Vector2D newVector = new Vector2D(9.9, 9.9); - List<Transform2D> newTransforms = Arrays.asList(new AffineTransform2D(newMatrix, newVector)); + List<Transform2D> newTransforms = List.of(new AffineTransform2D(newMatrix, newVector)); chaosGameDescription.setTransforms(newTransforms); assertEquals(newTransforms, chaosGameDescription.getTransforms()); } @@ -129,25 +139,36 @@ class ChaosGameDescriptionTest { void testSetMinAndMaxCoords() { Vector2D newMinCoords = new Vector2D(-99, -99); - assertThrows(IllegalArgumentException.class, () -> new ChaosGameDescription(newMinCoords, maxCoords, transforms, probabilities)); - assertThrows(IllegalArgumentException.class, () -> new ChaosGameDescription(maxCoords, minCoords, transforms, probabilities)); - assertThrows(IllegalArgumentException.class, () -> new ChaosGameDescription(minCoords, minCoords, transforms, probabilities)); + assertThrows(IllegalArgumentException.class, + () -> new ChaosGameDescription(newMinCoords, maxCoords, transforms, probabilities)); + assertThrows(IllegalArgumentException.class, + () -> new ChaosGameDescription(maxCoords, minCoords, transforms, probabilities)); + assertThrows(IllegalArgumentException.class, + () -> new ChaosGameDescription(minCoords, minCoords, transforms, probabilities)); } } @Test void testEquals() { - ChaosGameDescription sameChaosGameDescription = new ChaosGameDescription(minCoords, maxCoords, transforms, probabilities); + ChaosGameDescription sameChaosGameDescription = + new ChaosGameDescription(minCoords, maxCoords, transforms, probabilities); assertEquals(chaosGameDescription, sameChaosGameDescription); assertNotNull(chaosGameDescription); assertNotEquals(chaosGameDescription, new Object()); - ChaosGameDescription differentChaosGameDescription = new ChaosGameDescription(new Vector2D(1, 1), new Vector2D(2, 2), transforms, probabilities); + ChaosGameDescription differentChaosGameDescription = + new ChaosGameDescription( + new Vector2D(1, 1), + new Vector2D(2, 2), + transforms, probabilities); assertNotEquals(chaosGameDescription, differentChaosGameDescription); } @Test void testHashCode() { - ChaosGameDescription sameChaosGameDescription = new ChaosGameDescription(minCoords, maxCoords, transforms, probabilities); + ChaosGameDescription sameChaosGameDescription + = new ChaosGameDescription( + minCoords, maxCoords, + transforms, probabilities); assertEquals(chaosGameDescription.hashCode(), sameChaosGameDescription.hashCode()); } } diff --git a/src/test/java/org/example/chaosgame/model/chaos/ChaosGameFileHandlerTest.java b/src/test/java/org/example/chaosgame/model/chaos/ChaosGameFileHandlerTest.java index 84bcf44..32c0fa2 100644 --- a/src/test/java/org/example/chaosgame/model/chaos/ChaosGameFileHandlerTest.java +++ b/src/test/java/org/example/chaosgame/model/chaos/ChaosGameFileHandlerTest.java @@ -1,12 +1,8 @@ package org.example.chaosgame.model.chaos; -import org.example.chaosgame.model.linalg.Complex; -import org.example.chaosgame.model.linalg.Matrix2x2; -import org.example.chaosgame.model.linalg.Vector2D; -import org.example.chaosgame.model.transformations.AffineTransform2D; -import org.example.chaosgame.model.transformations.JuliaTransform; -import org.example.chaosgame.model.transformations.Transform2D; -import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -14,8 +10,21 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; +import org.example.chaosgame.controller.ChaosGameFileHandler; +import org.example.chaosgame.model.linalg.Complex; +import org.example.chaosgame.model.linalg.Matrix2x2; +import org.example.chaosgame.model.linalg.Vector2D; +import org.example.chaosgame.model.transformations.AffineTransform2D; +import org.example.chaosgame.model.transformations.JuliaTransform; +import org.example.chaosgame.model.transformations.Transform2D; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + + + -import static org.junit.jupiter.api.Assertions.*; class ChaosGameFileHandlerTest { private static ChaosGameFileHandler fileHandler; @@ -67,7 +76,7 @@ class ChaosGameFileHandlerTest { } private Path createTempFileWithContent(String content) throws IOException { - Path tempFile = Files.createTempFile("chaosgame", ".txt"); + Path tempFile = Files.createTempFile("chaosGame", ".txt"); try (BufferedWriter writer = Files.newBufferedWriter(tempFile)) { writer.write(content); } @@ -118,7 +127,8 @@ class ChaosGameFileHandlerTest { @Test void testReadUnknownType() throws IOException { Path tempFile = createTempFileWithContent(invalidTypeContent); - assertThrows(IllegalArgumentException.class, () -> fileHandler.readFromFile(tempFile.toString()), + assertThrows(IllegalArgumentException.class, + () -> fileHandler.readFromFile(tempFile.toString()), "Unknown type of transformation should throw IllegalArgumentException"); Files.delete(tempFile); @@ -142,24 +152,30 @@ class ChaosGameFileHandlerTest { new Vector2D(-2.65, 0.0), new Vector2D(2.65, 10.0), List.of( - new AffineTransform2D(new Matrix2x2(0.0, 0.0, 0.0, 0.16), new Vector2D(0.0, 0.0)), - new AffineTransform2D(new Matrix2x2(0.85, 0.04, -0.04, 0.85), new Vector2D(0.0, 1.6)), - new AffineTransform2D(new Matrix2x2(0.2, -0.26, 0.23, 0.22), new Vector2D(0.0, 1.6)), - new AffineTransform2D(new Matrix2x2(-0.15, 0.28, 0.26, 0.24), new Vector2D(0.0, 0.44)) + new AffineTransform2D(new Matrix2x2(0.0, 0.0, 0.0, 0.16), + new Vector2D(0.0, 0.0)), + new AffineTransform2D(new Matrix2x2(0.85, 0.04, -0.04, 0.85), + new Vector2D(0.0, 1.6)), + new AffineTransform2D(new Matrix2x2(0.2, -0.26, 0.23, 0.22), + new Vector2D(0.0, 1.6)), + new AffineTransform2D(new Matrix2x2(-0.15, 0.28, 0.26, 0.24), + new Vector2D(0.0, 0.44)) ) ); - Path tempFile = Files.createTempFile("chaosgame", ".txt"); + Path tempFile = Files.createTempFile("chaosGame", ".txt"); fileHandler.writeToFile(description, tempFile.toString()); String expectedContent = - "Affine2D # Type of transformation\n" + - "-2.65, 0.0 # Min-coordinate\n" + - "2.65, 10.0 # Max-coordinate\n" + - "0.0, 0.0, 0.0, 0.16, 0.0, 0.0 # 1 transformation\n" + - "0.85, 0.04, -0.04, 0.85, 0.0, 1.6 # 2 transformation\n" + - "0.2, -0.26, 0.23, 0.22, 0.0, 1.6 # 3 transformation\n" + - "-0.15, 0.28, 0.26, 0.24, 0.0, 0.44 # 4 transformation\n"; + """ + Affine2D # Type of transformation + -2.65, 0.0 # Min-coordinate + 2.65, 10.0 # Max-coordinate + 0.0, 0.0, 0.0, 0.16, 0.0, 0.0 # 1 transformation + 0.85, 0.04, -0.04, 0.85, 0.0, 1.6 # 2 transformation + 0.2, -0.26, 0.23, 0.22, 0.0, 1.6 # 3 transformation + -0.15, 0.28, 0.26, 0.24, 0.0, 0.44 # 4 transformation + """; StringBuilder actualContent = new StringBuilder(); try (BufferedReader reader = Files.newBufferedReader(tempFile)) { @@ -182,14 +198,16 @@ class ChaosGameFileHandlerTest { List.of(new JuliaTransform(new Complex(-0.70176, -0.3842), 1)) ); - Path tempFile = Files.createTempFile("chaosgame", ".txt"); + Path tempFile = Files.createTempFile("chaosGame", ".txt"); fileHandler.writeToFile(description, tempFile.toString()); String expectedContent = - "Julia # Type of transformation\n" + - "-1.6, -1.0 # Min-coordinate\n" + - "1.6, 1.0 # Max-coordinate\n" + - "-0.70176, -0.3842 # Real and imaginary part of the complex number\n"; + """ + Julia # Type of transformation + -1.6, -1.0 # Min-coordinate + 1.6, 1.0 # Max-coordinate + -0.70176, -0.3842 # Real and imaginary part of the complex number + """; StringBuilder actualContent = new StringBuilder(); try (BufferedReader reader = Files.newBufferedReader(tempFile)) { diff --git a/src/test/java/org/example/chaosgame/model/chaos/ChaosGameTest.java b/src/test/java/org/example/chaosgame/model/chaos/ChaosGameTest.java index 0c01145..5d967a7 100644 --- a/src/test/java/org/example/chaosgame/model/chaos/ChaosGameTest.java +++ b/src/test/java/org/example/chaosgame/model/chaos/ChaosGameTest.java @@ -1,16 +1,22 @@ package org.example.chaosgame.model.chaos; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.List; import org.example.chaosgame.controller.interfaces.Observer; import org.example.chaosgame.model.linalg.Complex; import org.example.chaosgame.model.linalg.Matrix2x2; import org.example.chaosgame.model.linalg.Vector2D; import org.example.chaosgame.model.transformations.AffineTransform2D; import org.example.chaosgame.model.transformations.JuliaTransform; -import org.junit.jupiter.api.*; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; class ChaosGameTest { private static ChaosGameDescription juliaDescription; @@ -61,7 +67,7 @@ class ChaosGameTest { @Nested - class gettersTest { + class GetterTests { @Test void getCanvas() { assertNotNull(instance.getCanvas(), "The canvas should not be null"); @@ -69,7 +75,9 @@ class ChaosGameTest { @Test void getDescription() { - assertEquals(juliaDescription, instance.getDescription(), "The description should be the same"); + assertEquals(juliaDescription, + instance.getDescription(), + "The description should be the same"); } @Test @@ -153,14 +161,18 @@ class ChaosGameTest { } @Nested - class setDescription { + class SetDescription { @Test void setChaosGameDescription() { instance.setChaosGameDescription(affineDescriptionWithProb); - assertEquals(affineDescriptionWithProb, instance.getDescription(), "The description should be the same"); - assertEquals(0, instance.getTotalSteps(), "The total steps should be 0"); - assertEquals(500, instance.getCanvas().getWidth(), "The width should be 500"); - assertEquals(500, instance.getCanvas().getHeight(), "The height should be 500"); + assertEquals(affineDescriptionWithProb, instance.getDescription(), + "The description should be the same"); + assertEquals(0, instance.getTotalSteps(), + "The total steps should be 0"); + assertEquals(500, instance.getCanvas().getWidth(), + "The width should be 500"); + assertEquals(500, instance.getCanvas().getHeight(), + "The height should be 500"); } @Test @@ -173,8 +185,12 @@ class ChaosGameTest { @Test void setChaosCanvas() { instance.setChaosCanvas(new Vector2D(-1.6, -1), new Vector2D(1.6, 1)); - assertEquals(new Vector2D(-1.6, -1), instance.getDescription().getMinCoords(), "The min coords should be the same"); - assertEquals(new Vector2D(1.6, 1), instance.getDescription().getMaxCoords(), "The max coords should be the same"); + assertEquals(new Vector2D(-1.6, -1), + instance.getDescription().getMinCoords(), + "The min coords should be the same"); + assertEquals(new Vector2D(1.6, 1), + instance.getDescription().getMaxCoords(), + "The max coords should be the same"); } @Test 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 00df098..ab56bbb 100644 --- a/src/test/java/org/example/chaosgame/model/chaos/ExploreGameTest.java +++ b/src/test/java/org/example/chaosgame/model/chaos/ExploreGameTest.java @@ -11,7 +11,6 @@ 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; -- GitLab