Skip to content

Commit f59ed40

Browse files
committed
Adding tests for "Stock exchange losses".
1 parent 1dff970 commit f59ed40

File tree

9 files changed

+145
-0
lines changed

9 files changed

+145
-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 "Stock exchange losses".
10+
711
## [2.0.0] - 2022-02-09
812
### Changed
913
- Using "*.dist" files as default PHP templates.
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\Medium\StockExchangeLosses;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Stock Exchange Losses" puzzle.
11+
*/
12+
class StockExchangeLosses implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf(STDIN, "%d", $n);
17+
$inputs = explode(" ", fgets(STDIN));
18+
for ($i = 0; $i < $n; $i++)
19+
{
20+
$v = intval($inputs[$i]);
21+
}
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("answer\n");
26+
}
27+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Medium\StockExchangeLosses;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Medium\StockExchangeLosses\StockExchangeLosses;
9+
10+
/**
11+
* Tests for the "Stock Exchange Losses" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Medium\StockExchangeLosses\StockExchangeLosses
14+
* @group stockExchangeLosses
15+
*/
16+
final class StockExchangeLossesTest extends PuzzleTest
17+
{
18+
// Methods :
19+
20+
public function setUp(): void
21+
{
22+
$this->puzzle = new StockExchangeLosses();
23+
}
24+
25+
/**
26+
* Test that the code can be executed for "First case".
27+
*
28+
* @group stockExchangeLosses_firstCase
29+
*/
30+
public function testCanExecuteSimpleAddition(): void
31+
{
32+
$this->expectExecuteOutputAnswer(
33+
__DIR__ . '/input/01 - first case.txt',
34+
-3 . PHP_EOL
35+
);
36+
}
37+
38+
/**
39+
* Test that the code can be executed for "Maximum loss between the first and last values".
40+
*
41+
* @group stockExchangeLosses_maximumLoss
42+
*/
43+
public function testCanExecuteMaximumLoss(): void
44+
{
45+
$this->expectExecuteOutputAnswer(
46+
__DIR__ . '/input/02 - maximum loss.txt',
47+
-4 . PHP_EOL
48+
);
49+
}
50+
51+
/**
52+
* Test that the code can be executed for "Profit".
53+
*
54+
* @group stockExchangeLosses_profit
55+
*/
56+
public function testCanExecuteProfit(): void
57+
{
58+
$this->expectExecuteOutputAnswer(
59+
__DIR__ . '/input/03 - profit.txt',
60+
0 . PHP_EOL
61+
);
62+
}
63+
64+
/**
65+
* Test that the code can be executed for "Profit 2".
66+
*
67+
* @group stockExchangeLosses_profit2
68+
*/
69+
public function testCanExecuteProfit2(): void
70+
{
71+
$this->expectExecuteOutputAnswer(
72+
__DIR__ . '/input/04 - profit 2.txt',
73+
0 . PHP_EOL
74+
);
75+
}
76+
77+
/**
78+
* Test that the code can be executed for "Large dataset".
79+
*
80+
* @group stockExchangeLosses_largeDataset
81+
*/
82+
public function testCanExecuteLargeDataset(): void
83+
{
84+
$this->expectExecuteOutputAnswer(
85+
__DIR__ . '/input/05 - large dataset.txt',
86+
-1073730311 . PHP_EOL
87+
);
88+
}
89+
90+
/**
91+
* Test that the code can be executed for "Varied".
92+
*
93+
* @group stockExchangeLosses_varied
94+
*/
95+
public function testCanExecuteVaried(): void
96+
{
97+
$this->expectExecuteOutputAnswer(
98+
__DIR__ . '/input/06 - varied.txt',
99+
-3 . PHP_EOL
100+
);
101+
}
102+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
6
2+
3 2 4 2 1 5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
6
2+
5 3 4 2 3 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
1 2 4 4 5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
3 4 7 9 10

tests/Training/Medium/StockExchangeLosses/input/05 - large dataset.txt

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
6
2+
3 2 10 7 15 14

0 commit comments

Comments
 (0)