Skip to content

Commit 21ce083

Browse files
committed
Adding tests for "Find the missing plus
signs in addition".
1 parent 20d94bb commit 21ce083

File tree

9 files changed

+131
-0
lines changed

9 files changed

+131
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
- Tests for "3×N tiling".
2828
- Tests for "Hexagonal maze - part2".
2929
- Tests for "Byte pair encoding".
30+
- Tests for "Find the missing plus signs in addition".
3031

3132
## [3.13.0] - 2022-09-30
3233
### Added
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\FindTheMissingPlusSignsInAddition;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Find the missing plus signs in addition" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/find-the-missing-plus-signs-in-addition
12+
*/
13+
class FindTheMissingPlusSignsInAddition implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $N);
18+
fscanf($stdin, "%d", $S);
19+
$O = stream_get_line($stdin, 100 + 1, "\n");
20+
21+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
22+
23+
echo("No solution or recovered addition(s)\n");
24+
}
25+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\FindTheMissingPlusSignsInAddition;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\FindTheMissingPlusSignsInAddition\FindTheMissingPlusSignsInAddition;
9+
10+
/**
11+
* Tests for the "Find the missing plus signs in addition" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\FindTheMissingPlusSignsInAddition\FindTheMissingPlusSignsInAddition
14+
* @group findTheMissingPlusSignsInAddition
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new FindTheMissingPlusSignsInAddition();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Example with unique solution".
26+
*
27+
* @group findTheMissingPlusSignsInAddition_exampleWithUniqueSolution
28+
*/
29+
public function testCanExecuteExampleWithUniqueSolution(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - example with unique solution.txt',
33+
"44+133=177" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "No solution there".
39+
*
40+
* @group findTheMissingPlusSignsInAddition_noSolutionThere
41+
*/
42+
public function testCanExecuteNoSolutionThere(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - no solution there.txt',
46+
"No solution" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "More than one solution".
52+
*
53+
* @group findTheMissingPlusSignsInAddition_moreThanOneSolution
54+
*/
55+
public function testCanExecuteMoreThanOneSolution(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - more than one solution.txt',
59+
file_get_contents(__DIR__ . '/output/03 - more than one solution.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Ten terms".
65+
*
66+
* @group findTheMissingPlusSignsInAddition_tenTerms
67+
*/
68+
public function testCanExecuteTenTerms(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - ten terms.txt',
72+
"48+113+19+189+25+37+72+81+212+17=813" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "59 digits in O".
78+
*
79+
* @group findTheMissingPlusSignsInAddition_59DigitsInO
80+
*/
81+
public function testCanExecute59DigitsInO(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - 59 digits in O.txt',
85+
"964510623+54170+987541234+7772451+246+94514215+159874623+432158796=2646426358" . PHP_EOL
86+
);
87+
}
88+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
177
3+
44133
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
35
3+
1313
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
6
2+
678
3+
24261236141232
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
10
2+
813
3+
48113191892537728121217
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
8
2+
2646426358
3+
96451062354170987541234777245124694514215159874623432158796
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
24+26+123+61+412+32=678
2+
242+61+236+14+123+2=678

0 commit comments

Comments
 (0)