Skip to content

Commit efb82ab

Browse files
committed
Adding tests for "The polish dictionary".
1 parent 7593100 commit efb82ab

File tree

12 files changed

+173
-0
lines changed

12 files changed

+173
-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 "Find the replacement".
3232
- Tests for "The urinal problem".
3333
- Tests for "2×2×2 rubik’s cube movements".
34+
- Tests for "The polish dictionary".
3435

3536
## [3.16.0] - 2022-12-31
3637
### Added
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\ThePolishDictionary;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "The polish dictionary" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/the-polish-dictionary
12+
*/
13+
class ThePolishDictionary implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $N);
18+
$inputs = explode(" ", fgets($stdin));
19+
for ($i = 0; $i < $N; $i++)
20+
{
21+
$member = ($inputs[$i]);
22+
}
23+
24+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
25+
26+
echo("5 + 3\n");
27+
}
28+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\ThePolishDictionary;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\ThePolishDictionary\ThePolishDictionary;
9+
10+
/**
11+
* Tests for the "The polish dictionary" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\ThePolishDictionary\ThePolishDictionary
14+
* @group thePolishDictionary
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new ThePolishDictionary();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Simple Test".
26+
*
27+
* @group ThePolishDictionary_simpleTest
28+
*/
29+
public function testCanExecuteSimpleTest(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - simple test.txt',
33+
"5 + 3" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "No parentheses needed".
39+
*
40+
* @group ThePolishDictionary_noParenthesesNeeded
41+
*/
42+
public function testCanExecuteNoParenthesesNeeded(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - no parentheses needed.txt',
46+
"6 + 7 * 8" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Simple parentheses".
52+
*
53+
* @group ThePolishDictionary_simpleParentheses
54+
*/
55+
public function testCanExecuteSimpleParentheses(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - simple parentheses.txt',
59+
"6 - (7 + 8)" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Multiple layers".
65+
*
66+
* @group ThePolishDictionary_multipleLayers
67+
*/
68+
public function testCanExecuteMultipleLayers(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - multiple layers.txt',
72+
"(5 + 3) * 10 + 8 + 4" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Parentheses inisde other parentheses".
78+
*
79+
* @group ThePolishDictionary_parenthesesInisdeOtherParentheses
80+
*/
81+
public function testCanExecuteParenthesesInisdeOtherParentheses(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - parentheses inisde other parentheses.txt',
85+
"1 * ((8 + 6) * (3 - 4) * 2 + 5 + 5)" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Variables".
91+
*
92+
* @group ThePolishDictionary_variables
93+
*/
94+
public function testCanExecuteVariables(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - variables.txt',
98+
"apple * (3 + x)" . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Tree divisions".
104+
*
105+
* @group ThePolishDictionary_treeDivisions
106+
*/
107+
public function testCanExecuteTreeDivisions(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - tree divisions.txt',
111+
"a / b / (c / d)" . PHP_EOL
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Big test".
117+
*
118+
* @group thePolishDictionary_bigTest
119+
*/
120+
public function testCanExecuteBigTest(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - big test.txt',
124+
file_get_contents(__DIR__ . '/output/08 - big test.txt')
125+
);
126+
}
127+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
3
2+
5 3 +
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
6 7 8 * +
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
6 7 8 + -
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
9
2+
5 3 + 10 * 8 4 + +
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
15
2+
1 8 6 + 3 4 - * 2 * 5 5 + + *
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
apple 3 x + *
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
7
2+
a b / c d / /

0 commit comments

Comments
 (0)