Skip to content

Commit 9261dda

Browse files
committed
Adding tests for "Rod cutting problem".
1 parent 8a5539a commit 9261dda

File tree

9 files changed

+228
-0
lines changed

9 files changed

+228
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- Tests for "Hexagonal maze - part2".
2929
- Tests for "Byte pair encoding".
3030
- Tests for "Find the missing plus signs in addition".
31+
- Tests for "Rod cutting problem".
3132

3233
## [1.13.0] - 2022-09-30
3334
### Added
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* The "Rod cutting problem" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/rod-cutting-problem}
4+
*/
5+
function execute(readline) {
6+
const L = parseInt(readline());
7+
const N = parseInt(readline());
8+
for (let i = 0; i < N; i++) {
9+
var inputs = readline().split(' ');
10+
const length = parseInt(inputs[0]);
11+
const value = parseInt(inputs[1]);
12+
}
13+
14+
// Write an answer using console.log()
15+
// To debug: console.error('Debug messages...');
16+
17+
console.log('0');
18+
}
19+
20+
export { execute };
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/medium/rodCuttingProblem/rodCuttingProblem.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Rod cutting problem", function() {
9+
const sandbox = sinon.createSandbox();
10+
11+
setup(function () {
12+
sandbox.stub(console, "log");
13+
});
14+
15+
teardown(function () {
16+
sandbox.restore();
17+
});
18+
19+
20+
test("Example test", function() {
21+
let inputFile = new File(__dirname + 'input/01 - example test.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
10
28+
);
29+
});
30+
31+
test("Same pieces but longer rod", function() {
32+
let inputFile = new File(__dirname + 'input/02 - same pieces but longer rod.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
32
39+
);
40+
});
41+
42+
test("More pieces", function() {
43+
let inputFile = new File(__dirname + 'input/03 - more pieces.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
42
50+
);
51+
});
52+
53+
test("Big pieces", function() {
54+
let inputFile = new File(__dirname + 'input/04 - big pieces.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
20
61+
);
62+
});
63+
64+
test("Many pieces", function() {
65+
let inputFile = new File(__dirname + 'input/05 - many pieces.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
1152
72+
);
73+
});
74+
75+
test("Huge rod", function() {
76+
let inputFile = new File(__dirname + 'input/06 - huge rod.txt');
77+
78+
execute(inputFile.readline.bind(inputFile));
79+
80+
assert.strictEqual(
81+
console.log.getCall(0).args[0],
82+
11538
83+
);
84+
});
85+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
4
2+
4
3+
1 1
4+
2 5
5+
3 8
6+
4 9
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
12
2+
4
3+
1 1
4+
2 5
5+
3 8
6+
4 9
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
15
2+
8
3+
1 1
4+
2 5
5+
3 8
6+
4 9
7+
5 10
8+
6 17
9+
7 17
10+
8 20
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
19
2+
4
3+
7 7
4+
11 13
5+
13 14
6+
23 15
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
1000
2+
45
3+
1 0
4+
2 1
5+
3 1
6+
5 4
7+
8 7
8+
13 15
9+
21 24
10+
34 36
11+
55 59
12+
89 97
13+
144 152
14+
233 240
15+
377 379
16+
610 611
17+
987 997
18+
1597 1607
19+
2584 2586
20+
4181 4188
21+
6765 6774
22+
10946 10946
23+
17711 17714
24+
28657 28662
25+
46368 46376
26+
75025 75032
27+
121393 121402
28+
196418 196419
29+
317811 317818
30+
514229 514230
31+
832040 832040
32+
1346269 1346279
33+
2178309 2178317
34+
3524578 3524584
35+
5702887 5702895
36+
9227465 9227475
37+
14930352 14930355
38+
24157817 24157819
39+
39088169 39088177
40+
63245986 63245992
41+
102334155 102334163
42+
165580141 165580144
43+
267914296 267914300
44+
433494437 433494438
45+
701408733 701408740
46+
1134903170 1134903179
47+
1836311903 1836311913
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
10000
2+
45
3+
1 0
4+
2 1
5+
3 1
6+
5 4
7+
8 7
8+
13 15
9+
21 24
10+
34 36
11+
55 59
12+
89 97
13+
144 152
14+
233 240
15+
377 379
16+
610 611
17+
987 997
18+
1597 1607
19+
2584 2586
20+
4181 4188
21+
6765 6774
22+
10946 10946
23+
17711 17714
24+
28657 28662
25+
46368 46376
26+
75025 75032
27+
121393 121402
28+
196418 196419
29+
317811 317818
30+
514229 514230
31+
832040 832040
32+
1346269 1346279
33+
2178309 2178317
34+
3524578 3524584
35+
5702887 5702895
36+
9227465 9227475
37+
14930352 14930355
38+
24157817 24157819
39+
39088169 39088177
40+
63245986 63245992
41+
102334155 102334163
42+
165580141 165580144
43+
267914296 267914300
44+
433494437 433494438
45+
701408733 701408740
46+
1134903170 1134903179
47+
1836311903 1836311913

0 commit comments

Comments
 (0)