Skip to content

Commit 5d67ad2

Browse files
committed
Adding tests for "Rectangle partition".
1 parent c1e0414 commit 5d67ad2

File tree

12 files changed

+199
-0
lines changed

12 files changed

+199
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Tests for "Container terminal".
10+
- Tests for "Rectangle partition".
1011

1112
## [3.1.0] - 2022-02-17
1213
### Added
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\RectanglePartition;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Rectangle partition" puzzle.
11+
*/
12+
class RectanglePartition implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d %d %d %d", $w, $h, $countX, $countY);
17+
$inputs = explode(" ", fgets($stdin));
18+
for ($i = 0; $i < $countX; $i++)
19+
{
20+
$x = intval($inputs[$i]);
21+
}
22+
$inputs = explode(" ", fgets($stdin));
23+
for ($i = 0; $i < $countY; $i++)
24+
{
25+
$y = intval($inputs[$i]);
26+
}
27+
28+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
29+
30+
echo("0\n");
31+
}
32+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\RectanglePartition;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\RectanglePartition\RectanglePartition;
9+
10+
/**
11+
* Tests for the "Rectangle partition" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\RectanglePartition\RectanglePartition
14+
* @group rectanglePartition
15+
*/
16+
final class CGTest extends PuzzleTest
17+
{
18+
public function setUp(): void
19+
{
20+
$this->puzzle = new RectanglePartition();
21+
}
22+
23+
/**
24+
* Test that the code can be executed for "Sample".
25+
*
26+
* @group rectanglePartition_sample
27+
*/
28+
public function testCanExecuteSample(): void
29+
{
30+
$this->expectExecuteOutputAnswer(
31+
__DIR__ . '/input/01 - sample.txt',
32+
4 . PHP_EOL
33+
);
34+
}
35+
36+
/**
37+
* Test that the code can be executed for "Squarish".
38+
*
39+
* @group rectanglePartition_squarish
40+
*/
41+
public function testCanExecuteSquarish(): void
42+
{
43+
$this->expectExecuteOutputAnswer(
44+
__DIR__ . '/input/02 - squarish.txt',
45+
14 . PHP_EOL
46+
);
47+
}
48+
49+
/**
50+
* Test that the code can be executed for "Bigger 1".
51+
*
52+
* @group rectanglePartition_bigger1
53+
*/
54+
public function testCanExecuteBigger1(): void
55+
{
56+
$this->expectExecuteOutputAnswer(
57+
__DIR__ . '/input/03 - bigger 1.txt',
58+
123 . PHP_EOL
59+
);
60+
}
61+
62+
/**
63+
* Test that the code can be executed for "Bigger 2".
64+
*
65+
* @group rectanglePartition_bigger2
66+
*/
67+
public function testCanExecuteBigger2(): void
68+
{
69+
$this->expectExecuteOutputAnswer(
70+
__DIR__ . '/input/04 - bigger 2.txt',
71+
36 . PHP_EOL
72+
);
73+
}
74+
75+
/**
76+
* Test that the code can be executed for "Lo-density 1".
77+
*
78+
* @group rectanglePartition_loDensity1
79+
*/
80+
public function testCanExecuteLoDensity1(): void
81+
{
82+
$this->expectExecuteOutputAnswer(
83+
__DIR__ . '/input/05 - lo-density 1.txt',
84+
25 . PHP_EOL
85+
);
86+
}
87+
88+
/**
89+
* Test that the code can be executed for "Lo-density 2".
90+
*
91+
* @group rectanglePartition_loDensity2
92+
*/
93+
public function testCanExecuteLoDensity2(): void
94+
{
95+
$this->expectExecuteOutputAnswer(
96+
__DIR__ . '/input/06 - lo-density 2.txt',
97+
0 . PHP_EOL
98+
);
99+
}
100+
101+
/**
102+
* Test that the code can be executed for "Hi-density 1".
103+
*
104+
* @group rectanglePartition_hiDensity1
105+
*/
106+
public function testCanExecuteHiDensity1(): void
107+
{
108+
$this->expectExecuteOutputAnswer(
109+
__DIR__ . '/input/07 - hi-density 1.txt',
110+
22281 . PHP_EOL
111+
);
112+
}
113+
114+
/**
115+
* Test that the code can be executed for "Hi-density 2".
116+
*
117+
* @group rectanglePartition_hiDensity2
118+
*/
119+
public function testCanExecuteHiDensity2(): void
120+
{
121+
$this->expectExecuteOutputAnswer(
122+
__DIR__ . '/input/08 - hi-density 2.txt',
123+
18431 . PHP_EOL
124+
);
125+
}
126+
127+
/**
128+
* Test that the code can be executed for "Imbalance".
129+
*
130+
* @group rectanglePartition_imbalance
131+
*/
132+
public function testCanExecuteImbalance(): void
133+
{
134+
$this->expectExecuteOutputAnswer(
135+
__DIR__ . '/input/09 - imbalance.txt',
136+
42 . PHP_EOL
137+
);
138+
}
139+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
10 5 2 1
2+
2 5
3+
3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
9 9 2 2
2+
3 6
3+
3 6
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
200 100 20 10
2+
11 25 26 29 30 40 44 56 65 71 87 98 100 108 130 149 153 161 173 179
3+
1 11 16 17 19 37 38 53 65 69
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
800 1000 15 20
2+
36 116 145 146 163 172 173 182 279 337 371 631 695 705 772
3+
86 95 103 319 336 362 370 382 445 519 522 657 707 811 842 866 881 895 918 930
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
12000 13000 36 25
2+
317 416 455 914 1333 1488 2216 2739 3070 3755 4012 4509 5008 5107 5408 5828 5836 5926 6339 6448 6707 7305 7497 7531 8175 9104 9518 9566 9570 9713 9831 10003 10062 10843 11216 11495
3+
734 2236 2287 3240 4185 4215 4609 4787 5619 5874 6667 6744 7379 7936 8989 9645 9649 9664 10088 10103 10710 11062 11267 12932 12979
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
20000 19990 3 4
2+
8393 13715 13752
3+
7017 8582 16500 19518
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
10000 9000 123 201
2+
1 14 79 126 390 506 573 690 747 778 798 887 896 907 912 1026 1122 1172 1193 1223 1380 1557 1693 1759 1840 2050 2063 2279 2321 2332 2396 2468 2514 2664 2803 2813 2823 2886 2913 3131 3363 3426 3580 3583 3780 3979 3981 4014 4102 4198 4284 4355 4666 4693 4708 4718 4926 5055 5094 5121 5292 5298 5299 5372 5406 5532 5634 5800 5801 5835 5838 5851 5875 6183 6305 6358 6359 6433 6479 6589 6600 6609 6635 6766 6774 6906 6940 6957 6978 7004 7008 7086 7226 7413 7442 7525 7536 7573 7625 7693 7721 8004 8113 8252 8300 8303 8385 8390 8523 8526 8688 8733 8766 9027 9075 9170 9196 9198 9223 9331 9497 9910 9945
3+
59 60 63 128 132 146 183 249 270 303 380 387 467 606 643 663 682 707 728 734 799 851 1019 1078 1105 1116 1122 1126 1167 1237 1327 1402 1436 1439 1635 1674 1718 1751 1817 1864 1865 1871 1921 1995 2001 2085 2089 2214 2274 2282 2399 2442 2443 2447 2564 2569 2577 2875 2937 2988 2992 3017 3121 3162 3202 3216 3226 3228 3259 3416 3426 3443 3475 3795 3852 3879 3920 3993 4038 4039 4052 4137 4207 4243 4248 4251 4270 4328 4346 4354 4369 4379 4389 4396 4413 4426 4477 4491 4501 4508 4531 4533 4544 4659 4666 4720 4769 4846 4877 4977 5036 5143 5254 5348 5416 5425 5452 5468 5523 5580 5601 5611 5613 5620 5714 5722 5724 5748 5759 5794 5803 5927 5979 6042 6101 6115 6168 6177 6184 6230 6269 6336 6343 6416 6428 6709 6756 6786 6813 6895 6919 6945 6971 7099 7114 7142 7179 7241 7267 7381 7401 7412 7416 7422 7427 7456 7514 7519 7533 7555 7577 7597 7735 7739 7745 7777 7780 7859 7913 7917 7948 7984 7999 8000 8035 8051 8071 8143 8155 8228 8392 8480 8490 8575 8653 8677 8731 8754 8830 8867 8887

0 commit comments

Comments
 (0)