Skip to content
Snippets Groups Projects
Commit cec5c3df authored by Nicklas Persia Tufteland's avatar Nicklas Persia Tufteland
Browse files

Merge branch '31-add-more-tests-to-improve-coverage' into 'dev'

Resolve "Add more tests to improve coverage"

Closes #31

See merge request !36
parents dff869bd 09736716
Branches master
No related tags found
2 merge requests!41final delivery,!36Resolve "Add more tests to improve coverage"
Pipeline #288596 failed
package edu.ntnu.idatt2003.model;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
......@@ -31,7 +32,7 @@ public class AffineTransform2dTest {
*/
@Nested
@DisplayName("Positive tests")
public class PositiveTests {
class PositiveTests {
/**
* Tests the transform method of AffineTransform2D.
......@@ -46,5 +47,35 @@ public class AffineTransform2dTest {
assertEquals(9, v3.getX0());
assertEquals(18, v3.getX1());
}
/**
* Tests the getMatrixCoordsList method of AffineTransform2D.
* Verifies that the matrix coordinates are correctly retrieved.
*/
@Test
@DisplayName("getMatrixCoordsListTestAffine")
void testGetMatrixCoordsList() {
AffineTransform2D transform = new AffineTransform2D(a1, b1);
double[] matrixCoords = transform.getMatrixCoordsList();
assertEquals(2, matrixCoords[0]);
assertEquals(2, matrixCoords[1]);
assertEquals(4, matrixCoords[2]);
assertEquals(5, matrixCoords[3]);
}
/**
* Tests the getVectorCoordsList method of AffineTransform2D.
* Verifies that the vector coordinates are correctly retrieved.
*/
@Test
@DisplayName("getVectorCoordsListTestAffine")
void testGetVectorCoordsList() {
AffineTransform2D transform = new AffineTransform2D(a1, b1);
double[] vectorCoords = transform.getVectorCoordsList();
assertEquals(3, vectorCoords[0]);
assertEquals(4, vectorCoords[1]);
}
}
}
......@@ -5,6 +5,7 @@ import org.junit.jupiter.api.*;
import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.InputMismatchException;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
......@@ -133,5 +134,25 @@ class ChaosGameFileHandlerTest {
void testReadChaosGameDescriptionWithNonExistingFile() {
assertThrows(FileNotFoundException.class, () -> fileHandler.readFromFile("non-existing-file.txt"));
}
/**
* Test reading from a file with an unknown transformation type.
* Verifies that an IllegalArgumentException is thrown.
*/
@Test
@DisplayName("Test readChaosGameDescription with unknown transformation type")
void testReadChaosGameDescriptionWithUnknownTransformationType() {
assertThrows(IllegalArgumentException.class, () -> fileHandler.readFromFile("src/test/resources/invalidNameExample.txt"));
}
/**
* Tests reading from a file with an invalid number of arguments.
* Verifies that an IllegalArgumentException is thrown.
*/
@Test
@DisplayName("Test readChaosGameDescription with invalid number of arguments")
void testReadChaosGameDescriptionWithInvalidNumberOfArguments() {
assertThrows(InputMismatchException.class, () -> fileHandler.readFromFile("src/test/resources/invalidFormatExample.txt"));
}
}
}
package edu.ntnu.idatt2003.model;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
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 static org.junit.jupiter.api.Assertions.*;
/**
* Test class for ChaosGame, covering both positive and negative test cases.
......@@ -22,10 +28,20 @@ public class ChaosGameTest {
@BeforeEach
public void setUp() {
AffineTransform2D transform1 = new AffineTransform2D(new Matrix2x2(1, 0, 0, 1), new Vector2d(1, 1));
AffineTransform2D transform2 = new AffineTransform2D(new Matrix2x2(1, 0, 0, 1), new Vector2d(-1, -1));
description = new ChaosGameDescription(new Vector2d(0, 0), new Vector2d(10, 10), Arrays.asList(transform1, transform2));
AffineTransform2D transform1 = new AffineTransform2D(
new Matrix2x2(1, 0, 0, 1),
new Vector2d(1, 1)
);
AffineTransform2D transform2 = new AffineTransform2D(
new Matrix2x2(1, 0, 0, 1),
new Vector2d(-1, -1)
);
description = new ChaosGameDescription(
new Vector2d(0, 0),
new Vector2d(10, 10),
Arrays.asList(transform1, transform2)
);
chaosGame = new ChaosGame(description, 10, 10);
......@@ -46,7 +62,7 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Constructor Test")
public void testConstructor() {
void testConstructor() {
assertNotNull(chaosGame);
assertEquals(10, chaosGame.getCanvas().getWidth());
assertEquals(10, chaosGame.getCanvas().getHeight());
......@@ -58,17 +74,71 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Get Canvas Test")
public void testGetCanvas() {
void testGetCanvas() {
assertNotNull(chaosGame.getCanvas());
}
/**
* Tests the getMinCoordsList() method of ChaosGame.
* Verifies that the list of MinCoords is correct.
*/
@Test
@DisplayName("Get Min Coords List Test")
void testGetMinCoordsList() {
double[] minCoords = chaosGame.getMinCoordsList();
assertEquals(0, minCoords[0]);
assertEquals(0, minCoords[1]);
}
/**
* Tests the getMaxCoordsList() method of ChaosGame.
* Verifies that the list of MaxCoords is correct.
*/
@Test
@DisplayName("Get Max Coords List Test")
void testGetMaxCoordsList() {
double[] maxCoords = chaosGame.getMaxCoordsList();
assertEquals(10, maxCoords[0]);
assertEquals(10, maxCoords[1]);
}
/**
* Tests the getTransformList() method of ChaosGame.
* Verifies that the list of transformations is correct.
*/
@Test
@DisplayName("Get Transform List Test")
void testGetTransformList() {
assertEquals(description.getTransform(), chaosGame.getTransformList());
}
/**
* Tests the getDescriptionName() method of ChaosGame.
* Verifies that the description name is correct.
*/
@Test
@DisplayName("Get Description Name Test")
void testGetDescriptionName() {
assertEquals("", chaosGame.getDescriptionName());
}
/**
* Tests the getTotalSteps() method of ChaosGame.
* Verifies that the total steps are initially zero.
*/
@Test
@DisplayName("Get Total Steps Test")
public void testGetTotalSteps() {
void testGetTotalSteps() {
assertEquals(0, chaosGame.getTotalSteps());
}
/**
* Test the runSteps() method of ChaosGame, sets totalSteps to 0.
*/
@Test
@DisplayName("Run Steps negative number Test")
void testRunStepsNegative() {
chaosGame.runStepsAndUpdateTotal(-1);
assertEquals(0, chaosGame.getTotalSteps());
}
......@@ -78,18 +148,19 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Run Steps and Update Total Test")
public void testRunStepsAndUpdateTotal() {
void testRunStepsAndUpdateTotal() {
chaosGame.runStepsAndUpdateTotal(5);
assertEquals(5, chaosGame.getTotalSteps());
}
/**
* Tests running steps without updating the total steps.
* Verifies that the total steps remain unchanged.
*/
@Test
@DisplayName("Run Steps without Updating Total Test")
public void testRunStepsWithoutUpdatingTotal() {
void testRunStepsWithoutUpdatingTotal() {
chaosGame.runStepsWithoutUpdatingTotal(5);
assertEquals(0, chaosGame.getTotalSteps());
}
......@@ -100,14 +171,25 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Change Transformation Test")
public void testChangeTransformation() {
AffineTransform2D newTransform1 = new AffineTransform2D(new Matrix2x2(1, 0, 0, 1), new Vector2d(2, 2));
AffineTransform2D newTransform2 = new AffineTransform2D(new Matrix2x2(1, 0, 0, 1), new Vector2d(-2, -2));
ChaosGameDescription newDescription = new ChaosGameDescription(new Vector2d(0, 0), new Vector2d(10, 10), Arrays.asList(newTransform1, newTransform2));
chaosGame.changeCustomTransformation(newDescription);
void testChangeTransformation() {
AffineTransform2D newTransform1 = new AffineTransform2D(
new Matrix2x2(1, 0, 0, 1),
new Vector2d(2, 2)
);
AffineTransform2D newTransform2 = new AffineTransform2D(
new Matrix2x2(1, 0, 0, 1),
new Vector2d(-2, -2)
);
ChaosGameDescription newDescription = new ChaosGameDescription(
new Vector2d(0, 0),
new Vector2d(10, 10),
Arrays.asList(newTransform1, newTransform2)
);
chaosGame.changeTransformation(newDescription, "affine");
assertEquals(newDescription, chaosGame.getDescription());
assertEquals("affine", chaosGame.getDescriptionName());
}
/**
......@@ -116,14 +198,25 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Change Custom Transformation Test")
public void testChangeCustomTransformation() {
AffineTransform2D customTransform1 = new AffineTransform2D(new Matrix2x2(1, 0, 0, 1), new Vector2d(3, 3));
AffineTransform2D customTransform2 = new AffineTransform2D(new Matrix2x2(1, 0, 0, 1), new Vector2d(-3, -3));
ChaosGameDescription customDescription = new ChaosGameDescription(new Vector2d(0, 0), new Vector2d(10, 10), Arrays.asList(customTransform1, customTransform2));
chaosGame.changeCustomTransformation(customDescription);
void testChangeCustomTransformation() {
AffineTransform2D customTransform1 = new AffineTransform2D(
new Matrix2x2(1, 0, 0, 1),
new Vector2d(3, 3)
);
AffineTransform2D customTransform2 = new AffineTransform2D(
new Matrix2x2(1, 0, 0, 1),
new Vector2d(-3, -3)
);
ChaosGameDescription customDescription = new ChaosGameDescription(
new Vector2d(0, 0),
new Vector2d(10, 10),
Arrays.asList(customTransform1, customTransform2)
);
chaosGame.changeTransformation(customDescription, "affine");
assertEquals(customDescription, chaosGame.getDescription());
assertEquals("affine", chaosGame.getDescriptionName());
}
/**
......@@ -132,10 +225,20 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Set Description Test")
public void testSetDescription() {
AffineTransform2D newTransform1 = new AffineTransform2D(new Matrix2x2(1, 0, 0, 1), new Vector2d(4, 4));
AffineTransform2D newTransform2 = new AffineTransform2D(new Matrix2x2(1, 0, 0, 1), new Vector2d(-4, -4));
ChaosGameDescription newDescription = new ChaosGameDescription(new Vector2d(0, 0), new Vector2d(10, 10), Arrays.asList(newTransform1, newTransform2));
void testSetDescription() {
AffineTransform2D newTransform1 = new AffineTransform2D(
new Matrix2x2(1, 0, 0, 1),
new Vector2d(4, 4)
);
AffineTransform2D newTransform2 = new AffineTransform2D(
new Matrix2x2(1, 0, 0, 1),
new Vector2d(-4, -4)
);
ChaosGameDescription newDescription = new ChaosGameDescription(
new Vector2d(0, 0),
new Vector2d(10, 10),
Arrays.asList(newTransform1, newTransform2)
);
chaosGame.setDescription(newDescription);
......@@ -148,7 +251,7 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Get Description Test")
public void testGetDescription() {
void testGetDescription() {
assertEquals(description, chaosGame.getDescription());
}
......@@ -158,7 +261,7 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Register Observer Test")
public void testRegisterObserver() {
void testRegisterObserver() {
TestObserver newObserver = new TestObserver();
chaosGame.registerObserver(newObserver);
chaosGame.notifyObservers();
......@@ -171,7 +274,7 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Notify Observers Test")
public void testNotifyObservers() {
void testNotifyObservers() {
chaosGame.notifyObservers();
assertTrue(observer.isUpdated());
}
......@@ -190,7 +293,7 @@ public class ChaosGameTest {
*/
@Test
@DisplayName("Remove Observer Test")
public void testRemoveObserver() {
void testRemoveObserver() {
chaosGame.removeObserver(observer);
chaosGame.notifyObservers();
assertFalse(observer.isUpdated());
......
......@@ -2,6 +2,7 @@ package edu.ntnu.idatt2003.model;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
......@@ -10,6 +11,13 @@ import org.junit.jupiter.api.Test;
* Test class for JuliaTransform, covering positive test cases.
*/
class JuliaTransformTest {
private static JuliaTransform jt;
@BeforeAll
static void setUp() {
Complex point = new Complex(1, 2);
jt = new JuliaTransform(point, 1);
}
/**
* Positive test cases for JuliaTransform.
*/
......@@ -17,6 +25,17 @@ class JuliaTransformTest {
@DisplayName("Positive tests")
class PositiveTests {
/**
* Tests the getPointAsList of JuliaTransform.
* Verifies that the point is correctly returned as a list.
*/
@Test
@DisplayName("Test getPointAsList")
void testGetPointAsList() {
double[] point = jt.getPointAsList();
assertEquals(1, point[0]);
assertEquals(2, point[1]);
}
/**
* Tests the transform method of JuliaTransform with a positive sign.
* Verifies that the transformation is correctly applied.
......@@ -24,7 +43,6 @@ class JuliaTransformTest {
@Test
@DisplayName("Test transform with positive sign")
void testTransform() {
JuliaTransform jt = new JuliaTransform(new Complex(1, 2), 1);
Complex v2 = new Complex(3, 4);
Vector2d v3 = jt.transform(v2);
assertEquals(1.554, v3.getX0(), 0.001);
......@@ -38,9 +56,9 @@ class JuliaTransformTest {
@Test
@DisplayName("Test transform with negative sign")
void testTransform2() {
JuliaTransform jt = new JuliaTransform(new Complex(1, 2), -1);
JuliaTransform jt2 = new JuliaTransform(new Complex(1, 2), -1);
Complex v2 = new Complex(3, 4);
Vector2d v3 = jt.transform(v2);
Vector2d v3 = jt2.transform(v2);
assertEquals(-1.554, v3.getX0(), 0.001);
assertEquals(-0.644, v3.getX1(), 0.001);
}
......
affine2D
-2.5, 0
2.5, 10
0, 0, 0, 0.16, 0, 0
0.85, 0.04, -0.04, 0.85, 0
0.2, -0.26, 0.23, 0.22, 0, 1.6
-0.15, 0.28, 0.26, 0.24, 0, 0.44
wrong
-2.5, 0
2.5, 10
0, 0, 0, 0.16, 0, 0
0.85, 0.04, -0.04, 0.85, 0, 1.6
0.2, -0.26, 0.23, 0.22, 0, 1.6
-0.15, 0.28, 0.26, 0.24, 0, 0.44
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment