Skip to content

Commit c8805d6

Browse files
committed
Adding tests for "1D spreadsheet".
1 parent 671f1eb commit c8805d6

29 files changed

+899
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Tests for "Dolbear's law".
1111
- Tests for "ISBN check digit".
1212
- Tests for "Equivalent resistance, circuit building".
13+
- Tests for "1D spreadsheet".
1314

1415
## [3.5.0] - 2022-02-22
1516
### 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\OneDSpreadsheet;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "1D spreadsheet" puzzle.
11+
*/
12+
class OneDSpreadsheet implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $N);
17+
for ($i = 0; $i < $N; $i++)
18+
{
19+
fscanf($stdin, "%s %s %s", $operation, $arg1, $arg2);
20+
}
21+
for ($i = 0; $i < $N; $i++)
22+
{
23+
24+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
25+
26+
echo("1\n");
27+
}
28+
}
29+
}
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\OneDSpreadsheet;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\OneDSpreadsheet\OneDSpreadsheet;
9+
10+
/**
11+
* Tests for the "1D spreadsheet" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\OneDSpreadsheet\OneDSpreadsheet
14+
* @group 1DSpreadsheet
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new OneDSpreadsheet();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Simple dependency".
26+
*
27+
* @group 1DSpreadsheet_simpleDependency
28+
*/
29+
public function testCanExecuteSimpleDependency(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - simple dependency.txt',
33+
file_get_contents(__DIR__ . '/output/01 - simple dependency.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Double dependency".
39+
*
40+
* @group 1DSpreadsheet_doubleDependency
41+
*/
42+
public function testCanExecuteDoubleDependency(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - double dependency.txt',
46+
file_get_contents(__DIR__ . '/output/02 - double dependency.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Subtraction".
52+
*
53+
* @group 1DSpreadsheet_subtraction
54+
*/
55+
public function testCanExecuteSubtraction(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - subtraction.txt',
59+
file_get_contents(__DIR__ . '/output/03 - subtraction.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Multiplication".
65+
*
66+
* @group 1DSpreadsheet_multiplication
67+
*/
68+
public function testCanExecuteMultiplication(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - multiplication.txt',
72+
file_get_contents(__DIR__ . '/output/04 - multiplication.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "No dependencies".
78+
*
79+
* @group 1DSpreadsheet_noDependencies
80+
*/
81+
public function testCanExecuteNoDependencies(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - no dependencies.txt',
85+
file_get_contents(__DIR__ . '/output/05 - no dependencies.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Coefficients".
91+
*
92+
* @group 1DSpreadsheet_coefficients
93+
*/
94+
public function testCanExecuteCoefficients(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - coefficients.txt',
98+
file_get_contents(__DIR__ . '/output/06 - coefficients.txt')
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Fibonacci".
104+
*
105+
* @group 1DSpreadsheet_fibonacci
106+
*/
107+
public function testCanExecuteFibonacci(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - fibonacci.txt',
111+
file_get_contents(__DIR__ . '/output/07 - fibonacci.txt')
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Backward dependency".
117+
*
118+
* @group 1DSpreadsheet_backwardDependency
119+
*/
120+
public function testCanExecuteBackwardDependency(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - backward dependency.txt',
124+
file_get_contents(__DIR__ . '/output/08 - backward dependency.txt')
125+
);
126+
}
127+
128+
/**
129+
* Test that the code can be executed for "Diamond dependency".
130+
*
131+
* @group 1DSpreadsheet_diamondDependency
132+
*/
133+
public function testCanExecuteDiamondDependency(): void
134+
{
135+
$this->expectExecuteOutputAnswer(
136+
__DIR__ . '/input/09 - diamond dependency.txt',
137+
file_get_contents(__DIR__ . '/output/09 - diamond dependency.txt')
138+
);
139+
}
140+
141+
/**
142+
* Test that the code can be executed for "Accounting is easy".
143+
*
144+
* @group 1DSpreadsheet_accountingIsEasy
145+
*/
146+
public function testCanExecuteAccountingIsEasy(): void
147+
{
148+
$this->expectExecuteOutputAnswer(
149+
__DIR__ . '/input/10 - accounting is easy.txt',
150+
file_get_contents(__DIR__ . '/output/10 - accounting is easy.txt')
151+
);
152+
}
153+
154+
/**
155+
* Test that the code can be executed for "Accounting is hard 1".
156+
*
157+
* @group 1DSpreadsheet_accountingIsHard1
158+
*/
159+
public function testCanExecuteAccountingIsHard1(): void
160+
{
161+
$this->expectExecuteOutputAnswer(
162+
__DIR__ . '/input/11 - accounting is hard 1.txt',
163+
file_get_contents(__DIR__ . '/output/11 - accounting is hard 1.txt')
164+
);
165+
}
166+
167+
/**
168+
* Test that the code can be executed for "Accounting is hard 2".
169+
*
170+
* @group 1DSpreadsheet_accountingIsHard2
171+
*/
172+
public function testCanExecuteAccountingIsHard2(): void
173+
{
174+
$this->expectExecuteOutputAnswer(
175+
__DIR__ . '/input/12 - accounting is hard 2.txt',
176+
file_get_contents(__DIR__ . '/output/12 - accounting is hard 2.txt')
177+
);
178+
}
179+
180+
/**
181+
* Test that the code can be executed for "Deep birecursion".
182+
*
183+
* @group 1DSpreadsheet_deepBirecursion
184+
*/
185+
public function testCanExecuteDeepBirecursion(): void
186+
{
187+
$this->expectExecuteOutputAnswer(
188+
__DIR__ . '/input/13 - deep birecursion.txt',
189+
file_get_contents(__DIR__ . '/output/13 - deep birecursion.txt')
190+
);
191+
}
192+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
VALUE 3 _
3+
ADD $0 4
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
VALUE 20 _
3+
ADD $0 100
4+
ADD $1 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
VALUE 12 _
3+
SUB $0 3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
VALUE 4 _
3+
MULT 4 $0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
ADD 1 2
3+
SUB 3 1
4+
MULT 2 4
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
7
2+
VALUE 10 _
3+
VALUE 3 _
4+
MULT $0 $1
5+
VALUE 2 _
6+
VALUE 4 _
7+
MULT $3 $4
8+
ADD $2 $5
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
9
2+
VALUE 0 _
3+
VALUE 1 _
4+
ADD $0 $1
5+
ADD $1 $2
6+
ADD $2 $3
7+
ADD $3 $4
8+
ADD $4 $5
9+
ADD $5 $6
10+
ADD $6 $7

0 commit comments

Comments
 (0)