Skip to content

Commit 8d6864e

Browse files
committed
Adding tests for "Telephone numbers".
1 parent f59ed40 commit 8d6864e

File tree

8 files changed

+10133
-0
lines changed

8 files changed

+10133
-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 "Stock exchange losses".
10+
- Tests for "Telephone numbers".
1011

1112
## [2.0.0] - 2022-02-09
1213
### Changed
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\Training\Medium\TelephoneNumbers;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Stock Exchange Losses" puzzle.
11+
*/
12+
class TelephoneNumbers implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $N);
17+
for ($i = 0; $i < $N; $i++)
18+
{
19+
fscanf($stdin, "%s", $telephone);
20+
}
21+
22+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
23+
24+
25+
// The number of elements (referencing a number) stored in the structure.
26+
echo("number\n");
27+
}
28+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Medium\TelephoneNumbers;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Medium\TelephoneNumbers\TelephoneNumbers;
9+
10+
/**
11+
* Tests for the "Telephone numbers" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Medium\TelephoneNumbers\TelephoneNumbers
14+
* @group telephoneNumbers
15+
*/
16+
final class TelephoneNumbersTest extends PuzzleTest
17+
{
18+
// Methods :
19+
20+
public function setUp(): void
21+
{
22+
$this->puzzle = new TelephoneNumbers();
23+
}
24+
25+
/**
26+
* Test that the code can be executed for "A telephone number".
27+
*
28+
* @group telephoneNumbers_aTelephoneNumber
29+
*/
30+
public function testCanExecuteATelephoneNumber(): void
31+
{
32+
$this->expectExecuteOutputAnswer(
33+
__DIR__ . '/input/01 - a telephone number.txt',
34+
10 . PHP_EOL
35+
);
36+
}
37+
38+
/**
39+
* Test that the code can be executed for "Numbers with a different base".
40+
*
41+
* @group telephoneNumbers_numbersWithADifferentBase
42+
*/
43+
public function testCanExecuteNumbersWithADifferentBase(): void
44+
{
45+
$this->expectExecuteOutputAnswer(
46+
__DIR__ . '/input/02 - numbers with a different base.txt',
47+
20 . PHP_EOL
48+
);
49+
}
50+
51+
/**
52+
* Test that the code can be executed for "Number included in another".
53+
*
54+
* @group telephoneNumbers_numberIncludedInAnother
55+
*/
56+
public function testCanExecuteNumberIncludedInAnother(): void
57+
{
58+
$this->expectExecuteOutputAnswer(
59+
__DIR__ . '/input/03 - number included in another.txt',
60+
10 . PHP_EOL
61+
);
62+
}
63+
64+
/**
65+
* Test that the code can be executed for "Numbers with a common part".
66+
*
67+
* @group telephoneNumbers_numbersWithACommonPart
68+
*/
69+
public function testCanExecuteNumbersWithACommonPart(): void
70+
{
71+
$this->expectExecuteOutputAnswer(
72+
__DIR__ . '/input/04 - numbers with a common part.txt',
73+
28 . PHP_EOL
74+
);
75+
}
76+
77+
/**
78+
* Test that the code can be executed for "Long list of numbers".
79+
*
80+
* @group telephoneNumbers_longListOfNumbers
81+
*/
82+
public function testCanExecuteLongListOfNumbers(): void
83+
{
84+
$this->expectExecuteOutputAnswer(
85+
__DIR__ . '/input/05 - long list of numbers.txt',
86+
45512 . PHP_EOL
87+
);
88+
}
89+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
0467123456
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
0123456789
3+
1123456789
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
0123456789
3+
0123
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
0412578440
3+
0412199803
4+
0468892011
5+
112
6+
15

0 commit comments

Comments
 (0)