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

Merge branch 'unit-test' of gitlab.stud.idi.ntnu.no:idatt2003-19/chaosgame into unit-test

parents 8d001a2d 0fff625f
No related branches found
No related tags found
1 merge request!20Created test classes for Factory and FileReader. Created equals methods
Pipeline #288054 passed
...@@ -143,8 +143,9 @@ public class ChaosGame implements Subject { ...@@ -143,8 +143,9 @@ public class ChaosGame implements Subject {
/** /**
* Method for running the chaos game. Randomly selects a transformation * Method for running the chaos game.
* from the description and applies it to the current point. * Selects which runSteps method to use based if it has a list of probabilities.
* Notifies observers after running the steps.
*/ */
public void runSteps() { public void runSteps() {
if (description.getProbabilities() != null) { if (description.getProbabilities() != null) {
...@@ -155,6 +156,10 @@ public class ChaosGame implements Subject { ...@@ -155,6 +156,10 @@ public class ChaosGame implements Subject {
notifyObservers(); 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) { private void runStepsUniform(int steps) {
for (int i = 0; i < steps; i++) { for (int i = 0; i < steps; i++) {
int transformIndex = random.nextInt(description.getTransforms().size()); int transformIndex = random.nextInt(description.getTransforms().size());
......
...@@ -42,6 +42,8 @@ class ChaosGameTest { ...@@ -42,6 +42,8 @@ class ChaosGameTest {
@BeforeEach @BeforeEach
void init() { void init() {
instance = ChaosGame.getInstance(juliaDescription, 500, 500); instance = ChaosGame.getInstance(juliaDescription, 500, 500);
instance.setSteps(0);
instance.setTotalSteps(0);
} }
@Nested @Nested
...@@ -119,37 +121,23 @@ class ChaosGameTest { ...@@ -119,37 +121,23 @@ class ChaosGameTest {
@Test @Test
void addTotalSteps() { void addTotalSteps() {
instance.addTotalSteps(10); 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 @Test
void resetTotalSteps() { void resetTotalSteps() {
instance.addTotalSteps(10); instance.addTotalSteps(10);
instance.resetTotalSteps(); instance.resetTotalSteps();
assertEquals(0, instance.getTotalSteps(), "The total steps should be 0"); assertEquals(0, instance.getTotalSteps(), "The total steps should be 0");
} }
}
@Test
void setSteps() {
}
@Test
void setTotalSteps() {
}
@Test @Test
void addTotalSteps() { void runSteps() {
} instance.setSteps(10);
instance.runSteps();
@Test assertEquals(10, instance.getSteps(), "The total steps should be 10");
void resetTotalSteps() { }
}
@Test
void runSteps() {
} }
@Test @Test
...@@ -159,4 +147,5 @@ class ChaosGameTest { ...@@ -159,4 +147,5 @@ class ChaosGameTest {
@Test @Test
void setChaosCanvas() { void setChaosCanvas() {
} }
} }
\ 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