Skip to content

Commit 16f947e

Browse files
committed
Adding tests for "MIME type".
1 parent 69a7bb5 commit 16f947e

13 files changed

+30156
-0
lines changed

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 "Defibrillators".
1010
- Tests for "Horse-racing duals".
11+
- Tests for "MIME type".
1112

1213
## [1.0.0] - 2022-02-26
1314
### Added
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* The "MIME type" puzzle.
3+
*/
4+
function execute(readline) {
5+
const N = parseInt(readline()); // Number of elements which make up the association table.
6+
const Q = parseInt(readline()); // Number Q of file names to be analyzed.
7+
for (let i = 0; i < N; i++) {
8+
var inputs = readline().split(' ');
9+
const EXT = inputs[0]; // file extension
10+
const MT = inputs[1]; // MIME type.
11+
}
12+
for (let i = 0; i < Q; i++) {
13+
const FNAME = readline(); // One file name per line.
14+
}
15+
16+
// Write an answer using console.log()
17+
// To debug: console.error('Debug messages...');
18+
19+
20+
// For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
21+
console.log('UNKNOWN');
22+
}
23+
24+
export { execute };
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../File.js';
4+
import { assertOutputAnswer } from '../../../assertOutputAnswer.js';
5+
import { execute } from '../../../../lib/training/easy/MIMEType/MIMEType.js';
6+
7+
/**
8+
* Tests for the "MIME type" puzzle.
9+
*/
10+
suite('MIME type', function() {
11+
const sandbox = sinon.createSandbox();
12+
13+
setup(function () {
14+
sandbox.stub(console, "log");
15+
});
16+
17+
teardown(function () {
18+
sandbox.restore();
19+
});
20+
21+
22+
test('Simple example', function() {
23+
let inputFile = new File('./test/training/easy/MIMEType/input/01 - simple example.txt');
24+
25+
execute(inputFile.readline.bind(inputFile));
26+
27+
assertOutputAnswer('./test/training/easy/MIMEType/output/01 - simple example.txt');
28+
});
29+
30+
test('Unknown MIME types', function() {
31+
let inputFile = new File('./test/training/easy/MIMEType/input/02 - unknown MIME types.txt');
32+
33+
execute(inputFile.readline.bind(inputFile));
34+
35+
assertOutputAnswer('./test/training/easy/MIMEType/output/02 - unknown MIME types.txt');
36+
});
37+
38+
test('Correct division of the extension', function() {
39+
let inputFile = new File('./test/training/easy/MIMEType/input/03 - correct division of the extension.txt');
40+
41+
execute(inputFile.readline.bind(inputFile));
42+
43+
assertOutputAnswer('./test/training/easy/MIMEType/output/03 - correct division of the extension.txt');
44+
});
45+
46+
test('Consideration of the case (upper or lower)', function() {
47+
let inputFile = new File('./test/training/easy/MIMEType/input/04 - consideration of the case (upper or lower).txt');
48+
49+
execute(inputFile.readline.bind(inputFile));
50+
51+
assertOutputAnswer('./test/training/easy/MIMEType/output/04 - consideration of the case (upper or lower).txt');
52+
});
53+
54+
test('Large dataset', function() {
55+
let inputFile = new File('./test/training/easy/MIMEType/input/05 - large dataset.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assertOutputAnswer('./test/training/easy/MIMEType/output/05 - large dataset.txt');
60+
});
61+
});
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)