Skip to content

Commit 43110b5

Browse files
committed
Adding tests for "Is the king in check? (part 1)".
1 parent efe3e87 commit 43110b5

File tree

8 files changed

+154
-0
lines changed

8 files changed

+154
-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 "Add'em up".
3232
- Tests for "Rotating arrows".
3333
- Tests for "10 pin bowling scores".
34+
- Tests for "Is the king in check? (part 1)".
3435

3536
## [3.7.0] - 2022-03-31
3637
### Added
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\IsTheKingInCheckPart1;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Is the king in check? (part 1)" puzzle.
11+
*/
12+
class IsTheKingInCheckPart1 implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
for ($i = 0; $i < 8; $i++)
17+
{
18+
$chessRow = stream_get_line($stdin, 15 + 1, "\n");
19+
}
20+
21+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
22+
23+
echo("Check/No Check\n");
24+
}
25+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\IsTheKingInCheckPart1;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\IsTheKingInCheckPart1\IsTheKingInCheckPart1;
9+
10+
/**
11+
* Tests for the "Is the king in check? (part 1)" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\IsTheKingInCheckPart1\IsTheKingInCheckPart1
14+
* @group isTheKingInCheckPart1
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new IsTheKingInCheckPart1();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "R vs K".
26+
*
27+
* @group isTheKingInCheckPart1_RvsK
28+
*/
29+
public function testCanExecuteRvsK(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - R vs K.txt',
33+
"Check" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "B vs K".
39+
*
40+
* @group isTheKingInCheckPart1_BvsK
41+
*/
42+
public function testCanExecuteBvsK(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - B vs K.txt',
46+
"No Check" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Q vs K".
52+
*
53+
* @group isTheKingInCheckPart1_BvsK
54+
*/
55+
public function testCanExecuteQvsK(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - Q vs K.txt',
59+
"Check" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "N vs K".
65+
*
66+
* @group isTheKingInCheckPart1_NvsK
67+
*/
68+
public function testCanExecuteNvsK(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - N vs K.txt',
72+
"No Check" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Test 5".
78+
*
79+
* @group isTheKingInCheckPart1_test5
80+
*/
81+
public function testCanExecuteTest5(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - test 5.txt',
85+
"Check" . PHP_EOL
86+
);
87+
}
88+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_ _ R _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ _ _ _ _ _ _
5+
_ _ _ _ _ _ _ _
6+
_ _ K _ _ _ _ _
7+
_ _ _ _ _ _ _ _
8+
_ _ _ _ _ _ _ _
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_ _ _ _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ K _ _ _ _ _
5+
_ _ B _ _ _ _ _
6+
_ _ _ _ _ _ _ _
7+
_ _ _ _ _ _ _ _
8+
_ _ _ _ _ _ _ _
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Q _ _ _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ _ _ _ _ _ _
5+
_ _ _ _ _ _ _ _
6+
_ _ _ _ _ _ _ _
7+
_ _ _ _ _ _ K _
8+
_ _ _ _ _ _ _ _
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_ _ _ _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ N _ K _ _ _
5+
_ _ _ _ _ _ _ _
6+
_ _ _ _ _ _ _ _
7+
_ _ _ _ _ _ _ _
8+
_ _ _ _ _ _ _ _
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_ _ _ _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ _ _ _ _ _ _
5+
_ _ _ _ _ _ _ _
6+
_ _ _ _ _ _ _ _
7+
_ _ _ _ _ N _ _
8+
_ _ _ _ _ _ _ K

0 commit comments

Comments
 (0)