Skip to content

Commit dc5ee9e

Browse files
committed
Adding tests for "The gift".
1 parent 10059f0 commit dc5ee9e

19 files changed

+3353
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
- Tests for "Conway sequence".
9+
- Tests for "The gift".
910

1011
## [2.1.0] - 2022-02-10
1112
### 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\Training\Medium\TheGift;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "The gift" puzzle.
11+
*/
12+
class TheGift implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $N);
17+
fscanf($stdin, "%d", $C);
18+
for ($i = 0; $i < $N; $i++)
19+
{
20+
fscanf($stdin, "%d", $B);
21+
}
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("IMPOSSIBLE\n");
26+
}
27+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Medium\TheGift;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Medium\TheGift\TheGift;
9+
10+
/**
11+
* Tests for the "The gift" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Medium\TheGift\TheGift
14+
* @group theGift
15+
*/
16+
final class TheGiftTest extends PuzzleTest
17+
{
18+
public function setUp(): void
19+
{
20+
$this->puzzle = new TheGift();
21+
}
22+
23+
/**
24+
* Test that the code can be executed for "Example 1".
25+
*
26+
* @group conwaySequence_example1
27+
*/
28+
public function testCanExecuteExample1(): void
29+
{
30+
$this->expectExecuteOutputAnswer(
31+
__DIR__ . '/input/01 - example 1.txt',
32+
'IMPOSSIBLE' . PHP_EOL
33+
);
34+
}
35+
36+
/**
37+
* Test that the code can be executed for "Example 2".
38+
*
39+
* @group conwaySequence_example2
40+
*/
41+
public function testCanExecuteExample2(): void
42+
{
43+
$this->expectExecuteOutputAnswer(
44+
__DIR__ . '/input/02 - example 2.txt',
45+
file_get_contents(__DIR__ . '/output/02 - example 2.txt')
46+
);
47+
}
48+
49+
/**
50+
* Test that the code can be executed for "Example 3".
51+
*
52+
* @group conwaySequence_example3
53+
*/
54+
public function testCanExecuteExample3(): void
55+
{
56+
$this->expectExecuteOutputAnswer(
57+
__DIR__ . '/input/03 - example 3.txt',
58+
file_get_contents(__DIR__ . '/output/03 - example 3.txt')
59+
);
60+
}
61+
62+
/**
63+
* Test that the code can be executed for "Impossible".
64+
*
65+
* @group conwaySequence_impossible
66+
*/
67+
public function testCanExecuteImpossible(): void
68+
{
69+
$this->expectExecuteOutputAnswer(
70+
__DIR__ . '/input/04 - impossible.txt',
71+
'IMPOSSIBLE' . PHP_EOL
72+
);
73+
}
74+
75+
/**
76+
* Test that the code can be executed for "Sort".
77+
*
78+
* @group conwaySequence_sort
79+
*/
80+
public function testCanExecuteSort(): void
81+
{
82+
$this->expectExecuteOutputAnswer(
83+
__DIR__ . '/input/05 - sort.txt',
84+
file_get_contents(__DIR__ . '/output/05 - sort.txt')
85+
);
86+
}
87+
88+
/**
89+
* Test that the code can be executed for "Budget limit".
90+
*
91+
* @group conwaySequence_budgetLimit
92+
*/
93+
public function testCanExecuteBudgetLimit(): void
94+
{
95+
$this->expectExecuteOutputAnswer(
96+
__DIR__ . '/input/06 - budget Limit.txt',
97+
file_get_contents(__DIR__ . '/output/06 - budget Limit.txt')
98+
);
99+
}
100+
101+
/**
102+
* Test that the code can be executed for "Several solutions budget".
103+
*
104+
* @group conwaySequence_severalSolutionsBudget
105+
*/
106+
public function testCanExecuteSeveralSolutionsBudget(): void
107+
{
108+
$this->expectExecuteOutputAnswer(
109+
__DIR__ . '/input/07 - several solutions budget.txt',
110+
file_get_contents(__DIR__ . '/output/07 - several solutions budget.txt')
111+
);
112+
}
113+
114+
/**
115+
* Test that the code can be executed for "Several solution fast".
116+
*
117+
* @group conwaySequence_severalSolutionFast
118+
*/
119+
public function testCanExecuteSeveralSolutionFast(): void
120+
{
121+
$this->expectExecuteOutputAnswer(
122+
__DIR__ . '/input/08 - several solution fast.txt',
123+
file_get_contents(__DIR__ . '/output/08 - several solution fast.txt')
124+
);
125+
}
126+
127+
/**
128+
* Test that the code can be executed for "Big random".
129+
*
130+
* @group conwaySequence_bigRandom
131+
*/
132+
public function testCanExecuteBigRandom(): void
133+
{
134+
$this->expectExecuteOutputAnswer(
135+
__DIR__ . '/input/09 - big random.txt',
136+
file_get_contents(__DIR__ . '/output/09 - big random.txt')
137+
);
138+
}
139+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
20
4+
20
5+
40
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
40
4+
40
5+
40
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
100
4+
1
5+
60
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
20
4+
20
5+
20
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
3
3+
3
4+
3
5+
3
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
10
4+
100
5+
100
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
10
3+
5
4+
10
5+
5

0 commit comments

Comments
 (0)