Skip to content

Commit 021dd81

Browse files
committed
Adding tests for "Sudoku validator".
1 parent a396b19 commit 021dd81

File tree

10 files changed

+207
-0
lines changed

10 files changed

+207
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Tests for "Sum of spiral's diagonals".
1919
- Tests for "Brackets, extreme edition".
2020
- Tests for "The electrician apprentice".
21+
- Tests for "Sudoku validator".
2122

2223
## [3.6.0] - 2022-03-11
2324
### Added
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\SudokuValidator;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Sudoku validator" puzzle.
11+
*/
12+
class SudokuValidator implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
for ($i = 0; $i < 9; $i++)
17+
{
18+
$inputs = explode(" ", fgets($stdin));
19+
for ($j = 0; $j < 9; $j++)
20+
{
21+
$n = intval($inputs[$j]);
22+
}
23+
}
24+
25+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
26+
27+
echo("true or false\n");
28+
}
29+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\SudokuValidator;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\SudokuValidator\SudokuValidator;
9+
10+
/**
11+
* Tests for the "Sudoku validator" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\SudokuValidator\SudokuValidator
14+
* @group sudokuValidator
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new SudokuValidator();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Basic grid".
26+
*
27+
* @group sudokuValidator_basicGrid
28+
*/
29+
public function testCanExecuteBasicGrid(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - basic grid.txt',
33+
"true" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Another correct grid".
39+
*
40+
* @group sudokuValidator_anotherCorrectGrid
41+
*/
42+
public function testCanExecuteAnotherCorrectGrid(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - another correct grid.txt',
46+
"true" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Row error".
52+
*
53+
* @group sudokuValidator_rowError
54+
*/
55+
public function testCanExecuteRowError(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - row error.txt',
59+
"false" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Column error".
65+
*
66+
* @group sudokuValidator_columnError
67+
*/
68+
public function testCanExecuteColumnError(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - column error.txt',
72+
"false" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Subgrid error".
78+
*
79+
* @group sudokuValidator_subgridError
80+
*/
81+
public function testCanExecuteSubgridError(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - subgrid error.txt',
85+
"false" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Rubbish error".
91+
*
92+
* @group sudokuValidator_rubbishError
93+
*/
94+
public function testCanExecuteRubbishError(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - rubbish error.txt',
98+
"false" . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "When summing is not enough".
104+
*
105+
* @group sudokuValidator_whenSummingIsNotEnough
106+
*/
107+
public function testCanExecuteWhenSummingIsNotEnough(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - when summing is not enough.txt',
111+
"false" . PHP_EOL
112+
);
113+
}
114+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1 2 3 4 5 6 7 8 9
2+
4 5 6 7 8 9 1 2 3
3+
7 8 9 1 2 3 4 5 6
4+
9 1 2 3 4 5 6 7 8
5+
3 4 5 6 7 8 9 1 2
6+
6 7 8 9 1 2 3 4 5
7+
8 9 1 2 3 4 5 6 7
8+
2 3 4 5 6 7 8 9 1
9+
5 6 7 8 9 1 2 3 4
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 3 5 2 6 9 7 8 1
2+
6 8 2 5 7 1 4 9 3
3+
1 9 7 8 3 4 5 6 2
4+
8 2 6 1 9 5 3 4 7
5+
3 7 4 6 8 2 9 1 5
6+
9 5 1 7 4 3 6 2 8
7+
5 1 9 3 2 6 8 7 4
8+
2 4 8 9 5 7 1 3 6
9+
7 6 3 4 1 8 2 5 9
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 3 2 2 6 9 7 8 1
2+
6 8 5 5 7 1 4 9 3
3+
1 9 7 8 3 4 5 6 2
4+
8 2 6 1 9 5 3 4 7
5+
3 7 4 6 8 2 9 1 5
6+
9 5 1 7 4 3 6 2 8
7+
5 1 9 3 2 6 8 7 4
8+
2 4 8 9 5 7 1 3 6
9+
7 6 3 4 1 8 2 5 9
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 3 5 2 6 9 7 8 1
2+
6 8 2 5 7 1 4 9 3
3+
1 9 7 8 3 4 5 6 2
4+
8 2 6 1 9 5 3 4 7
5+
3 7 4 6 8 2 9 1 5
6+
1 5 9 7 4 3 6 2 8
7+
5 1 9 3 2 6 8 7 4
8+
2 4 8 9 5 7 1 3 6
9+
7 6 3 4 1 8 2 5 9
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 3 5 2 6 9 7 8 1
2+
6 8 2 5 7 1 4 9 3
3+
8 9 7 1 3 4 5 6 2
4+
1 2 6 8 9 5 3 4 7
5+
3 7 4 6 8 2 9 1 5
6+
9 5 1 7 4 3 6 2 8
7+
5 1 9 3 2 6 8 7 4
8+
2 4 8 9 5 7 1 3 6
9+
7 6 3 4 1 8 2 5 9
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
5 9 6 1 4 2 5 3 7
2+
6 1 4 3 5 8 2 4 8
3+
5 6 9 4 1 2 5 3 6
4+
1 9 5 3 6 8 4 1 6
5+
5 9 3 6 3 4 8 2 1
6+
5 9 5 3 2 1 4 5 6
7+
1 3 6 4 8 6 5 2 5
8+
4 1 2 3 6 8 4 9 2
9+
3 6 8 7 4 1 5 6 3
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1 3 3 4 5 6 7 7 9
2+
4 5 6 7 7 9 1 3 3
3+
7 7 9 1 3 3 4 5 6
4+
9 1 3 3 4 5 6 7 7
5+
3 4 5 6 7 7 9 1 3
6+
6 7 7 9 1 3 3 4 5
7+
7 9 1 3 3 4 5 6 7
8+
3 3 4 5 6 7 7 9 1
9+
5 6 7 7 9 1 3 3 4

0 commit comments

Comments
 (0)