Skip to content

Commit e8845b2

Browse files
committed
Adding tests for "Scrabble".
1 parent dc5ee9e commit e8845b2

12 files changed

+51074
-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
- Tests for "Conway sequence".
99
- Tests for "The gift".
10+
- Tests for "Scrabble".
1011

1112
## [2.1.0] - 2022-02-10
1213
### 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\Training\Medium\Scrabble;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Scrabble" puzzle.
11+
*/
12+
class Scrabble implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $N);
17+
for ($i = 0; $i < $N; $i++)
18+
{
19+
$W = stream_get_line($stdin, 30 + 1, "\n");
20+
}
21+
$LETTERS = stream_get_line($stdin, 7 + 1, "\n");
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("invalid word\n");
26+
}
27+
}
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\Training\Medium\Scrabble;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Medium\Scrabble\Scrabble;
9+
10+
/**
11+
* Tests for the "The gift" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Medium\Scrabble\Scrabble
14+
* @group scrabble
15+
*/
16+
final class ScrabbleTest extends PuzzleTest
17+
{
18+
public function setUp(): void
19+
{
20+
$this->puzzle = new Scrabble();
21+
}
22+
23+
/**
24+
* Test that the code can be executed for "Only one word".
25+
*
26+
* @group scrabble_onlyOneWord
27+
*/
28+
public function testCanExecuteOnlyOneWord(): void
29+
{
30+
$this->expectExecuteOutputAnswer(
31+
__DIR__ . '/input/01 - only one word.txt',
32+
'which' . PHP_EOL
33+
);
34+
}
35+
36+
/**
37+
* Test that the code can be executed for "2 words with the same value".
38+
*
39+
* @group scrabble_2WordsWithTheSameValue
40+
*/
41+
public function testCanExecute2WordsWithTheSameValue(): void
42+
{
43+
$this->expectExecuteOutputAnswer(
44+
__DIR__ . '/input/02 - 2 words with the same value.txt',
45+
'potsie' . PHP_EOL
46+
);
47+
}
48+
49+
/**
50+
* Test that the code can be executed for "2 words with different values".
51+
*
52+
* @group scrabble_2WordsWithDifferentValues
53+
*/
54+
public function testCanExecute2WordsWithDifferentValues(): void
55+
{
56+
$this->expectExecuteOutputAnswer(
57+
__DIR__ . '/input/03 - 2 words with different values.txt',
58+
'powers' . PHP_EOL
59+
);
60+
}
61+
62+
/**
63+
* Test that the code can be executed for "Many possibilities".
64+
*
65+
* @group scrabble_manyPossibilities
66+
*/
67+
public function testCanExecuteManyPossibilities(): void
68+
{
69+
$this->expectExecuteOutputAnswer(
70+
__DIR__ . '/input/04 - many possibilities.txt',
71+
'waster' . PHP_EOL
72+
);
73+
}
74+
75+
/**
76+
* Test that the code can be executed for "Value better than size".
77+
*
78+
* @group scrabble_valueBetterThanSize
79+
*/
80+
public function testCanExecuteValueBetterThanSize(): void
81+
{
82+
$this->expectExecuteOutputAnswer(
83+
__DIR__ . '/input/05 - value better than size.txt',
84+
'tween' . PHP_EOL
85+
);
86+
}
87+
88+
/**
89+
* Test that the code can be executed for "Valid word".
90+
*
91+
* @group scrabble_validWord
92+
*/
93+
public function testCanExecuteValidWord(): void
94+
{
95+
$this->expectExecuteOutputAnswer(
96+
__DIR__ . '/input/06 - valid word.txt',
97+
'aeiou' . PHP_EOL
98+
);
99+
}
100+
101+
/**
102+
* Test that the code can be executed for "Large dictionary 1".
103+
*
104+
* @group scrabble_largeDictionary1
105+
*/
106+
public function testCanExecuteLargeDictionary1(): void
107+
{
108+
$this->expectExecuteOutputAnswer(
109+
__DIR__ . '/input/07 - large dictionary 1.txt',
110+
'satire' . PHP_EOL
111+
);
112+
}
113+
114+
/**
115+
* Test that the code can be executed for "Large dictionary 2".
116+
*
117+
* @group scrabble_largeDictionary2
118+
*/
119+
public function testCanExecuteLargeDictionary2(): void
120+
{
121+
$this->expectExecuteOutputAnswer(
122+
__DIR__ . '/input/08 - large dictionary 2.txt',
123+
'pastern' . PHP_EOL
124+
);
125+
}
126+
127+
/**
128+
* Test that the code can be executed for "Cannot use letter twice".
129+
*
130+
* @group scrabble_cannotUseLetterTwice
131+
*/
132+
public function testCanExecuteCannotUseLetterTwice(): void
133+
{
134+
$this->expectExecuteOutputAnswer(
135+
__DIR__ . '/input/09 - cannot use letter twice.txt',
136+
'powers' . PHP_EOL
137+
);
138+
}
139+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
5
2+
because
3+
first
4+
these
5+
could
6+
which
7+
hicquwh
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
10
2+
some
3+
first
4+
potsie
5+
day
6+
could
7+
postie
8+
from
9+
have
10+
back
11+
this
12+
sopitez
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
10
2+
after
3+
repots
4+
user
5+
powers
6+
these
7+
time
8+
know
9+
from
10+
could
11+
people
12+
tsropwe
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
10
2+
arrest
3+
rarest
4+
raster
5+
raters
6+
sartre
7+
starer
8+
waster
9+
waters
10+
wrest
11+
wrase
12+
arwtsre
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
5
2+
entire
3+
tween
4+
soft
5+
would
6+
test
7+
etiewrn
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
5
2+
qzyoq
3+
azejuy
4+
kqjsdh
5+
aeiou
6+
qsjkdh
7+
qzaeiou

0 commit comments

Comments
 (0)