Skip to content

Commit 9d1240c

Browse files
committed
Adding tests for "1D spreadsheet".
1 parent ef09cab commit 9d1240c

29 files changed

+826
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Tests for "Dolbear's law".
1111
- Tests for "ISBN check digit".
1212
- Tests for "Equivalent resistance, circuit building".
13+
- Tests for "1D spreadsheet".
1314

1415
### Changed
1516
- Using "__dirname" for input / output paths.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* The "1D spreadsheet" puzzle.
3+
*/
4+
function execute(readline) {
5+
const N = parseInt(readline());
6+
for (let i = 0; i < N; i++) {
7+
var inputs = readline().split(' ');
8+
const operation = inputs[0];
9+
const arg1 = inputs[1];
10+
const arg2 = inputs[2];
11+
}
12+
for (let i = 0; i < N; i++) {
13+
14+
// Write an answer using console.log()
15+
// To debug: console.error('Debug messages...');
16+
17+
console.log('1');
18+
}
19+
}
20+
21+
export { execute };
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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/easy/oneDSpreadsheet/oneDSpreadsheet.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
/**
10+
* Tests for the "1D spreadsheet" puzzle.
11+
*/
12+
suite('1D spreadsheet', function() {
13+
const sandbox = sinon.createSandbox();
14+
15+
setup(function () {
16+
sandbox.stub(console, "log");
17+
});
18+
19+
teardown(function () {
20+
sandbox.restore();
21+
});
22+
23+
24+
test('Simple dependency', function() {
25+
let inputFile = new File(__dirname + 'input/01 - simple dependency.txt');
26+
27+
execute(inputFile.readline.bind(inputFile));
28+
29+
assertOutputAnswer(__dirname + 'output/01 - simple dependency.txt');
30+
});
31+
32+
test('Double dependency', function() {
33+
let inputFile = new File(__dirname + 'input/02 - double dependency.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assertOutputAnswer(__dirname + 'output/02 - double dependency.txt');
38+
});
39+
40+
test('Subtraction', function() {
41+
let inputFile = new File(__dirname + 'input/03 - subtraction.txt');
42+
43+
execute(inputFile.readline.bind(inputFile));
44+
45+
assertOutputAnswer(__dirname + 'output/03 - subtraction.txt');
46+
});
47+
48+
test('Multiplication', function() {
49+
let inputFile = new File(__dirname + 'input/04 - multiplication.txt');
50+
51+
execute(inputFile.readline.bind(inputFile));
52+
53+
assertOutputAnswer(__dirname + 'output/04 - multiplication.txt');
54+
});
55+
56+
test('No dependencies', function() {
57+
let inputFile = new File(__dirname + 'input/05 - no dependencies.txt');
58+
59+
execute(inputFile.readline.bind(inputFile));
60+
61+
assertOutputAnswer(__dirname + 'output/05 - no dependencies.txt');
62+
});
63+
64+
test('Coefficients', function() {
65+
let inputFile = new File(__dirname + 'input/06 - coefficients.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assertOutputAnswer(__dirname + 'output/06 - coefficients.txt');
70+
});
71+
72+
test('Fibonacci', function() {
73+
let inputFile = new File(__dirname + 'input/07 - fibonacci.txt');
74+
75+
execute(inputFile.readline.bind(inputFile));
76+
77+
assertOutputAnswer(__dirname + 'output/07 - fibonacci.txt');
78+
});
79+
80+
test('Backward dependency', function() {
81+
let inputFile = new File(__dirname + 'input/08 - backward dependency.txt');
82+
83+
execute(inputFile.readline.bind(inputFile));
84+
85+
assertOutputAnswer(__dirname + 'output/08 - backward dependency.txt');
86+
});
87+
88+
test('Diamond dependency', function() {
89+
let inputFile = new File(__dirname + 'input/09 - diamond dependency.txt');
90+
91+
execute(inputFile.readline.bind(inputFile));
92+
93+
assertOutputAnswer(__dirname + 'output/09 - diamond dependency.txt');
94+
});
95+
96+
test('Accounting is easy', function() {
97+
let inputFile = new File(__dirname + 'input/10 - accounting is easy.txt');
98+
99+
execute(inputFile.readline.bind(inputFile));
100+
101+
assertOutputAnswer(__dirname + 'output/10 - accounting is easy.txt');
102+
});
103+
104+
test('Accounting is hard 1', function() {
105+
let inputFile = new File(__dirname + 'input/11 - accounting is hard 1.txt');
106+
107+
execute(inputFile.readline.bind(inputFile));
108+
109+
assertOutputAnswer(__dirname + 'output/11 - accounting is hard 1.txt');
110+
});
111+
112+
test('Accounting is hard 2', function() {
113+
let inputFile = new File(__dirname + 'input/12 - accounting is hard 2.txt');
114+
115+
execute(inputFile.readline.bind(inputFile));
116+
117+
assertOutputAnswer(__dirname + 'output/12 - accounting is hard 2.txt');
118+
});
119+
120+
test('Deep birecursion', function() {
121+
let inputFile = new File(__dirname + 'input/13 - deep birecursion.txt');
122+
123+
execute(inputFile.readline.bind(inputFile));
124+
125+
assertOutputAnswer(__dirname + 'output/13 - deep birecursion.txt');
126+
});
127+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
VALUE 3 _
3+
ADD $0 4
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
VALUE 20 _
3+
ADD $0 100
4+
ADD $1 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
VALUE 12 _
3+
SUB $0 3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
VALUE 4 _
3+
MULT 4 $0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
ADD 1 2
3+
SUB 3 1
4+
MULT 2 4
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
7
2+
VALUE 10 _
3+
VALUE 3 _
4+
MULT $0 $1
5+
VALUE 2 _
6+
VALUE 4 _
7+
MULT $3 $4
8+
ADD $2 $5
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
9
2+
VALUE 0 _
3+
VALUE 1 _
4+
ADD $0 $1
5+
ADD $1 $2
6+
ADD $2 $3
7+
ADD $3 $4
8+
ADD $4 $5
9+
ADD $5 $6
10+
ADD $6 $7

0 commit comments

Comments
 (0)