Skip to content

Commit b48d9dc

Browse files
committed
Adding tests for "Fun with set theory".
1 parent 5bbb819 commit b48d9dc

18 files changed

+257
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- Tests for "Brackets, extended edition".
2929
- Tests for "Target firing".
3030
- Tests for "Chained matrix products".
31+
- Tests for "Fun with set theory".
3132

3233
## [3.12.0] - 2022-09-01
3334
### Added
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\FunWithSetTheory;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Fun with set theory" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/fun-with-set-theory
12+
*/
13+
class FunWithSetTheory implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
$INPUT = stream_get_line($stdin, 99 + 1, "\n");
18+
19+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
20+
21+
echo("answer\n");
22+
}
23+
}
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\FunWithSetTheory;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\FunWithSetTheory\FunWithSetTheory;
9+
10+
/**
11+
* Tests for the "Fun with set theory" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\FunWithSetTheory\FunWithSetTheory
14+
* @group funWithSetTheory
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new FunWithSetTheory();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "With braces".
26+
*
27+
* @group funWithSetTheory_withBraces
28+
*/
29+
public function testCanExecuteWithBraces(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - with braces.txt',
33+
"1 2 3" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "With brackets".
39+
*
40+
* @group funWithSetTheory_withBrackets
41+
*/
42+
public function testCanExecuteWithBrackets(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - with brackets.txt',
46+
"4 5 6 7 8 9" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Simple union".
52+
*
53+
* @group funWithSetTheory_simpleUnion
54+
*/
55+
public function testCanExecuteSimpleUnion(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - simple union.txt',
59+
"0 1 2 3 4 5" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Multiple unions".
65+
*
66+
* @group funWithSetTheory_multipleUnions
67+
*/
68+
public function testCanExecuteMultipleUnions(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - multiple unions.txt',
72+
"-2 -1 0 1 2 3 4 5 10" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Simple intersection".
78+
*
79+
* @group funWithSetTheory_simpleIntersection
80+
*/
81+
public function testCanExecuteSimpleIntersection(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - simple intersection.txt',
85+
"4" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Multiple intersections".
91+
*
92+
* @group funWithSetTheory_multipleIntersections
93+
*/
94+
public function testCanExecuteMultipleIntersections(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - multiple intersections.txt',
98+
"EMPTY" . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Simple difference".
104+
*
105+
* @group funWithSetTheory_simpleDifference
106+
*/
107+
public function testCanExecuteSimpleDifference(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - simple difference.txt',
111+
"1 3" . PHP_EOL
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Multiple differences".
117+
*
118+
* @group funWithSetTheory_multipleDifferences
119+
*/
120+
public function testCanExecuteMultipleDifferences(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - multiple differences.txt',
124+
"5 6 7 8 10" . PHP_EOL
125+
);
126+
}
127+
128+
/**
129+
* Test that the code can be executed for "Braces and brackets".
130+
*
131+
* @group funWithSetTheory_bracesAndBrackets
132+
*/
133+
public function testCanExecuteBracesAndBrackets(): void
134+
{
135+
$this->expectExecuteOutputAnswer(
136+
__DIR__ . '/input/09 - braces and brackets.txt',
137+
"8 16 20 24" . PHP_EOL
138+
);
139+
}
140+
141+
/**
142+
* Test that the code can be executed for "Empty set".
143+
*
144+
* @group funWithSetTheory_emptySet
145+
*/
146+
public function testCanExecuteEmptySet(): void
147+
{
148+
$this->expectExecuteOutputAnswer(
149+
__DIR__ . '/input/10 - empty set.txt',
150+
"EMPTY" . PHP_EOL
151+
);
152+
}
153+
154+
/**
155+
* Test that the code can be executed for "Negative numbers".
156+
*
157+
* @group funWithSetTheory_negativeNumbers
158+
*/
159+
public function testCanExecuteNegativeNumbers(): void
160+
{
161+
$this->expectExecuteOutputAnswer(
162+
__DIR__ . '/input/11 - negative numbers.txt',
163+
"-5 -2 -1" . PHP_EOL
164+
);
165+
}
166+
167+
/**
168+
* Test that the code can be executed for "Orientation of brackets".
169+
*
170+
* @group funWithSetTheory_orientationOfBrackets
171+
*/
172+
public function testCanExecuteOrientationOfBrackets(): void
173+
{
174+
$this->expectExecuteOutputAnswer(
175+
__DIR__ . '/input/12 - orientation of brackets.txt',
176+
"0 1" . PHP_EOL
177+
);
178+
}
179+
180+
/**
181+
* Test that the code can be executed for "Simple parentheses".
182+
*
183+
* @group funWithSetTheory_simpleParentheses
184+
*/
185+
public function testCanExecuteSimpleParentheses(): void
186+
{
187+
$this->expectExecuteOutputAnswer(
188+
__DIR__ . '/input/13 - simple parentheses.txt',
189+
"40 41 46 47 48 49 50" . PHP_EOL
190+
);
191+
}
192+
193+
/**
194+
* Test that the code can be executed for "Nested parentheses".
195+
*
196+
* @group funWithSetTheory_nestedParentheses
197+
*/
198+
public function testCanExecuteNestedParentheses(): void
199+
{
200+
$this->expectExecuteOutputAnswer(
201+
__DIR__ . '/input/14 - nested parentheses.txt',
202+
"46 47 48 49 50" . PHP_EOL
203+
);
204+
}
205+
206+
/**
207+
* Test that the code can be executed for "Everything!".
208+
*
209+
* @group funWithSetTheory_everything
210+
*/
211+
public function testCanExecuteEverything(): void
212+
{
213+
$this->expectExecuteOutputAnswer(
214+
__DIR__ . '/input/15 - everything!.txt',
215+
"6 7 8 9" . PHP_EOL
216+
);
217+
}
218+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{2;3;1}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[4;9]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[0;3]U[2;5]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[0;5]U{1;10}U[-2;3]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{4;5;1}I{2;4}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{1;2;3}I{2;3;4}I{4;5}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{1;2;3}-{2;50;60}

0 commit comments

Comments
 (0)