main
parent
6888fc2923
commit
b151cbe35c
|
|
@ -1,4 +1,6 @@
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class VectorTest {
|
||||
|
|
@ -72,4 +74,95 @@ public class VectorTest {
|
|||
};
|
||||
assertNull(Vector.matrixMultiplication(invalidMatrix, 3));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
void testScalarMultiplicationVariants() {
|
||||
int[] v1 = {1, 2, 3};
|
||||
Vector.scalarMultiplication(v1, 2);
|
||||
assertArrayEquals(new int[]{2, 4, 6}, v1);
|
||||
|
||||
int[] v2 = {7, 8, 15};
|
||||
Vector.scalarMultiplication(v2, -1);
|
||||
assertArrayEquals(new int[]{-7, -8, -15}, v2);
|
||||
|
||||
int[] v3 = {0, 0, 0};
|
||||
Vector.scalarMultiplication(v3, 5);
|
||||
assertArrayEquals(new int[]{0, 0, 0}, v3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVectorProduct2DVariants() {
|
||||
int ergebnis1 = -2;
|
||||
System.out.println("Erwartet: " + ergebnis1 );
|
||||
Vector.vectorProduct(new int[]{3, 4}, new int[]{5, 6});
|
||||
int ergebnis2 = -1;
|
||||
System.out.println("Erwartet: " + ergebnis2 );
|
||||
Vector.vectorProduct(new int[]{0, 1}, new int[]{1, 0});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVectorProduct3DVariants() {
|
||||
int[] ergebnis1 = {-3, 6, -3};
|
||||
System.out.println("Erwartet: [" + ergebnis1[0]+", " + ergebnis1[1] +", " + ergebnis1[2]+"]");
|
||||
Vector.vectorProduct(new int[]{1, 2, 3}, new int[]{4, 5, 6});
|
||||
int[] ergebnis2 = {-1, 0, 0};
|
||||
System.out.println("Erwartet: [" + ergebnis2[0]+", " + ergebnis2[1] +", " + ergebnis2[2]+"]");
|
||||
Vector.vectorProduct(new int[]{0, 0, 1}, new int[]{0, 1, 0});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVectorProductInvalidDimensions() {
|
||||
System.out.println("Erwartet: illegale Dimension" );
|
||||
Vector.vectorProduct(new int[]{1, 0}, new int[]{0, 1, 0});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVectorLengthVariants() {
|
||||
assertEquals(5.0, Vector.vectorLength(new int[]{3, 4}), 0.001);
|
||||
assertEquals(3.0, Vector.vectorLength(new int[]{1, 2, 2}), 0.001);
|
||||
assertEquals(0.0, Vector.vectorLength(new int[]{0, 0, 0}), 0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMatrixMultiplicationVariants() {
|
||||
int[][] matrix = {
|
||||
{1, 2, 3},
|
||||
{4, 5, 6},
|
||||
{7, 8, 9}
|
||||
};
|
||||
int[][] expected = {
|
||||
{2, 4, 6},
|
||||
{8, 10, 12},
|
||||
{14, 16, 18}
|
||||
};
|
||||
assertArrayEquals(expected, Vector.matrixMultiplication(matrix, 2));
|
||||
|
||||
int[][] zeroMatrix = {
|
||||
{1, -2, -6},
|
||||
{-3, 4, 5},
|
||||
{-70, 12, -8}
|
||||
};
|
||||
int[][] expectedZero = {
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0}
|
||||
};
|
||||
assertArrayEquals(expectedZero, Vector.matrixMultiplication(zeroMatrix, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMatrixMultiplicationInvalidCases() {
|
||||
int[][] nonSquare = {
|
||||
{1, 2},
|
||||
{3, 4}
|
||||
};
|
||||
assertNull(Vector.matrixMultiplication(nonSquare, 3));
|
||||
|
||||
int[][] empty = new int[0][0];
|
||||
assertNull(Vector.matrixMultiplication(empty, 2));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue