Compare commits
No commits in common. "87fc879292dc208d41ba849fea6dabe37f39ae41" and "051958057c993d88b56fe9dfe65d48a6b59fbcbd" have entirely different histories.
87fc879292
...
051958057c
|
|
@ -2,7 +2,7 @@
|
||||||
public class Time {
|
public class Time {
|
||||||
public static boolean timeCheck(String time) {
|
public static boolean timeCheck(String time) {
|
||||||
|
|
||||||
String regex = "([01]\\d|2[0-3]):([0-5]\\d)";
|
String regex = "^( ?: [01] \\d | 2[0-3] ) : [0-5]\\d$";
|
||||||
boolean formatRichtig = false;
|
boolean formatRichtig = false;
|
||||||
|
|
||||||
if (time == null) {
|
if (time == null) {
|
||||||
|
|
@ -18,8 +18,7 @@ public class Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println(timeCheck("23:56"));
|
System.out.println("23:56 \n abc");
|
||||||
System.out.println(timeCheck("00:00"));
|
|
||||||
System.out.println(timeCheck(null));
|
System.out.println(timeCheck(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
Vector.java
10
Vector.java
|
|
@ -9,15 +9,13 @@ public class Vector {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void vectorProduct(int[] vector1, int[] vector2) {
|
public static void vectorProduct(int[] vector1, int[] vector2) {
|
||||||
if (vector1 == null || vector2 == null){
|
|
||||||
System.out.println("Wegen unterschiedlichen Dimensionen ist das Kreuzprodukt nicht erlaubt");
|
if (vector1.length == vector2.length && vector2.length == 3) {
|
||||||
}
|
|
||||||
else if (vector1.length == vector2.length && vector2.length == 3) {
|
|
||||||
int[] kreuzVektor3D = new int[3];
|
int[] kreuzVektor3D = new int[3];
|
||||||
kreuzVektor3D[0] = (vector1[1] * vector2[2]) - (vector1[2] * vector2[1]);
|
kreuzVektor3D[0] = (vector1[1] * vector2[2]) - (vector1[2] * vector2[1]);
|
||||||
kreuzVektor3D[1] = (vector1[2] * vector2[0]) - (vector1[0] * vector2[2]);
|
kreuzVektor3D[1] = (vector1[2] * vector2[0]) - (vector1[0] * vector2[2]);
|
||||||
kreuzVektor3D[2] = (vector1[0] * vector2[1]) - (vector1[1] * vector2[0]);
|
kreuzVektor3D[2] = (vector1[0] * vector2[1]) - (vector1[1] * vector2[0]);
|
||||||
System.out.println("Ergebnis des 3DKreuzproduktes: [" + kreuzVektor3D[0] + ", " + kreuzVektor3D[1] + ", "
|
System.out.println("Ergebnis des Kreuzproduktes: [" + kreuzVektor3D[0] + ", " + kreuzVektor3D[1] + ", "
|
||||||
+ kreuzVektor3D[2] + "]");
|
+ kreuzVektor3D[2] + "]");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +23,7 @@ public class Vector {
|
||||||
else if (vector1.length == vector2.length && vector2.length == 2) {
|
else if (vector1.length == vector2.length && vector2.length == 2) {
|
||||||
int kreuzVektor2D = 0;
|
int kreuzVektor2D = 0;
|
||||||
kreuzVektor2D = (vector1[0] * vector2[1]) - (vector1[1] * vector2[0]);
|
kreuzVektor2D = (vector1[0] * vector2[1]) - (vector1[1] * vector2[0]);
|
||||||
System.out.println("Ergebnis des 2DKreuzproduktes: " + kreuzVektor2D);
|
System.out.println("Ergebnis des Kreuzproduktes: " + kreuzVektor2D);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,78 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class VectorTest {
|
public class VectorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testScalarMultiplication() {
|
||||||
|
int[] vector = {1, 2, 3};
|
||||||
|
int scalar = 2;
|
||||||
|
Vector.scalarMultiplication(vector, scalar);
|
||||||
|
assertArrayEquals(new int[]{2, 4, 6}, vector);
|
||||||
|
int[] vector1 = {7, 8, 15};
|
||||||
|
|
||||||
|
Vector.scalarMultiplication(vector1, -1);
|
||||||
|
assertArrayEquals(new int[]{-7, -8, -15}, vector1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testVectorProduct2D() {
|
||||||
|
int[] vector1 = {3, 4};
|
||||||
|
int[] vector2 = {5, 6};
|
||||||
|
// Für 2D Kreuzprodukt wird der Skalarwert (Z-Komponente des 3D-Kreuzprodukts) verwendet
|
||||||
|
// 3*6 - 4*5 = 18 - 20 = -2
|
||||||
|
// Erwartete Ausgabe: -2
|
||||||
|
System.out.print("Erwartete Ausgabe: -2\nTatsächliche Ausgabe: ");
|
||||||
|
Vector.vectorProduct(vector1, vector2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testVectorProduct3D() {
|
||||||
|
int[] vector1 = {1, 2, 3};
|
||||||
|
int[] vector2 = {4, 5, 6};
|
||||||
|
// Kreuzprodukt:
|
||||||
|
// x = 2*6 - 3*5 = 12 - 15 = -3
|
||||||
|
// y = 3*4 - 1*6 = 12 - 6 = 6
|
||||||
|
// z = 1*5 - 2*4 = 5 - 8 = -3
|
||||||
|
System.out.print("Erwartete Ausgabe: [-3, 6, -3]\nTatsächliche Ausgabe: ");
|
||||||
|
Vector.vectorProduct(vector1, vector2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testVectorLength() {
|
||||||
|
int[] vector = {3, 4};
|
||||||
|
double length = Vector.vectorLength(vector);
|
||||||
|
assertEquals(5.0, length, 0.001);
|
||||||
|
|
||||||
|
int[] vector3D = {1, 2, 2};
|
||||||
|
assertEquals(3.0, Vector.vectorLength(vector3D), 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMatrixMultiplicationValidMatrix() {
|
||||||
|
int[][] matrix = {
|
||||||
|
{1, 2, 3},
|
||||||
|
{4, 5, 6},
|
||||||
|
{7, 8, 9}
|
||||||
|
};
|
||||||
|
int scalar = 2;
|
||||||
|
int[][] expected = {
|
||||||
|
{2, 4, 6},
|
||||||
|
{8, 10, 12},
|
||||||
|
{14, 16, 18}
|
||||||
|
};
|
||||||
|
assertArrayEquals(expected, Vector.matrixMultiplication(matrix, scalar));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMatrixMultiplicationInvalidMatrix() {
|
||||||
|
int[][] invalidMatrix = {
|
||||||
|
{1, 2},
|
||||||
|
{3, 4}
|
||||||
|
};
|
||||||
|
assertNull(Vector.matrixMultiplication(invalidMatrix, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testScalarMultiplicationVariants() {
|
void testScalarMultiplicationVariants() {
|
||||||
int[] v1 = {1, 2, 3};
|
int[] v1 = {1, 2, 3};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue