Skip to content

Commit c1fddff

Browse files
committed
Adding tests for "Binary search tree
traversal".
1 parent 0b280a7 commit c1fddff

File tree

15 files changed

+125
-0
lines changed

15 files changed

+125
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- Tests for "Game of life".
3434
- Tests for "Maximum sub-sequence".
3535
- Tests for "Snake encoding".
36+
- Tests for "Binary search tree traversal".
3637

3738
## [1.13.0] - 2022-09-30
3839
### Added
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* The "Binary search tree traversal" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/binary-search-tree-traversal}
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 vi = parseInt(inputs[i]);
10+
}
11+
for (let i = 0; i < 4; i++) {
12+
13+
// Write an answer using console.log()
14+
// To debug: console.error('Debug messages...');
15+
16+
console.log('answer');
17+
}
18+
}
19+
20+
export { execute };
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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/binarySearchTreeTraversal/binarySearchTreeTraversal.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("Binary search tree traversal", 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("Positive values only", function() {
30+
let inputFile = new File(__dirname + 'input/02 - positive values only.txt');
31+
32+
execute(inputFile.readline.bind(inputFile));
33+
34+
assertOutputAnswer(__dirname + 'output/02 - positive values only.txt');
35+
});
36+
37+
test("Small random values", function() {
38+
let inputFile = new File(__dirname + 'input/03 - small random values.txt');
39+
40+
execute(inputFile.readline.bind(inputFile));
41+
42+
assertOutputAnswer(__dirname + 'output/03 - small random values.txt');
43+
});
44+
45+
test("Large random values", function() {
46+
let inputFile = new File(__dirname + 'input/04 - large random values.txt');
47+
48+
execute(inputFile.readline.bind(inputFile));
49+
50+
assertOutputAnswer(__dirname + 'output/04 - large random values.txt');
51+
});
52+
53+
test("More random values", function() {
54+
let inputFile = new File(__dirname + 'input/05 - more random values.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assertOutputAnswer(__dirname + 'output/05 - more random values.txt');
59+
});
60+
61+
test("Ordered values", function() {
62+
let inputFile = new File(__dirname + 'input/06 - ordered values.txt');
63+
64+
execute(inputFile.readline.bind(inputFile));
65+
66+
assertOutputAnswer(__dirname + 'output/06 - ordered values.txt');
67+
});
68+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
8 6 13 10 5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
8
2+
135 151 128 13 201 260 158 195
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
10
2+
-4 2 17 -15 -17 15 -12 11 30 29
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
14
2+
80549 235191 118837 -498143 -185405 -475495 428331 -146618 -479044 -173808 417544 204945 -479692 -70525
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
30
2+
-364052 -781443 796022 298864 295887 -614308 -296991 -1129497 838567 22573 40801 273590 1033779 715337 -38508 356628 514888 386934 930494 -907064 -916571 762755 -657230 -293721 822425 -314334 -862634 -146274 228429 1042357
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
50
2+
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
8 6 5 13 10
2+
5 6 8 10 13
3+
5 6 10 13 8
4+
8 6 13 5 10

0 commit comments

Comments
 (0)