Skip to content

Commit 4375846

Browse files
committed
Adding tests for "The polish dictionary".
1 parent cd3ff7b commit 4375846

File tree

12 files changed

+141
-0
lines changed

12 files changed

+141
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
- Tests for "Find the replacement".
3232
- Tests for "The urinal problem".
3333
- Tests for "2×2×2 rubik’s cube movements".
34+
- Tests for "The polish dictionary".
3435

3536
## [1.16.0] - 2022-12-31
3637
### Added
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* The "The polish dictionary" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/the-polish-dictionary}
4+
*/
5+
function execute(readline) {
6+
const N = parseInt(readline());
7+
var inputs = readline().split(' ');
8+
for (let i = 0; i < N; i++) {
9+
const member = inputs[i];
10+
}
11+
12+
// Write an answer using console.log()
13+
// To debug: console.error('Debug messages...');
14+
15+
console.log('5 + 3');
16+
}
17+
18+
export { execute };
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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/community/training/medium/thePolishDictionary/thePolishDictionary.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("The polish dictionary", function() {
10+
const sandbox = sinon.createSandbox();
11+
12+
setup(function () {
13+
sandbox.stub(console, "log");
14+
});
15+
16+
teardown(function () {
17+
sandbox.restore();
18+
});
19+
20+
21+
test("Simple Test", function() {
22+
let inputFile = new File(__dirname + 'input/01 - simple test.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
"5 + 3"
29+
);
30+
});
31+
32+
test("No parentheses needed", function() {
33+
let inputFile = new File(__dirname + 'input/02 - no parentheses needed.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
"6 + 7 * 8"
40+
);
41+
});
42+
43+
test("Simple parentheses", function() {
44+
let inputFile = new File(__dirname + 'input/03 - simple parentheses.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
"6 - (7 + 8)"
51+
);
52+
});
53+
54+
test("Multiple layers", function() {
55+
let inputFile = new File(__dirname + 'input/04 - multiple layers.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
"(5 + 3) * 10 + 8 + 4"
62+
);
63+
});
64+
65+
test("Parentheses inisde other parentheses", function() {
66+
let inputFile = new File(__dirname + 'input/05 - parentheses inisde other parentheses.txt');
67+
68+
execute(inputFile.readline.bind(inputFile));
69+
70+
assert.strictEqual(
71+
console.log.getCall(0).args[0],
72+
"1 * ((8 + 6) * (3 - 4) * 2 + 5 + 5)"
73+
);
74+
});
75+
76+
test("Variables", function() {
77+
let inputFile = new File(__dirname + 'input/06 - variables.txt');
78+
79+
execute(inputFile.readline.bind(inputFile));
80+
81+
assert.strictEqual(
82+
console.log.getCall(0).args[0],
83+
"apple * (3 + x)"
84+
);
85+
});
86+
87+
test("Tree divisions", function() {
88+
let inputFile = new File(__dirname + 'input/07 - tree divisions.txt');
89+
90+
execute(inputFile.readline.bind(inputFile));
91+
92+
assert.strictEqual(
93+
console.log.getCall(0).args[0],
94+
"a / b / (c / d)"
95+
);
96+
});
97+
98+
test("Big test", function() {
99+
let inputFile = new File(__dirname + 'input/08 - big test.txt');
100+
101+
execute(inputFile.readline.bind(inputFile));
102+
103+
assertOutputAnswer(__dirname + 'output/08 - big test.txt');
104+
});
105+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
3
2+
5 3 +
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
6 7 8 * +
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
6 7 8 + -
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
9
2+
5 3 + 10 * 8 4 + +
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
15
2+
1 8 6 + 3 4 - * 2 * 5 5 + + *
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
apple 3 x + *
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
7
2+
a b / c d / /

0 commit comments

Comments
 (0)