Skip to content

Commit cc69a57

Browse files
committed
Adding tests for "ISBN check digit".
1 parent 460300f commit cc69a57

File tree

11 files changed

+481
-0
lines changed

11 files changed

+481
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Tests for "Walk on a die".
1010
- Tests for "Dolbear's law".
11+
- Tests for "ISBN check digit".
1112

1213
## [3.5.0] - 2022-02-22
1314
### Added
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\ISBNCheckDigit;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "ISBN check digit" puzzle.
11+
*/
12+
class ISBNCheckDigit implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $N);
17+
for ($i = 0; $i < $N; $i++)
18+
{
19+
$ISBN = stream_get_line($stdin, 20 + 1, "\n");
20+
}
21+
22+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
23+
24+
echo("answer\n");
25+
}
26+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\ISBNCheckDigit;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\ISBNCheckDigit\ISBNCheckDigit;
9+
10+
/**
11+
* Tests for the "ISBN check digit" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\ISBNCheckDigit\ISBNCheckDigit
14+
* @group ISBNCheckDigit
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new ISBNCheckDigit();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Example".
26+
*
27+
* @group ISBNCheckDigit_example
28+
*/
29+
public function testCanExecuteExample(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - example.txt',
33+
file_get_contents(__DIR__ . '/output/01 - example.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Short".
39+
*
40+
* @group ISBNCheckDigit_short
41+
*/
42+
public function testCanExecuteShort(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - short.txt',
46+
file_get_contents(__DIR__ . '/output/02 - short.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Longer".
52+
*
53+
* @group ISBNCheckDigit_longer
54+
*/
55+
public function testCanExecuteLonger(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - longer.txt',
59+
file_get_contents(__DIR__ . '/output/03 - longer.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Much longer".
65+
*
66+
* @group ISBNCheckDigit_muchLonger
67+
*/
68+
public function testCanExecuteMuchLonger(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - much longer.txt',
72+
file_get_contents(__DIR__ . '/output/04 - much longer.txt')
73+
);
74+
}
75+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
6
2+
0306406152
3+
013603599X
4+
1145185215X
5+
9780306406157
6+
9780306406154
7+
978043551907X
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
10
2+
0470371722
3+
9781119247792
4+
9780470124512
5+
11190495550
6+
1118105354
7+
9781118737637
8+
0387372350
9+
154875155X
10+
9781548751555
11+
978193981677
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
21
2+
0471697037
3+
1171711743
4+
1146386265
5+
9781531807382
6+
0671039414
7+
0553282964
8+
0743412524
9+
Im_garbage
10+
0553270502
11+
9781784399092
12+
0553493825
13+
9781511343572
14+
0553156284
15+
0553570099
16+
9780606393188
17+
97804X8458533
18+
9780745669779
19+
0976315262
20+
1498773192
21+
9780408478999
22+
9780691154305

0 commit comments

Comments
 (0)