Skip to content

Commit 969b775

Browse files
committed
Adding tests for "Rod cutting problem".
1 parent 21ce083 commit 969b775

File tree

9 files changed

+252
-0
lines changed

9 files changed

+252
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- Tests for "Hexagonal maze - part2".
2929
- Tests for "Byte pair encoding".
3030
- Tests for "Find the missing plus signs in addition".
31+
- Tests for "Rod cutting problem".
3132

3233
## [3.13.0] - 2022-09-30
3334
### Added
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\RodCuttingProblem;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Rod cutting problem" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/rod-cutting-problem
12+
*/
13+
class RodCuttingProblem implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $L);
18+
fscanf($stdin, "%d", $N);
19+
for ($i = 0; $i < $N; $i++)
20+
{
21+
fscanf($stdin, "%d %d", $length, $value);
22+
}
23+
24+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
25+
26+
echo("0\n");
27+
}
28+
}
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\RodCuttingProblem;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\RodCuttingProblem\RodCuttingProblem;
9+
10+
/**
11+
* Tests for the "Rod cutting problem" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\RodCuttingProblem\RodCuttingProblem
14+
* @group rodCuttingProblem
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new RodCuttingProblem();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Example test".
26+
*
27+
* @group rodCuttingProblem_exampleTest
28+
*/
29+
public function testCanExecuteExampleTest(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - example test.txt',
33+
10 . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Same pieces but longer rod".
39+
*
40+
* @group rodCuttingProblem_samePiecesButLongerRod
41+
*/
42+
public function testCanExecuteSamePiecesButLongerRod(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - same pieces but longer rod.txt',
46+
32 . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "More pieces".
52+
*
53+
* @group rodCuttingProblem_morePieces
54+
*/
55+
public function testCanExecuteMorePieces(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - more pieces.txt',
59+
42 . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Big pieces".
65+
*
66+
* @group rodCuttingProblem_bigPieces
67+
*/
68+
public function testCanExecuteBigPieces(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - big pieces.txt',
72+
20 . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Many pieces".
78+
*
79+
* @group rodCuttingProblem_manyPieces
80+
*/
81+
public function testCanExecuteManyPieces(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - many pieces.txt',
85+
1152 . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Huge rod".
91+
*
92+
* @group rodCuttingProblem_hugeRod
93+
*/
94+
public function testCanExecuteHugePieces(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - huge rod.txt',
98+
11538 . PHP_EOL
99+
);
100+
}
101+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
4
2+
4
3+
1 1
4+
2 5
5+
3 8
6+
4 9
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
12
2+
4
3+
1 1
4+
2 5
5+
3 8
6+
4 9
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
15
2+
8
3+
1 1
4+
2 5
5+
3 8
6+
4 9
7+
5 10
8+
6 17
9+
7 17
10+
8 20
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
19
2+
4
3+
7 7
4+
11 13
5+
13 14
6+
23 15
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
1000
2+
45
3+
1 0
4+
2 1
5+
3 1
6+
5 4
7+
8 7
8+
13 15
9+
21 24
10+
34 36
11+
55 59
12+
89 97
13+
144 152
14+
233 240
15+
377 379
16+
610 611
17+
987 997
18+
1597 1607
19+
2584 2586
20+
4181 4188
21+
6765 6774
22+
10946 10946
23+
17711 17714
24+
28657 28662
25+
46368 46376
26+
75025 75032
27+
121393 121402
28+
196418 196419
29+
317811 317818
30+
514229 514230
31+
832040 832040
32+
1346269 1346279
33+
2178309 2178317
34+
3524578 3524584
35+
5702887 5702895
36+
9227465 9227475
37+
14930352 14930355
38+
24157817 24157819
39+
39088169 39088177
40+
63245986 63245992
41+
102334155 102334163
42+
165580141 165580144
43+
267914296 267914300
44+
433494437 433494438
45+
701408733 701408740
46+
1134903170 1134903179
47+
1836311903 1836311913
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
10000
2+
45
3+
1 0
4+
2 1
5+
3 1
6+
5 4
7+
8 7
8+
13 15
9+
21 24
10+
34 36
11+
55 59
12+
89 97
13+
144 152
14+
233 240
15+
377 379
16+
610 611
17+
987 997
18+
1597 1607
19+
2584 2586
20+
4181 4188
21+
6765 6774
22+
10946 10946
23+
17711 17714
24+
28657 28662
25+
46368 46376
26+
75025 75032
27+
121393 121402
28+
196418 196419
29+
317811 317818
30+
514229 514230
31+
832040 832040
32+
1346269 1346279
33+
2178309 2178317
34+
3524578 3524584
35+
5702887 5702895
36+
9227465 9227475
37+
14930352 14930355
38+
24157817 24157819
39+
39088169 39088177
40+
63245986 63245992
41+
102334155 102334163
42+
165580141 165580144
43+
267914296 267914300
44+
433494437 433494438
45+
701408733 701408740
46+
1134903170 1134903179
47+
1836311903 1836311913

0 commit comments

Comments
 (0)