From 0fff625f4985a6a24ec6fb84b564f818a5fc2728 Mon Sep 17 00:00:00 2001
From: vetlesho <vetlesho@stud.ntnu.no>
Date: Mon, 20 May 2024 11:50:35 +0200
Subject: [PATCH] Fixed error in one chaosgame-testmethod.

---
 .../chaosgame/model/chaos/ChaosGame.java      |  9 +++--
 .../chaosgame/model/chaos/ChaosGameTest.java  | 33 +++++++------------
 2 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/example/chaosgame/model/chaos/ChaosGame.java b/src/main/java/org/example/chaosgame/model/chaos/ChaosGame.java
index 57867b0..2b461a6 100644
--- a/src/main/java/org/example/chaosgame/model/chaos/ChaosGame.java
+++ b/src/main/java/org/example/chaosgame/model/chaos/ChaosGame.java
@@ -143,8 +143,9 @@ public class ChaosGame implements Subject {
 
 
   /**
-   * Method for running the chaos game. Randomly selects a transformation
-   * from the description and applies it to the current point.
+   * Method for running the chaos game.
+   * Selects which runSteps method to use based if it has a list of probabilities.
+   * Notifies observers after running the steps.
    */
   public void runSteps() {
     if (description.getProbabilities() != null) {
@@ -155,6 +156,10 @@ public class ChaosGame implements Subject {
     notifyObservers();
   }
 
+  /**
+   * Method for running the chaos game. Randomly selects a transformation
+   * from the description and applies it to the current point.
+   */
   private void runStepsUniform(int steps) {
     for (int i = 0; i < steps; i++) {
       int transformIndex = random.nextInt(description.getTransforms().size());
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 2b35732..c6ec2d4 100644
--- a/src/test/java/org/example/chaosgame/model/chaos/ChaosGameTest.java
+++ b/src/test/java/org/example/chaosgame/model/chaos/ChaosGameTest.java
@@ -42,6 +42,8 @@ class ChaosGameTest {
   @BeforeEach
   void init() {
     instance = ChaosGame.getInstance(juliaDescription, 500, 500);
+    instance.setSteps(0);
+    instance.setTotalSteps(0);
   }
 
   @Nested
@@ -119,37 +121,23 @@ class ChaosGameTest {
     @Test
     void addTotalSteps() {
       instance.addTotalSteps(10);
-      assertEquals(10, instance.getTotalSteps(), "The total steps should be 10");
+      instance.addTotalSteps(10);
+      assertEquals(20, instance.getTotalSteps(), "The total steps should be 10");
     }
 
-
-
     @Test
     void resetTotalSteps() {
       instance.addTotalSteps(10);
       instance.resetTotalSteps();
       assertEquals(0, instance.getTotalSteps(), "The total steps should be 0");
     }
-  }
-
-  @Test
-  void setSteps() {
-  }
-
-  @Test
-  void setTotalSteps() {
-  }
 
-  @Test
-  void addTotalSteps() {
-  }
-
-  @Test
-  void resetTotalSteps() {
-  }
-
-  @Test
-  void runSteps() {
+    @Test
+    void runSteps() {
+      instance.setSteps(10);
+      instance.runSteps();
+      assertEquals(10, instance.getSteps(), "The total steps should be 10");
+    }
   }
 
   @Test
@@ -159,4 +147,5 @@ class ChaosGameTest {
   @Test
   void setChaosCanvas() {
   }
+
 }
\ No newline at end of file
-- 
GitLab