Skip to content

Commit f2e29a5

Browse files
committed
Adding tests for "Temperatures".
1 parent a536824 commit f2e29a5

File tree

10 files changed

+149
-0
lines changed

10 files changed

+149
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/src/**/*.php
55
!/src/Training/Easy/ASCIIArt/ASCIIArt.php
66
!/src/Training/Easy/HorseRacingDuals/HorseRacingDuals.php
7+
!/src/Training/Easy/Temperatures/Temperatures.php
78
!/src/Training/Easy/Unary/Unary.php
89
!/src/Puzzle.php
910
/tools/

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Tests for "Unary".
10+
- Tests for "Temperatures".
1011

1112
## [1.0.0] - 2022-02-07
1213
### Added
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Training\Easy\Temperatures;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
class Temperatures extends Puzzle
10+
{
11+
// Methods :
12+
13+
public function execute($stdin): void
14+
{
15+
// $n: the number of temperatures to analyse
16+
fscanf($stdin, "%d", $n);
17+
$inputs = explode(" ", fgets($stdin));
18+
for ($i = 0; $i < $n; $i++)
19+
{
20+
$t = intval($inputs[$i]); // a temperature expressed as an integer ranging from -273 to 5526
21+
}
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("result\n");
26+
}
27+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Easy\Temperatures;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Easy\Temperatures\Temperatures;
9+
10+
/**
11+
* @coversDefaultClass \CyrilVerloop\Codingame\Training\Easy\Temperatures\Temperatures
12+
* @group temperatures
13+
*/
14+
final class TemperaturesTest extends PuzzleTest
15+
{
16+
// Methods :
17+
18+
/**
19+
* Initialises tests.
20+
*/
21+
public function setUp(): void
22+
{
23+
$this->puzzle = new Temperatures();
24+
}
25+
26+
/**
27+
* Test that the code can be executed for "Simple test case".
28+
*
29+
* @covers ::execute
30+
* @group unary_simpleTestCase
31+
*/
32+
public function testCanExecuteSimpleTestCase(): void
33+
{
34+
$this->expectExecuteOutputAnswer(
35+
__DIR__ . '/input/01 - simple test case.txt',
36+
'1' . PHP_EOL
37+
);
38+
}
39+
40+
/**
41+
* Test that the code can be executed for "Only negative numbers".
42+
*
43+
* @covers ::execute
44+
* @group unary_onlyNegativeNumbers
45+
*/
46+
public function testCanExecuteOnlyNegativeNumbers(): void
47+
{
48+
$this->expectExecuteOutputAnswer(
49+
__DIR__ . '/input/02 - only negative numbers.txt',
50+
-5 . PHP_EOL
51+
);
52+
}
53+
54+
/**
55+
* Test that the code can be executed for "Choose the right temperature".
56+
*
57+
* @covers ::execute
58+
* @group unary_chooseTheRightTemperature
59+
*/
60+
public function testCanExecuteChooseTheRightTemperature(): void
61+
{
62+
$this->expectExecuteOutputAnswer(
63+
__DIR__ . '/input/03 - choose the right temperature.txt',
64+
5 . PHP_EOL
65+
);
66+
}
67+
68+
/**
69+
* Test that the code can be executed for "Choose the right temperature 2".
70+
*
71+
* @covers ::execute
72+
* @group unary_chooseTheRightTemperature2
73+
*/
74+
public function testCanExecuteChooseTheRightTemperature2(): void
75+
{
76+
$this->expectExecuteOutputAnswer(
77+
__DIR__ . '/input/04 - choose the right temperature 2.txt',
78+
5 . PHP_EOL
79+
);
80+
}
81+
82+
/**
83+
* Test that the code can be executed for "Complex test case".
84+
*
85+
* @covers ::execute
86+
* @group unary_complexTestCase
87+
*/
88+
public function testCanExecuteComplexTestCase(): void
89+
{
90+
$this->expectExecuteOutputAnswer(
91+
__DIR__ . '/input/05 - complex test case.txt',
92+
2 . PHP_EOL
93+
);
94+
}
95+
96+
/**
97+
* Test that the code can be executed for "No temperature".
98+
*
99+
* @covers ::execute
100+
* @group unary_noTemperature
101+
*/
102+
public function testCanExecuteNoTemperature(): void
103+
{
104+
$this->expectExecuteOutputAnswer(
105+
__DIR__ . '/input/06 - no temperature.txt',
106+
0 . PHP_EOL
107+
);
108+
}
109+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
1 -2 -8 4 5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
3
2+
-12 -5 -137
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
6
2+
42 -5 12 21 5 24
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
6
2+
42 5 12 21 -5 24
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
10
2+
-5 -4 -2 12 -40 4 2 18 11 5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

0 commit comments

Comments
 (0)