Skip to content
Snippets Groups Projects
Commit b37c71b1 authored by Guyslain's avatar Guyslain
Browse files

update du sujet, 2024

parent 3f26fd43
No related branches found
No related tags found
No related merge requests found
package datastruct;
package matrix;
import org.junit.jupiter.api.Test;
......
package datastruct;
package matrix;
import org.junit.jupiter.api.Test;
......
package datastruct;
package matrix;
import org.junit.jupiter.api.Test;
......@@ -6,14 +6,14 @@ import java.util.Iterator;
import static org.junit.jupiter.api.Assertions.*;
class MatrixTest {
class ListMatrixTest {
private final MatrixInitializer<Integer> sumInitializer =
coord -> coord.x() + coord.y();
@Test
public void testMatrixCreationWithInitializer() {
Matrix<Integer> matrix = new Matrix<>(3, 4, sumInitializer);
ListMatrix<Integer> matrix = new ListMatrix<>(3, 4, sumInitializer);
assertEquals(3, matrix.width());
assertEquals(4, matrix.height());
assertEquals(4, matrix.get(2, 2));
......@@ -24,7 +24,7 @@ class MatrixTest {
@Test
public void testMatrixCreationWithInitialValue() {
Matrix<String> matrix = new Matrix<>(2, 2, "Foo");
ListMatrix<String> matrix = new ListMatrix<>(2, 2, "Foo");
assertEquals(2, matrix.width());
assertEquals(2, matrix.height());
assertEquals("Foo", matrix.get(1, 1)); // Test a specific cell value.
......@@ -32,7 +32,7 @@ class MatrixTest {
@Test
public void testMatrixSetAndGet() {
Matrix<Integer> matrix = new Matrix<>(3, 3, 0);
ListMatrix<Integer> matrix = new ListMatrix<>(3, 3, 0);
matrix.set(1, 1,42);
assertEquals(42, matrix.get(1, 1));
matrix.set(0, 2,10);
......@@ -43,7 +43,7 @@ class MatrixTest {
@Test
public void testMatrixWidthAndHeight() {
Matrix<String> matrix = new Matrix<>(4, 2, "A");
ListMatrix<String> matrix = new ListMatrix<>(4, 2, "A");
assertEquals(4, matrix.width());
assertEquals(2, matrix.height());
matrix.set(3, 1,"B");
......@@ -53,7 +53,7 @@ class MatrixTest {
@Test
public void testMatrixIterator() {
Matrix<Integer> matrix = new Matrix<>(2, 2, sumInitializer);
ListMatrix<Integer> matrix = new ListMatrix<>(2, 2, sumInitializer);
Iterator<Integer> iterator = matrix.iterator();
assertTrue(iterator.hasNext());
assertEquals(0, iterator.next());
......@@ -68,7 +68,7 @@ class MatrixTest {
@Test
public void testMatrixCoordinates() {
Matrix<Integer> matrix = new Matrix<>(2, 2, 0);
ListMatrix<Integer> matrix = new ListMatrix<>(2, 2, 0);
Iterable<Coordinate> coordinates = matrix.coordinates();
int count = 0;
for (Coordinate coord : coordinates) {
......@@ -77,12 +77,24 @@ class MatrixTest {
assertEquals(4, count);
}
@Test
public void testMatrixLens() {
Matrix<Integer> matrix = new Matrix<>(2, 2, 0);
Lens<Integer> lens = matrix.at(1, 1);
assertEquals(0, lens.get());
lens.set(42);
assertEquals(42, matrix.get(1, 1));
public void testSubMatrix() {
Matrix<Integer> matrix = new ListMatrix<>(5, 5, 0);
for (int x = 0; x < 5; x++) {
for (int y = 0; y < 5; y++) {
matrix.set(x,y,x + y * 5);
}
}
Matrix<Integer> sub = matrix.subMatrix(Coordinate.of(2,1),2,3);
assertEquals(2, sub.width());
assertEquals(3, sub.height());
for (int x = 2; x < 4; x++) {
for (int y = 1; y < 4; y++) {
assertEquals(x + y * 5, sub.get(x-2,y-1));
}
}
}
}
package model;
import datastruct.Coordinate;
import matrix.Coordinate;
import javafx.scene.paint.Color;
import model.automata.GameOfLifeAutomaton;
import static model.automata.GameOfLifeState.*;
......
package model;
import controller.Simulation;
import datastruct.Coordinate;
import matrix.Coordinate;
import model.automata.GameOfLifeAutomaton;
import model.automata.GameOfLifeState;
import org.junit.jupiter.api.BeforeEach;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment