Skip to content

Commit fbf3711

Browse files
committed
Adding tests for "Create the longest
sequence of 1s".
1 parent 31c4d1d commit fbf3711

File tree

18 files changed

+256
-0
lines changed

18 files changed

+256
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Tests for "The electrician apprentice".
2121
- Tests for "Sudoku validator".
2222
- Tests for "Mountain map".
23+
- Tests for "Create the longest sequence of 1s".
2324

2425
## [3.6.0] - 2022-03-11
2526
### Added
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\CreateTheLongestSequenceOf1s;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Create the longest sequence of 1s" puzzle.
11+
*/
12+
class CreateTheLongestSequenceOf1s implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
$b = stream_get_line($stdin, 999 + 1, "\n");
17+
18+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
19+
20+
echo("answer\n");
21+
}
22+
}
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\Easy\CreateTheLongestSequenceOf1s;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\CreateTheLongestSequenceOf1s\CreateTheLongestSequenceOf1s;
9+
10+
/**
11+
* Tests for the "Create the longest sequence of 1s" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\CreateTheLongestSequenceOf1s\CreateTheLongestSequenceOf1s
14+
* @group createTheLongestSequenceOf1s
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new CreateTheLongestSequenceOf1s();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "2 bits".
26+
*
27+
* @group createTheLongestSequenceOf1s_2Bits
28+
*/
29+
public function testCanExecute2Bits(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - 2 bits.txt',
33+
1 . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "5 bits".
39+
*
40+
* @group createTheLongestSequenceOf1s_5Bits
41+
*/
42+
public function testCanExecute5Bits(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - 5 bits.txt',
46+
3 . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "11 bits".
52+
*
53+
* @group createTheLongestSequenceOf1s_11Bits
54+
*/
55+
public function testCanExecute11Bits(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - 11 bits.txt',
59+
8 . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "50 bits".
65+
*
66+
* @group createTheLongestSequenceOf1s_50Bits
67+
*/
68+
public function testCanExecute50Bits(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - 50 bits.txt',
72+
8 . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "100 bits".
78+
*
79+
* @group createTheLongestSequenceOf1s_100Bits
80+
*/
81+
public function testCanExecute100Bits(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - 100 bits.txt',
85+
13 . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "999 bits".
91+
*
92+
* @group createTheLongestSequenceOf1s_999Bits
93+
*/
94+
public function testCanExecute999Bits(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - 999 bits.txt',
98+
23 . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "32 bits".
104+
*
105+
* @group createTheLongestSequenceOf1s_32Bits
106+
*/
107+
public function testCanExecute32Bits(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - 32 bits.txt',
111+
6 . PHP_EOL
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "20 bits".
117+
*
118+
* @group createTheLongestSequenceOf1s_20Bits
119+
*/
120+
public function testCanExecute20Bits(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - 20 bits.txt',
124+
5 . PHP_EOL
125+
);
126+
}
127+
128+
/**
129+
* Test that the code can be executed for "Whole string".
130+
*
131+
* @group createTheLongestSequenceOf1s_wholeString
132+
*/
133+
public function testCanExecuteWholeString(): void
134+
{
135+
$this->expectExecuteOutputAnswer(
136+
__DIR__ . '/input/09 - whole string.txt',
137+
15 . PHP_EOL
138+
);
139+
}
140+
141+
/**
142+
* Test that the code can be executed for "All zeros".
143+
*
144+
* @group createTheLongestSequenceOf1s_allZeros
145+
*/
146+
public function testCanExecuteAllZeros(): void
147+
{
148+
$this->expectExecuteOutputAnswer(
149+
__DIR__ . '/input/10 - all zeros.txt',
150+
1 . PHP_EOL
151+
);
152+
}
153+
154+
/**
155+
* Test that the code can be executed for "Gaps".
156+
*
157+
* @group createTheLongestSequenceOf1s_gaps
158+
*/
159+
public function testCanExecuteGaps(): void
160+
{
161+
$this->expectExecuteOutputAnswer(
162+
__DIR__ . '/input/11 - gaps.txt',
163+
4 . PHP_EOL
164+
);
165+
}
166+
167+
/**
168+
* Test that the code can be executed for "Random 100".
169+
*
170+
* @group createTheLongestSequenceOf1s_random100
171+
*/
172+
public function testCanExecuteRandom100(): void
173+
{
174+
$this->expectExecuteOutputAnswer(
175+
__DIR__ . '/input/12 - random 100.txt',
176+
7 . PHP_EOL
177+
);
178+
}
179+
180+
/**
181+
* Test that the code can be executed for "Random 32".
182+
*
183+
* @group createTheLongestSequenceOf1s_random32
184+
*/
185+
public function testCanExecuteRandom32(): void
186+
{
187+
$this->expectExecuteOutputAnswer(
188+
__DIR__ . '/input/13 - random 32.txt',
189+
10 . PHP_EOL
190+
);
191+
}
192+
193+
/**
194+
* Test that the code can be executed for "Gaps 2".
195+
*
196+
* @group createTheLongestSequenceOf1s_gaps2
197+
*/
198+
public function testCanExecuteGaps2(): void
199+
{
200+
$this->expectExecuteOutputAnswer(
201+
__DIR__ . '/input/14 - gaps 2.txt',
202+
5 . PHP_EOL
203+
);
204+
}
205+
206+
/**
207+
* Test that the code can be executed for "Steps".
208+
*
209+
* @group createTheLongestSequenceOf1s_steps
210+
*/
211+
public function testCanExecuteSteps(): void
212+
{
213+
$this->expectExecuteOutputAnswer(
214+
__DIR__ . '/input/15 - steps.txt',
215+
12 . PHP_EOL
216+
);
217+
}
218+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
00
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01010
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11011101111
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01110100110011000101001100011110010010101011111011
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1011010111110110111001001110111011000001011010110011101101111101111111011100011001101011011110001010
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
010001100101101100111010110010111000111010011101100000001110100100000111011100110001011100011011110011010111110101100000110001011010011011000000011000101001011101101110011100000110101100001001111011000000001000110011000001111110000010111001111000100010100001100011111001111011110101000010001101101001000000001010000101010101101011101000000010101110111010100001000010011100010110111111111010001000110010010110100110011101001110001000101001111111111111011111111101110110000001001110010010110100001101010010010101011010010001111001000010100110110100011000110100101111001011111100101110001010100100010010111100101110111011010100110011010001101011000000111110011010010100010010100111000010111000100110010100110111010101111001110111011011000100110100100101010110110001000100111110000111001110100110101100011010001101001101100010110100110110011101000000111001010101100011010111110100000100000011111110000111101001001110001000100101011011000000111100000111110010011000101001001100000110110111010111011110100
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10000000011100000000011111000001

0 commit comments

Comments
 (0)