Skip to content

Commit 20d94bb

Browse files
committed
Adding tests for "Byte pair encoding".
1 parent a18f511 commit 20d94bb

File tree

13 files changed

+202
-0
lines changed

13 files changed

+202
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
- Tests for "Horse-hyperracing hyperduals".
2727
- Tests for "3×N tiling".
2828
- Tests for "Hexagonal maze - part2".
29+
- Tests for "Byte pair encoding".
2930

3031
## [3.13.0] - 2022-09-30
3132
### Added
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\BytePairEncoding;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Byte pair encoding" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/byte-pair-encoding
12+
*/
13+
class BytePairEncoding implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d %d", $n, $m);
18+
for ($i = 0; $i < $n; $i++)
19+
{
20+
fscanf($stdin, "%s", $line);
21+
}
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("answer\n");
26+
}
27+
}
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\BytePairEncoding;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\BytePairEncoding\BytePairEncoding;
9+
10+
/**
11+
* Tests for the "Byte pair encoding" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\BytePairEncoding\BytePairEncoding
14+
* @group bytePairEncoding
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new BytePairEncoding();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Test 1".
26+
*
27+
* @group bytePairEncoding_test1
28+
*/
29+
public function testCanExecuteTest1(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - test 1.txt',
33+
file_get_contents(__DIR__ . '/output/01 - test 1.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Test 2".
39+
*
40+
* @group bytePairEncoding_test2
41+
*/
42+
public function testCanExecuteTest2(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - test 2.txt',
46+
file_get_contents(__DIR__ . '/output/02 - test 2.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Test 3".
52+
*
53+
* @group bytePairEncoding_test3
54+
*/
55+
public function testCanExecuteTest3(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - test 3.txt',
59+
file_get_contents(__DIR__ . '/output/03 - test 3.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Test 4".
65+
*
66+
* @group bytePairEncoding_test4
67+
*/
68+
public function testCanExecuteTest4(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - test 4.txt',
72+
file_get_contents(__DIR__ . '/output/04 - test 4.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Test 5".
78+
*
79+
* @group bytePairEncoding_test5
80+
*/
81+
public function testCanExecuteTest5(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - test 5.txt',
85+
file_get_contents(__DIR__ . '/output/05 - test 5.txt')
86+
);
87+
}
88+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1 11
2+
aaabdaaabac
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2 10
2+
aedcaafffb
3+
ddcaaacdcd
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4 10
2+
aaaaaaaaaa
3+
aaaaabbbbb
4+
bbbbbbbbbb
5+
cccccccccc
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
10 10
2+
cdeaafdhhh
3+
cdecbfcbhf
4+
hdhhccfhed
5+
eadggchefh
6+
gcaffgdcag
7+
dfedaghgce
8+
afbdccegbf
9+
ggafhdffbh
10+
ahgadeabcc
11+
abhfgeceff
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
10 20
2+
bbhhehbhejhgeijaagjb
3+
eccfjaidghhcdjhadajb
4+
ejdffehjgbeejahcddae
5+
ciibfggbfbdifcafchcc
6+
jfaecjacccihgejjfbga
7+
acfegbhiigcfbeeibhji
8+
gighedcbcafacgcghjch
9+
cbjaiahfcaihdedijjja
10+
ffghhiabdgacafgghdai
11+
eicehcgjichccaeeafgb
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
XdXac
2+
Z = aa
3+
Y = Za
4+
X = Yb
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
aeXfffbdXacZd
2+
Z = dc
3+
Y = Za
4+
X = Ya

0 commit comments

Comments
 (0)