Skip to content

Commit 1b0d893

Browse files
committed
Adding tests for "MIME Type".
1 parent f2e29a5 commit 1b0d893

14 files changed

+30204
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/src/**/*.php
55
!/src/Training/Easy/ASCIIArt/ASCIIArt.php
66
!/src/Training/Easy/HorseRacingDuals/HorseRacingDuals.php
7+
!/src/Training/Easy/MIMEType/MIMEType.php
78
!/src/Training/Easy/Temperatures/Temperatures.php
89
!/src/Training/Easy/Unary/Unary.php
910
!/src/Puzzle.php

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Tests for "Unary".
1010
- Tests for "Temperatures".
11+
- Tests for "MIME Type".
1112

1213
## [1.0.0] - 2022-02-07
1314
### Added
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Training\Easy\MIMEType;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
class MIMEType extends Puzzle
10+
{
11+
// Methods :
12+
13+
public function execute($stdin): void
14+
{
15+
// $N: Number of elements which make up the association table.
16+
fscanf($stdin, "%d", $N);
17+
// $Q: Number Q of file names to be analyzed.
18+
fscanf($stdin, "%d", $Q);
19+
for ($i = 0; $i < $N; $i++)
20+
{
21+
// $EXT: file extension
22+
// $MT: MIME type.
23+
fscanf($stdin, "%s %s", $EXT, $MT);
24+
}
25+
for ($i = 0; $i < $Q; $i++)
26+
{
27+
$FNAME = stream_get_line($stdin, 256 + 1, "\n");// One file name per line.
28+
}
29+
30+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
31+
// To debug: error_log(var_export($var, true)); (equivalent to var_dump)
32+
33+
34+
// For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
35+
echo("UNKNOWN\n");
36+
}
37+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Easy\MIMEType;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Easy\MIMEType\MIMEType;
9+
10+
/**
11+
* @coversDefaultClass \CyrilVerloop\Codingame\Training\Easy\MIMEType\MIMEType
12+
* @group MIMEType
13+
*/
14+
final class MIMETypeTest extends PuzzleTest
15+
{
16+
// Methods :
17+
18+
/**
19+
* Initialises tests.
20+
*/
21+
public function setUp(): void
22+
{
23+
$this->puzzle = new MIMEType();
24+
}
25+
26+
/**
27+
* Test that the code can be executed for "Simple example".
28+
*
29+
* @covers ::execute
30+
* @group MIMEType_simpleExample
31+
*/
32+
public function testCanExecuteSimpleExample(): void
33+
{
34+
$this->expectExecuteOutputAnswer(
35+
__DIR__ . '/input/01 - simple example.txt',
36+
file_get_contents(__DIR__ . '/output/01 - simple example.txt')
37+
);
38+
}
39+
40+
/**
41+
* Test that the code can be executed for "Unknown MIME types".
42+
*
43+
* @covers ::execute
44+
* @group MIMEType_unknownMIMETypes
45+
*/
46+
public function testCanExecuteUnknownMIMETypes(): void
47+
{
48+
$this->expectExecuteOutputAnswer(
49+
__DIR__ . '/input/02 - unknown MIME types.txt',
50+
file_get_contents(__DIR__ . '/output/02 - unknown MIME types.txt')
51+
);
52+
}
53+
54+
/**
55+
* Test that the code can be executed for "Correct division of the extension".
56+
*
57+
* @covers ::execute
58+
* @group MIMEType_correctDivisionOfTheExtension
59+
*/
60+
public function testCanExecuteCorrectDivisionOfTheExtension(): void
61+
{
62+
$this->expectExecuteOutputAnswer(
63+
__DIR__ . '/input/03 - correct division of the extension.txt',
64+
file_get_contents(__DIR__ . '/output/03 - correct division of the extension.txt')
65+
);
66+
}
67+
68+
/**
69+
* Test that the code can be executed for "Consideration of the case (upper or lower)".
70+
*
71+
* @covers ::execute
72+
* @group MIMEType_considerationOfTheCase
73+
*/
74+
public function testCanExecuteConsiderationOfTheCase(): void
75+
{
76+
$this->expectExecuteOutputAnswer(
77+
__DIR__ . '/input/04 - consideration of the case (upper or lower).txt',
78+
file_get_contents(__DIR__ . '/output/04 - consideration of the case (upper or lower).txt')
79+
);
80+
}
81+
82+
/**
83+
* Test that the code can be executed for "Large dataset".
84+
*
85+
* @covers ::execute
86+
* @group MIMEType_largeDataset
87+
*/
88+
public function testCanExecuteLargeDataset(): void
89+
{
90+
$this->expectExecuteOutputAnswer(
91+
__DIR__ . '/input/05 - large dataset.txt',
92+
file_get_contents(__DIR__ . '/output/05 - large dataset.txt')
93+
);
94+
}
95+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
3
2+
3
3+
html text/html
4+
png image/png
5+
gif image/gif
6+
animated.gif
7+
portrait.png
8+
index.html
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
4
3+
txt text/plain
4+
xml text/xml
5+
flv video/x-flv
6+
image.png
7+
animated.gif
8+
script.js
9+
source.cpp
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
3
2+
11
3+
wav audio/x-wav
4+
mp3 audio/mpeg
5+
pdf application/pdf
6+
a
7+
a.wav
8+
b.wav.tmp
9+
test.vmp3
10+
pdf
11+
.pdf
12+
mp3
13+
report..pdf
14+
defaultwav
15+
.mp3.
16+
final.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
4
2+
7
3+
png image/png
4+
TIFF image/TIFF
5+
css text/css
6+
TXT text/plain
7+
example.TXT
8+
referecnce.txt
9+
strangename.tiff
10+
resolv.CSS
11+
matrix.TiFF
12+
lanDsCape.Png
13+
extract.cSs

0 commit comments

Comments
 (0)