Skip to content
Snippets Groups Projects
Commit 3dfca13d authored by Julian's avatar Julian
Browse files

contrast

parent 6885231c
No related branches found
No related tags found
No related merge requests found
import java.util.InputMismatchException;
import java.util.Random;
import static org.junit.jupiter.api.Assertions.*;
class MatrixImageTest {
@org.junit.jupiter.api.Test
void removeVPath1() throws java.io.FileNotFoundException {
int[] path = {0, 0};
int[][] matrixB = {{1, 3}, {2, 4}};
int[][] matrixA = {{2, 4}};
processRemoveTest(matrixA, matrixB, path, 2, 2);
}
@org.junit.jupiter.api.Test
void removeVPath2() throws java.io.FileNotFoundException {
int[] path = {0, 0, 0};
int[][] matrixB = {{1, 4, 7}, {2, 5, 8}, {3, 6, 9}};
int[][] matrixA = {{2, 5, 8}, {3, 6, 9}};
processRemoveTest(matrixA, matrixB, path, 3, 3);
}
@org.junit.jupiter.api.Test
void removeVPath3() throws java.io.FileNotFoundException {
int[] path = {1, 1, 1};
int[][] matrixB = {{1, 3, 5}, {2, 4, 6}};
int[][] matrixA = {{1, 3, 5}};
processRemoveTest(matrixA, matrixB, path, 2, 3);
}
@org.junit.jupiter.api.Test
void removeVPath4() throws java.io.FileNotFoundException {
int[] path = {1, 2};
int[][] matrixB = {{1, 4}, {2, 5}, {3, 6}};
int[][] matrixA = {{1, 4}, {3, 5}};
processRemoveTest(matrixA, matrixB, path, 3, 2);
}
void processRemoveTest(int[][] matrixA, int[][] matrixB, int[] path, int x, int y) {
MatrixImage matrixImage = new MatrixImage(x, y);
matrixImage.field = matrixB;
matrixImage.removeVPath(path);
matrixB = matrixImage.field;
areMatrixIdentical(matrixA, matrixB);
}
void areMatrixIdentical(int[][] matrixA, int[][] matrixB) {
assertNotNull(matrixA, "Null Pointer zurückgegeben");
assertNotNull(matrixB, "Null Pointer zurückgegeben");
assertEquals(matrixA.length, matrixB.length, "Größe der Matrix stimmt nicht");
assertEquals(matrixA[0].length, matrixB[0].length, "Größe der Matrix stimmt nicht");
for (int i = 0; i < matrixA.length; i++) {
for (int j = 0; j < matrixA[0].length; j++) {
assertEquals(matrixA[i][j], matrixB[i][j], "Falscher Wert an [" + i + "][" + j + "]");
}
}
}
@org.junit.jupiter.api.Test
void contrastCheckExceptions() throws java.io.FileNotFoundException {
for (int i = 0; i < 5; i++) {
Random r = new Random();
int x = r.nextInt(9) + 1;
int y = r.nextInt(9) + 1;
MatrixImage matrixImage = new MatrixImage(x, y);
assertThrows(InputMismatchException.class, () -> {
matrixImage.contrast(new Coordinate(x - 1, y - 1), new Coordinate(x - 1, y));
}, "wirft keine exception");
assertThrows(InputMismatchException.class, () -> {
matrixImage.contrast(new Coordinate(x, y - 1), new Coordinate(x - 1, y - 1));
}, "wirft keine exception");
assertThrows(InputMismatchException.class, () -> {
matrixImage.contrast(new Coordinate(x - 1, y - 1), new Coordinate(x - 1, -1));
}, "wirft keine exception");
assertThrows(InputMismatchException.class, () -> {
matrixImage.contrast(new Coordinate(-1, y - 1), new Coordinate(x - 1, y - 1));
}, "wirft keine exception");
assertDoesNotThrow(() ->
matrixImage.contrast(new Coordinate(x - 1, y - 1), new Coordinate(0, 0)),
"Wirft exception, obwohl index in der matrix liegen sollte"
);
}
}
@org.junit.jupiter.api.Test
void contrast1() throws java.io.FileNotFoundException {
int[][] matrixA = {{1, 3}, {2, 4}};
MatrixImage m = new MatrixImage(2, 2);
m.field = matrixA;
assertEquals(0.0, m.contrast(new Coordinate(1, 1), new Coordinate(1, 1)));
assertTrue(m.contrast(new Coordinate(1, 0), new Coordinate(0, 1)) >= 0, "" +
"contrast should only return positive values");
assertEquals(1.0, m.contrast(new Coordinate(1, 0), new Coordinate(0, 1)));
assertTrue(m.contrast(new Coordinate(1, 1), new Coordinate(0, 0)) >= 0, "" +
"contrast should only return positive values");
assertEquals(3.0, m.contrast(new Coordinate(1, 1), new Coordinate(0, 0)));
}
@org.junit.jupiter.api.Test
void contrast2() throws java.io.FileNotFoundException {
int[][] matrix = {{5, 4, 3, 2, 1}};
MatrixImage m = new MatrixImage(1, 5);
m.field = matrix;
assertEquals(0, m.contrast(new Coordinate(0, 4), new Coordinate(0, 4)));
assertTrue(m.contrast(new Coordinate(0, 2), new Coordinate(0, 3)) >= 0, "" +
"contrast should only return positive values");
assertEquals(1.0, m.contrast(new Coordinate(0, 2), new Coordinate(0, 1)));
assertTrue(m.contrast(new Coordinate(0, 3), new Coordinate(0, 4)) >= 0, "" +
"contrast should only return positive values");
assertEquals(1.0, m.contrast(new Coordinate(0, 3), new Coordinate(0, 4)));
}
}
\ 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