Skip to content

Commit f8549fb

Browse files
committed
Adding tests for "Advanced tree".
1 parent d230e29 commit f8549fb

39 files changed

+596
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- Tests for "Vote counting".
3737
- Tests for "Maze for the champions".
3838
- Tests for "Longest increasing subsequence".
39+
- Tests for "Advanced tree".
3940

4041
## [1.16.0] - 2022-12-31
4142
### Added
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The "Advanced tree" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/advanced-tree}
4+
*/
5+
function execute(readline) {
6+
const S = readline();
7+
const F = readline();
8+
const N = parseInt(readline());
9+
for (let i = 0; i < N; i++) {
10+
const line = readline();
11+
}
12+
13+
// Write an answer using console.log()
14+
// To debug: console.error('Debug messages...');
15+
16+
console.log('Tree output');
17+
}
18+
19+
export { execute };
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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/advancedTree/advancedTree.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("Advanced tree", 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("Example", function() {
22+
let inputFile = new File(__dirname + 'input/01 - example.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assertOutputAnswer(__dirname + 'output/01 - example.txt');
27+
});
28+
29+
test("In a directory test", function() {
30+
let inputFile = new File(__dirname + 'input/02 - in a directory test.txt');
31+
32+
execute(inputFile.readline.bind(inputFile));
33+
34+
assertOutputAnswer(__dirname + 'output/02 - in a directory test.txt');
35+
});
36+
37+
test("Also in a directory test", function() {
38+
let inputFile = new File(__dirname + 'input/03 - also in a directory test.txt');
39+
40+
execute(inputFile.readline.bind(inputFile));
41+
42+
assertOutputAnswer(__dirname + 'output/03 - also in a directory test.txt');
43+
});
44+
45+
test("Gap end of tree handling test", function() {
46+
let inputFile = new File(__dirname + 'input/04 - gap end of tree handling test.txt');
47+
48+
execute(inputFile.readline.bind(inputFile));
49+
50+
assertOutputAnswer(__dirname + 'output/04 - gap end of tree handling test.txt');
51+
});
52+
53+
test("Hidden directories w/o -a test", function() {
54+
let inputFile = new File(__dirname + 'input/05 - hidden directories wo -a test.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assertOutputAnswer(__dirname + 'output/05 - hidden directories wo -a test.txt');
59+
});
60+
61+
test("Dots in filenames test", function() {
62+
let inputFile = new File(__dirname + 'input/06 - dots in filenames test.txt');
63+
64+
execute(inputFile.readline.bind(inputFile));
65+
66+
assertOutputAnswer(__dirname + 'output/06 - dots in filenames test.txt');
67+
});
68+
69+
test("Limit flag test", function() {
70+
let inputFile = new File(__dirname + 'input/07 - limit flag test.txt');
71+
72+
execute(inputFile.readline.bind(inputFile));
73+
74+
assertOutputAnswer(__dirname + 'output/07 - limit flag test.txt');
75+
});
76+
77+
test("Hidden files w/o -a test", function() {
78+
let inputFile = new File(__dirname + 'input/08 - hidden files wo -a test.txt');
79+
80+
execute(inputFile.readline.bind(inputFile));
81+
82+
assertOutputAnswer(__dirname + 'output/08 - hidden files wo -a test.txt');
83+
});
84+
85+
test("Hidden files with -a test", function() {
86+
let inputFile = new File(__dirname + 'input/09 - hidden files with -a test.txt');
87+
88+
execute(inputFile.readline.bind(inputFile));
89+
90+
assertOutputAnswer(__dirname + 'output/09 - hidden files with -a test.txt');
91+
});
92+
93+
test("Directory flag test", function() {
94+
let inputFile = new File(__dirname + 'input/10 - directory flag test.txt');
95+
96+
execute(inputFile.readline.bind(inputFile));
97+
98+
assertOutputAnswer(__dirname + 'output/10 - directory flag test.txt');
99+
});
100+
101+
test("Multiple flags test", function() {
102+
let inputFile = new File(__dirname + 'input/11 - multiple flags test.txt');
103+
104+
execute(inputFile.readline.bind(inputFile));
105+
106+
assertOutputAnswer(__dirname + 'output/11 - multiple flags test.txt');
107+
});
108+
109+
test("All flags test", function() {
110+
let inputFile = new File(__dirname + 'input/12 - all flags test.txt');
111+
112+
execute(inputFile.readline.bind(inputFile));
113+
114+
assertOutputAnswer(__dirname + 'output/12 - all flags test.txt');
115+
});
116+
117+
test("Error handling 1 test", function() {
118+
let inputFile = new File(__dirname + 'input/13 - error handling 1 test.txt');
119+
120+
execute(inputFile.readline.bind(inputFile));
121+
122+
assertOutputAnswer(__dirname + 'output/13 - error handling 1 test.txt');
123+
});
124+
125+
test("Error handling 2 test", function() {
126+
let inputFile = new File(__dirname + 'input/14 - error handling 2 test.txt');
127+
128+
execute(inputFile.readline.bind(inputFile));
129+
130+
assertOutputAnswer(__dirname + 'output/14 - error handling 2 test.txt');
131+
});
132+
133+
test("Error handling 3 test", function() {
134+
let inputFile = new File(__dirname + 'input/15 - error handling 3 test.txt');
135+
136+
execute(inputFile.readline.bind(inputFile));
137+
138+
assertOutputAnswer(__dirname + 'output/15 - error handling 3 test.txt');
139+
});
140+
141+
test("Wrong flag test", function() {
142+
let inputFile = new File(__dirname + 'input/16 - wrong flag test.txt');
143+
144+
execute(inputFile.readline.bind(inputFile));
145+
146+
assertOutputAnswer(__dirname + 'output/16 - wrong flag test.txt');
147+
});
148+
149+
test("Big test 1", function() {
150+
let inputFile = new File(__dirname + 'input/17 - big test 1.txt');
151+
152+
execute(inputFile.readline.bind(inputFile));
153+
154+
assertOutputAnswer(__dirname + 'output/17 - big test 1.txt');
155+
});
156+
157+
test("Not starting in .", function() {
158+
let inputFile = new File(__dirname + 'input/18 - not starting in.txt');
159+
160+
execute(inputFile.readline.bind(inputFile));
161+
162+
assertOutputAnswer(__dirname + 'output/18 - not starting in.txt');
163+
});
164+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.
2+
3+
6
4+
./Directory1/File1
5+
./Directory1/File2
6+
./Directory2/File3
7+
./Directory1/File4
8+
./Directory2/Directory3/File5
9+
./File6
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
./Directory1
2+
3+
6
4+
./Directory1/File1
5+
./Directory1/File2
6+
./Directory2/File3
7+
./Directory1/File4
8+
./Directory2/Directory3/File5
9+
./File6
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Directory1
2+
3+
6
4+
./Directory1/File1
5+
./Directory1/File2
6+
./Directory2/File3
7+
./Directory1/File4
8+
./Directory2/Directory3/File5
9+
./File6
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.
2+
3+
10
4+
./Directory1/File1
5+
./Directory2/File2
6+
./Directory3/File4
7+
./Directory3/File3
8+
./Directory4/Directory5/File5
9+
./Directory4/Directory5/File6
10+
./Directory6/File7
11+
./Directory6/File8
12+
./Directory6/Test/File10
13+
./Directory6/Test/File9
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.
2+
3+
7
4+
./Directory1/File1
5+
./Directory2/File2
6+
./Directory2/File3
7+
./.Directory3/File4
8+
./Directory4/File5
9+
./Directory4/File6
10+
./Directory4/.Directory5/File7
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.
2+
-a
3+
7
4+
./Directory1/File1.txt
5+
./Directory1/File2.js
6+
./Directory2/File3.rb
7+
./Directory2/File4.cpp
8+
./.Directory3/Directory4/.File5.c
9+
./.Directory3/Directory4/File6.py
10+
./File7
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.
2+
-L 2
3+
6
4+
./Directory1/File1
5+
./Directory1/File2
6+
./Directory2/File3
7+
./Directory1/File4
8+
./Directory2/Directory3/File5
9+
./File6

0 commit comments

Comments
 (0)