Skip to content

Commit dc1deb6

Browse files
committed
Adding tests for "How time flies".
1 parent 15bff9d commit dc1deb6

File tree

12 files changed

+183
-0
lines changed

12 files changed

+183
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- Tests for "Artificial emotional intelligence".
3030
- Tests for "Park pilot".
3131
- Tests for "Buzzle".
32+
- Tests for "How time flies".
3233

3334
### Changed
3435
- Renaming "Linear Bézier curves" to "Cubic Bézier curves".
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\HowTimeFlies;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "How time flies" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/how-time-flies
12+
*/
13+
class HowTimeFlies implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%s", $BEGIN);
18+
fscanf($stdin, "%s", $END);
19+
20+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
21+
22+
echo("YY year[s], MM month[s], total NN days\n");
23+
}
24+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\HowTimeFlies;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\HowTimeFlies\HowTimeFlies;
9+
10+
/**
11+
* Tests for the "How time flies" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\HowTimeFlies\HowTimeFlies
14+
* @group howTimeFlies
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new HowTimeFlies();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Full years".
26+
*
27+
* @group howTimeFlies_fullYears
28+
*/
29+
public function testCanExecuteFullYears(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - full years.txt',
33+
"16 years, total 5844 days" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Full months".
39+
*
40+
* @group howTimeFlies_fullMonths
41+
*/
42+
public function testCanExecuteFullMonths(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - full months.txt',
46+
"7 months, total 213 days" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Years and months".
52+
*
53+
* @group howTimeFlies_yearsAndMonths
54+
*/
55+
public function testCanExecuteYearsAndMonths(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - years and months.txt',
59+
"1 year, 3 months, total 458 days" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Days only".
65+
*
66+
* @group howTimeFlies_daysOnly
67+
*/
68+
public function testCanExecuteDaysOnly(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - days only.txt',
72+
"total 30 days" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Same date".
78+
*
79+
* @group howTimeFlies_sameDate
80+
*/
81+
public function testCanExecuteSameDate(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - same date.txt',
85+
"total 0 days" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Complex".
91+
*
92+
* @group howTimeFlies_complex
93+
*/
94+
public function testCanExecuteComplex(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - complex.txt',
98+
"3 years, 1 month, total 1140 days" . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "One month".
104+
*
105+
* @group howTimeFlies_oneMonth
106+
*/
107+
public function testCanExecuteOneMonth(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - one month.txt',
111+
"1 month, total 31 days" . PHP_EOL
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "One year".
117+
*
118+
* @group howTimeFlies_oneYear
119+
*/
120+
public function testCanExecuteOneYear(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - one year.txt',
124+
"1 year, total 365 days" . PHP_EOL
125+
);
126+
}
127+
128+
/**
129+
* Test that the code can be executed for "Leap year".
130+
*
131+
* @group howTimeFlies_leapYear
132+
*/
133+
public function testCanExecuteLeapYear(): void
134+
{
135+
$this->expectExecuteOutputAnswer(
136+
__DIR__ . '/input/09 - leap year.txt',
137+
"1 year, total 366 days" . PHP_EOL
138+
);
139+
}
140+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
01.01.2000
2+
01.01.2016
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
01.01.2016
2+
01.08.2016
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
01.11.2015
2+
01.02.2017
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
17.12.2016
2+
16.01.2017
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
01.01.2016
2+
01.01.2016
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
28.02.2015
2+
13.04.2018
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
28.01.2015
2+
28.02.2015

0 commit comments

Comments
 (0)