Skip to content

Commit 7212ba8

Browse files
committed
Adding tests for "Roller coaster".
1 parent 8faec20 commit 7212ba8

9 files changed

+3149
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
### Added
9+
- Tests for "Roller coaster".
10+
711
## [2.5.0] - 2022-02-13
812
### Added
913
- Tests for "Genome sequencing".
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Training\Hard\RollerCoaster;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Roller coaster" puzzle.
11+
*/
12+
class RollerCoaster implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d %d %d", $L, $C, $N);
17+
for ($i = 0; $i < $N; $i++)
18+
{
19+
fscanf($stdin, "%d", $pi);
20+
}
21+
22+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
23+
24+
echo("answer\n");
25+
}
26+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Hard\RollerCoaster;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Hard\RollerCoaster\RollerCoaster;
9+
10+
/**
11+
* Tests for the "RollerCoaster" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Hard\RollerCoaster\RollerCoaster
14+
* @group rollerCoaster
15+
*/
16+
final class RollerCoasterTest extends PuzzleTest
17+
{
18+
public function setUp(): void
19+
{
20+
$this->puzzle = new RollerCoaster();
21+
}
22+
23+
/**
24+
* Test that the code can be executed for "Simple case".
25+
*
26+
* @group rollerCoaster_simpleCase
27+
*/
28+
public function testCanExecuteSimpleCase(): void
29+
{
30+
$this->expectExecuteOutputAnswer(
31+
__DIR__ . '/input/01 - simple case.txt',
32+
7 . PHP_EOL
33+
);
34+
}
35+
36+
/**
37+
* Test that the code can be executed for "1000 groups of a few people".
38+
*
39+
* @group rollerCoaster_1000GroupsOfAFewPeople
40+
*/
41+
public function testCanExecute1000GroupsOfAFewPeople(): void
42+
{
43+
$this->expectExecuteOutputAnswer(
44+
__DIR__ . '/input/02 - 1000 groups of a few people.txt',
45+
3935 . PHP_EOL
46+
);
47+
}
48+
49+
/**
50+
* Test that the code can be executed for "The same groups go on the ride several times during the day".
51+
*
52+
* @group rollerCoaster_theSameGroupsGoOnTheRideSeveralTimesDuringTheDay
53+
*/
54+
public function testCanExecuteTheSameGroupsGoOnTheRideSeveralTimesDuringTheDay(): void
55+
{
56+
$this->expectExecuteOutputAnswer(
57+
__DIR__ . '/input/03 - the same groups go on the ride several times during the day.txt',
58+
15 . PHP_EOL
59+
);
60+
}
61+
62+
/**
63+
* Test that the code can be executed for "All the people get on the roller coaster at least once".
64+
*
65+
* @group rollerCoaster_allThePeopleGetOnTheRollerCoasterAtLeastOnce
66+
*/
67+
public function testCanExecuteAllThePeopleGetOnTheRollerCoasterAtLeastOnce(): void
68+
{
69+
$this->expectExecuteOutputAnswer(
70+
__DIR__ . '/input/04 - all the people get on the roller coaster at least once.txt',
71+
15000 . PHP_EOL
72+
);
73+
}
74+
75+
/**
76+
* Test that the code can be executed for "High earnings during the day (> 2^32)".
77+
*
78+
* @group rollerCoaster_highEarningsduringTheDay
79+
*/
80+
public function testCanExecuteHighEarningsduringTheDay(): void
81+
{
82+
$this->expectExecuteOutputAnswer(
83+
__DIR__ . '/input/05 - high earnings during the day.txt',
84+
4999975000 . PHP_EOL
85+
);
86+
}
87+
88+
/**
89+
* Test that the code can be executed for "Works with a large dataset".
90+
*
91+
* @group rollerCoaster_worksWithALargeDataset
92+
*/
93+
public function testCanExecuteWorksWithALargeDataset(): void
94+
{
95+
$this->expectExecuteOutputAnswer(
96+
__DIR__ . '/input/06 - works with a large dataset.txt',
97+
89744892565569 . PHP_EOL
98+
);
99+
}
100+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3 3 4
2+
3
3+
1
4+
1
5+
2

0 commit comments

Comments
 (0)