Skip to content

Commit 9d6eff9

Browse files
committed
Adding tests for "Simple fraction to mixed
number".
1 parent cb62bae commit 9d6eff9

18 files changed

+219
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- Tests for "Plight of the fellowship of the ring".
3636
- Tests for "DDCG mapper".
3737
- Tests for "Queneau numbers".
38+
- Tests for "Simple fraction to mixed number".
3839

3940
### Fixed
4041
- Tests groups for "CGFunge interpreter".
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\SimpleFractionToMixedNumber;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Simple fraction to mixed number" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/simple-fraction-to-mixed-number
12+
*/
13+
class SimpleFractionToMixedNumber implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $N);
18+
for ($i = 0; $i < $N; $i++)
19+
{
20+
fscanf($stdin, "%s", $xY);
21+
}
22+
for ($i = 0; $i < $N; $i++)
23+
{
24+
25+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
26+
27+
echo("answer\n");
28+
}
29+
}
30+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\SimpleFractionToMixedNumber;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\SimpleFractionToMixedNumber\SimpleFractionToMixedNumber;
9+
10+
/**
11+
* Tests for the "Simple fraction to mixed number" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\SimpleFractionToMixedNumber\SimpleFractionToMixedNumber
14+
* @group simpleFractionToMixedNumber
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new SimpleFractionToMixedNumber();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Both integer and fractional parts".
26+
*
27+
* @group simpleFractionToMixedNumber_bothIntegerAndFractionalParts
28+
*/
29+
public function testCanExecuteBothIntegerAndFractionalParts(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - both integer and fractional parts.txt',
33+
file_get_contents(__DIR__ . '/output/01 - both integer and fractional parts.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Integer part only".
39+
*
40+
* @group simpleFractionToMixedNumber_integerPartOnly
41+
*/
42+
public function testCanExecuteIntegerPartOnly(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - integer part only.txt',
46+
file_get_contents(__DIR__ . '/output/02 - integer part only.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Fractional part only".
52+
*
53+
* @group simpleFractionToMixedNumber_fractionalPartOnly
54+
*/
55+
public function testCanExecuteFractionalPartOnly(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - fractional part only.txt',
59+
file_get_contents(__DIR__ . '/output/03 - fractional part only.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Zero".
65+
*
66+
* @group simpleFractionToMixedNumber_zero
67+
*/
68+
public function testCanExecuteZero(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - zero.txt',
72+
file_get_contents(__DIR__ . '/output/04 - zero.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Division by zero".
78+
*
79+
* @group simpleFractionToMixedNumber_divisionByZero
80+
*/
81+
public function testCanExecuteDivisionByZero(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - division by zero.txt',
85+
"DIVISION BY ZERO" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Sign handling".
91+
*
92+
* @group simpleFractionToMixedNumber_signHandling
93+
*/
94+
public function testCanExecuteSignHandling(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - sign handling.txt',
98+
file_get_contents(__DIR__ . '/output/06 - sign handling.txt')
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Some more sign handling".
104+
*
105+
* @group simpleFractionToMixedNumber_someMoreSignHandling
106+
*/
107+
public function testCanExecuteSomeMoreSignHandling(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - some more sign handling.txt',
111+
file_get_contents(__DIR__ . '/output/07 - some more sign handling.txt')
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Several random cases".
117+
*
118+
* @group simpleFractionToMixedNumber_severalRandomCases
119+
*/
120+
public function testCanExecuteSeveralRandomCases(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - several random cases.txt',
124+
file_get_contents(__DIR__ . '/output/08 - several random cases.txt')
125+
);
126+
}
127+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
42/9
3+
71/23
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
6/3
3+
28/4
4+
105/35
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
4/6
3+
10/78
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
0/91
3+
-0/287
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
3/0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
-5/20
3+
20/-5
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
-10/-7
3+
21/-6

0 commit comments

Comments
 (0)