Skip to content

Commit d418431

Browse files
committed
Adding tests for "Stock exchange losses".
1 parent 1ea9bff commit d418431

File tree

9 files changed

+116
-0
lines changed

9 files changed

+116
-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 "Network cabling".
1010
- Tests for "Scrabble".
11+
- Tests for "Stock exchange losses".
1112

1213
## [1.2.0] - 2022-03-02
1314
### Added
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* The "Stock exchange losses" puzzle.
3+
*/
4+
function execute(readline) {
5+
const n = parseInt(readline());
6+
var inputs = readline().split(' ');
7+
for (let i = 0; i < n; i++) {
8+
const v = parseInt(inputs[i]);
9+
}
10+
11+
// Write an answer using console.log()
12+
// To debug: console.error('Debug messages...');
13+
14+
console.log('answer');
15+
}
16+
17+
export { execute };
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../File.js';
4+
import { execute } from '../../../../lib/training/medium/stockExchangeLosses/stockExchangeLosses.js';
5+
6+
/**
7+
* Tests for the "Stock exchange losses" puzzle.
8+
*/
9+
suite('Stock exchange losses', 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('(3 2 4 2 1 5) -> -3', function() {
22+
let inputFile = new File('./test/training/medium/stockExchangeLosses/input/01 - first case.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
-3
29+
);
30+
});
31+
32+
test('Maximum Loss between the first and last values (5 3 4 2 3 1) -> -4', function() {
33+
let inputFile = new File('./test/training/medium/stockExchangeLosses/input/02 - maximum loss.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
-4
40+
);
41+
});
42+
43+
test('Profit (1 2 4 4 5) -> 0', function() {
44+
let inputFile = new File('./test/training/medium/stockExchangeLosses/input/03 - profit.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
0
51+
);
52+
});
53+
54+
test('Profit 2 (3 4 7 9 10) -> 0', function() {
55+
let inputFile = new File('./test/training/medium/stockExchangeLosses/input/04 - profit 2.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
0
62+
);
63+
});
64+
65+
test('Large dataset (n = 99999)', function() {
66+
let inputFile = new File('./test/training/medium/stockExchangeLosses/input/05 - large dataset.txt');
67+
68+
execute(inputFile.readline.bind(inputFile));
69+
70+
assert.strictEqual(
71+
console.log.getCall(0).args[0],
72+
-1073730311
73+
);
74+
});
75+
76+
test('Varied (3 2 10 7 15 14)', function() {
77+
let inputFile = new File('./test/training/medium/stockExchangeLosses/input/06 - varied.txt');
78+
79+
execute(inputFile.readline.bind(inputFile));
80+
81+
assert.strictEqual(
82+
console.log.getCall(0).args[0],
83+
-3
84+
);
85+
});
86+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
6
2+
3 2 4 2 1 5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
6
2+
5 3 4 2 3 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
1 2 4 4 5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
3 4 7 9 10

test/training/medium/stockExchangeLosses/input/05 - large dataset.txt

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
6
2+
3 2 10 7 15 14

0 commit comments

Comments
 (0)