67 lines
2.2 KiB
Java
67 lines
2.2 KiB
Java
package sudoku;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Scanner;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
public class AppTest {
|
|
|
|
@Test
|
|
public void testExample() {
|
|
// Simulate user input with proper line endings
|
|
// First 1 is to select the int type of Symboles and after, Symboles are entered
|
|
// (1 to 16)
|
|
String simulatedInput = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n";
|
|
System.setIn(new ByteArrayInputStream(simulatedInput.getBytes()));
|
|
|
|
// Create a new Sudoku
|
|
Sudoku sudoku = new Sudoku(16);
|
|
sudoku.getGrille().askSetSymbolesPossibles(1, new Scanner(System.in)); // Pass the type of symbol and scanner
|
|
|
|
// Verify the symbols
|
|
ArrayList<Symbole> expectedSymbols = new ArrayList<>(Arrays.asList(
|
|
Symbole.of(1),
|
|
Symbole.of(2),
|
|
Symbole.of(3),
|
|
Symbole.of(4),
|
|
Symbole.of(5),
|
|
Symbole.of(6),
|
|
Symbole.of(7),
|
|
Symbole.of(8),
|
|
Symbole.of(9),
|
|
Symbole.of(10),
|
|
Symbole.of(11),
|
|
Symbole.of(12),
|
|
Symbole.of(13),
|
|
Symbole.of(14),
|
|
Symbole.of(15),
|
|
Symbole.of(16)));
|
|
assertEquals(expectedSymbols, sudoku.getGrille().getSymbolesPossibles());
|
|
|
|
// Cleanup
|
|
System.setIn(System.in);
|
|
|
|
int taille = 16;
|
|
for (int i = 0; i < taille; i++) {
|
|
sudoku.getGrille().setCase(i, i, expectedSymbols.get(i));
|
|
}
|
|
|
|
sudoku.getGrille().creerBlocCarre();
|
|
|
|
sudoku.ajouterContrainte(new ContrainteLigne());
|
|
sudoku.ajouterContrainte(new ContrainteColonne());
|
|
sudoku.ajouterContrainte(new ContrainteBloc());
|
|
|
|
System.out.println(sudoku.getGrille().toString());
|
|
|
|
Resolveur resolveur = new ResolveurBacktraceSimple();
|
|
resolveur.resoudre(sudoku, false);
|
|
System.out.println("Sudoku résolu :");
|
|
System.out.println(sudoku.getGrille().toString());
|
|
}
|
|
} |