Skip to content

Commit 4ec8fc1

Browse files
committed
Adding tests for "Ways to make change".
1 parent ecbc7f9 commit 4ec8fc1

File tree

9 files changed

+149
-0
lines changed

9 files changed

+149
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Tests for "Merlin's magic square".
2525
- Tests for "Windmill problem".
2626
- Tests for "Elementary cellular automaton".
27+
- Tests for "Ways to make change".
2728

2829
## [3.12.0] - 2022-09-01
2930
### Added
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\WaysToMakeChange;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Ways to make change" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/ways-to-make-change
12+
*/
13+
class WaysToMakeChange implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $N);
18+
fscanf($stdin, "%d", $S);
19+
$inputs = explode(" ", fgets($stdin));
20+
for ($i = 0; $i < $S; $i++)
21+
{
22+
$vi = intval($inputs[$i]);
23+
}
24+
25+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
26+
27+
echo("answer\n");
28+
}
29+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\WaysToMakeChange;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\WaysToMakeChange\WaysToMakeChange;
9+
10+
/**
11+
* Tests for the "Ways to make change" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\WaysToMakeChange\WaysToMakeChange
14+
* @group waysToMakeChange
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new WaysToMakeChange();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Small change".
26+
*
27+
* @group waysToMakeChange_smallChange
28+
*/
29+
public function testCanExecuteSmallChange(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - small change.txt',
33+
3 . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Bigger change".
39+
*
40+
* @group waysToMakeChange_biggerChange
41+
*/
42+
public function testCanExecuteBiggerChange(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - bigger change.txt',
46+
343 . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "That won't be easy !".
52+
*
53+
* @group waysToMakeChange_thatWontBeEasy
54+
*/
55+
public function testCanExecuteThatWontBeEasy(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - that won\'t be easy !.txt',
59+
0 . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Bank notes only please".
65+
*
66+
* @group waysToMakeChange_bankNotesOnlyPlease
67+
*/
68+
public function testCanExecuteBankNotesOnlyPlease(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - bank notes only please.txt',
72+
1022 . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "How am i supposed to do ?!".
78+
*
79+
* @group waysToMakeChange_howAmISupposedToDo
80+
*/
81+
public function testCanExecuteHowAmISupposedToDo(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - how am i supposed to do ?!.txt',
85+
0 . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Pushing a bit...".
91+
*
92+
* @group waysToMakeChange_pushingABit
93+
*/
94+
public function testCanExecutePushingABit(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - pushing a bit....txt',
98+
357746987 . PHP_EOL
99+
);
100+
}
101+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
10
2+
2
3+
1 5
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
100
2+
5
3+
1 5 10 20 50
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
9
2+
3
3+
5 6 10
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
300
2+
7
3+
5 10 20 50 100 200 500
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
413
2+
2
3+
5 10
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1000
2+
5
3+
1 2 3 4 5

0 commit comments

Comments
 (0)