Skip to content
Snippets Groups Projects
Commit 77ca0357 authored by Magnus Eik's avatar Magnus Eik
Browse files

Add Illegalargumentexception to AffineTransform2D, add negative test.

parent bdafd79a
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenCompilerTasksManager">
<option name="afterCompileTasks">
<set>
<MavenCompilerTask>
<option name="goal" value="install" />
<option name="projectPath" value="$PROJECT_DIR$/pom.xml" />
</MavenCompilerTask>
</set>
</option>
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
......
......@@ -8,5 +8,6 @@
</component>
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/idatt2003" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -29,6 +29,11 @@ public class AffineTransform2D extends Transform2D {
* @param inputVector A vector {@link Vector2D} which defines the vector-addition part of the affine transformation.
*/
public AffineTransform2D(Matrix2x2 inputMatrix, Vector2D inputVector){
if (inputMatrix == null){
throw new IllegalArgumentException("Input matrix should not be null");
} else if (inputVector == null) {
throw new IllegalArgumentException("Input vector should not be null");
}
this.matrix = inputMatrix;
this.vector = inputVector;
}
......@@ -39,6 +44,9 @@ public class AffineTransform2D extends Transform2D {
* @return A new vector {@link Vector2D} which represents a point on a plane. The point represents a new step in the creation of fractal.
*/
public Vector2D transform(Vector2D point){
if (point == null){
throw new IllegalArgumentException("Input should not be null");
}
return matrix.multiply(point).add(vector);
}
......
......@@ -20,8 +20,6 @@ class AffineTransform2DTest {
@BeforeEach
void setUp() {
matrix2x2 = new Matrix2x2(0.5,1,1,0.5);
vector2D = new Vector2D(3,1);
affineTransform2D = new AffineTransform2D(matrix2x2,vector2D);
......@@ -54,4 +52,15 @@ class AffineTransform2DTest {
assertEquals(vector2D, actual, "The getVector method should return the correct vector");
}
}
}
\ No newline at end of file
@Nested
@DisplayName("Negative Affine Transform Tests")
class NegativeAffineTransform2DTests{
@Test
void transformWithNullInput() {
assertThrows(IllegalArgumentException.class, () -> affineTransform2D.transform(null),
"The transform method should throw IllegalArgumentException when the input is null");
}
}
}
......@@ -14,7 +14,6 @@ class JuliaTransformTest {
Complex complex;
Matrix2x2 matrix2x2;
Vector2D vector2D;
JuliaTransform juliaTransform;
......@@ -37,7 +36,7 @@ class JuliaTransformTest {
}
@Test
void transform(){
Vector2D expected = new Vector2D(1.866,0.428);
Vector2D expected = new Vector2D(1.647,0.12138);
Vector2D actual = juliaTransform.transform(vector2D);
assertEquals(expected.getX0(),actual.getX0(),0.01);
assertEquals(expected.getX1(),actual.getX1(),0.01);
......@@ -52,9 +51,6 @@ class JuliaTransformTest {
JuliaTransform juliaTransformZeroSign = new JuliaTransform(complex,0);
assertEquals(vector2D.getX0(),juliaTransformZeroSign.transform(vector2D).getX0());
assertEquals(vector2D.getX1(),juliaTransformZeroSign.transform(vector2D).getX1());
}
}
}
\ 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