Skip to content

Commit 33d768f

Browse files
committed
Adding tests for "Futoshiki solver".
1 parent 3932446 commit 33d768f

24 files changed

+322
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
- Tests for "Minimax exercise".
3232
- Tests for "Constrained latin squares".
3333
- Tests for "Crossword".
34+
- Tests for "Futoshiki solver".
3435

3536
## [3.11.0] - 2022-07-31
3637
### Added
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\FutoshikiSolver;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Futoshiki solver" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/futoshiki-solver
12+
*/
13+
class FutoshikiSolver implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $size);
18+
for ($i = 0; $i < $size; $i++)
19+
{
20+
$line = stream_get_line($stdin, 256 + 1, "\n");
21+
}
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("answer\n");
26+
}
27+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\FutoshikiSolver;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\FutoshikiSolver\FutoshikiSolver;
9+
10+
/**
11+
* Tests for the "Futoshiki solver" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\FutoshikiSolver\FutoshikiSolver
14+
* @group futoshikiSolver
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new FutoshikiSolver();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "No comparisons".
26+
*
27+
* @group futoshikiSolver_noComparisons
28+
*/
29+
public function testCanExecuteNoComparisons(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - no comparisons.txt',
33+
file_get_contents(__DIR__ . '/output/01 - no comparisons.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Comparisons only horizontal".
39+
*
40+
* @group futoshikiSolver_comparisonsOnlyHorizontal
41+
*/
42+
public function testCanExecuteComparisonsOnlyHorizontal(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - comparisons only horizontal.txt',
46+
file_get_contents(__DIR__ . '/output/02 - comparisons only horizontal.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Comparisons only vertical".
52+
*
53+
* @group futoshikiSolver_comparisonsOnlyVertical
54+
*/
55+
public function testCanExecuteComparisonsOnlyVertical(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - comparisons only vertical.txt',
59+
file_get_contents(__DIR__ . '/output/03 - comparisons only vertical.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "5x5".
65+
*
66+
* @group futoshikiSolver_5x5
67+
*/
68+
public function testCanExecute5x5(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - 5x5.txt',
72+
file_get_contents(__DIR__ . '/output/04 - 5x5.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "7x7".
78+
*
79+
* @group futoshikiSolver_7x7
80+
*/
81+
public function testCanExecute7x7(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - 7x7.txt',
85+
file_get_contents(__DIR__ . '/output/05 - 7x7.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "More 5x5".
91+
*
92+
* @group futoshikiSolver_more5x5
93+
*/
94+
public function testCanExecuteMore5x5(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - more 5x5.txt',
98+
file_get_contents(__DIR__ . '/output/06 - more 5x5.txt')
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "4x4".
104+
*
105+
* @group futoshikiSolver_4x4
106+
*/
107+
public function testCanExecute4x4(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - 4x4.txt',
111+
file_get_contents(__DIR__ . '/output/07 - 4x4.txt')
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "6x6".
117+
*
118+
* @group futoshikiSolver_6x6
119+
*/
120+
public function testCanExecute6x6(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - 6x6.txt',
124+
file_get_contents(__DIR__ . '/output/08 - 6x6.txt')
125+
);
126+
}
127+
128+
/**
129+
* Test that the code can be executed for "More 6x6".
130+
*
131+
* @group futoshikiSolver_more6x6
132+
*/
133+
public function testCanExecuteMore6x6(): void
134+
{
135+
$this->expectExecuteOutputAnswer(
136+
__DIR__ . '/input/09 - more 6x6.txt',
137+
file_get_contents(__DIR__ . '/output/09 - more 6x6.txt')
138+
);
139+
}
140+
141+
/**
142+
* Test that the code can be executed for "3x3".
143+
*
144+
* @group futoshikiSolver_3x3
145+
*/
146+
public function testCanExecute3x3(): void
147+
{
148+
$this->expectExecuteOutputAnswer(
149+
__DIR__ . '/input/10 - 3x3.txt',
150+
file_get_contents(__DIR__ . '/output/10 - 3x3.txt')
151+
);
152+
}
153+
154+
/**
155+
* Test that the code can be executed for "1x1".
156+
*
157+
* @group futoshikiSolver_1x1
158+
*/
159+
public function testCanExecute1x1(): void
160+
{
161+
$this->expectExecuteOutputAnswer(
162+
__DIR__ . '/input/11 - 1x1.txt',
163+
1 . PHP_EOL
164+
);
165+
}
166+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
1 0
3+
4+
0 0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
0>0
3+
4+
0<0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
0 0
3+
^ v
4+
0 0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
9
2+
0>3 5 1 0
3+
4+
0 2 0 5 0
5+
^
6+
0 0 0 0 0
7+
8+
0 5 0 3 0
9+
10+
0 4 3 2<0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
13
2+
0 3 0>0 0 5 0
3+
v ^
4+
0 0 0 0 0 0 0
5+
^
6+
4 5 0>0 0 2 7
7+
v
8+
0 0 0 0 0 0 0
9+
v v
10+
2 6 0 0 0 1 3
11+
^
12+
0 0 0 0 0 0 0
13+
14+
0 2 0 0<0 3<0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
9
2+
0 0<0 0<0
3+
^
4+
0 0>0 0 0
5+
6+
0 0 0 0 0
7+
8+
0<0 0 0 0
9+
v ^
10+
0 0 0<0<0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
7
2+
0 0<3<0
3+
4+
0 0 0 0
5+
^
6+
0>0 0 0
7+
^
8+
0 0 0<0

0 commit comments

Comments
 (0)