Skip to content

Commit 53bcd5e

Browse files
committed
Adding tests for "Micro assembly".
1 parent 54b190e commit 53bcd5e

File tree

11 files changed

+186
-1
lines changed

11 files changed

+186
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [1.11.0] - 2022-07-31
88
### Added
99
- Tests for "Someone's acting sus....".
1010
- Tests for "Personal best".
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- Tests for "Lunar lockout".
3737
- Tests for "Shikaku solver".
3838
- Tests for "Hexagonal maze".
39+
- Tests for "Micro assembly".
3940

4041
### Changed
4142
- Renaming "Linear Bézier curves" to "Cubic Bézier curves".
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* The "Micro assembly" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/micro-assembly}
4+
*/
5+
function execute(readline) {
6+
var inputs = readline().split(' ');
7+
const a = parseInt(inputs[0]);
8+
const b = parseInt(inputs[1]);
9+
const c = parseInt(inputs[2]);
10+
const d = parseInt(inputs[3]);
11+
const n = parseInt(readline());
12+
for (let i = 0; i < n; i++) {
13+
const instruction = readline();
14+
}
15+
16+
// Write an answer using console.log()
17+
// To debug: console.error('Debug messages...');
18+
19+
console.log('a b c d');
20+
}
21+
22+
export { execute };
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/medium/microAssembly/microAssembly.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Micro assembly", 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("MOV test", function() {
21+
let inputFile = new File(__dirname + 'input/01 - MOV test.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
"1 3 1 -4"
28+
);
29+
});
30+
31+
test("ADD test", function() {
32+
let inputFile = new File(__dirname + 'input/02 - ADD test.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
"4 9 13 5"
39+
);
40+
});
41+
42+
test("SUB test", function() {
43+
let inputFile = new File(__dirname + 'input/03 - SUB test.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
"0 12 21 12"
50+
);
51+
});
52+
53+
test("JNE test", function() {
54+
let inputFile = new File(__dirname + 'input/04 - JNE test.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
"3 0 7 9"
61+
);
62+
});
63+
64+
test("Handling negative values", function() {
65+
let inputFile = new File(__dirname + 'input/05 - handling negative values.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
"-1 0 -3 -10"
72+
);
73+
});
74+
75+
test("Calculating sum of 1..N", function() {
76+
let inputFile = new File(__dirname + 'input/06 - calculating sum of 1_N.txt');
77+
78+
execute(inputFile.readline.bind(inputFile));
79+
80+
assert.strictEqual(
81+
console.log.getCall(0).args[0],
82+
"55 0 0 0"
83+
);
84+
});
85+
86+
test("Nested loops", function() {
87+
let inputFile = new File(__dirname + 'input/07 - nested loops.txt');
88+
89+
execute(inputFile.readline.bind(inputFile));
90+
91+
assert.strictEqual(
92+
console.log.getCall(0).args[0],
93+
"30 0 0 -7"
94+
);
95+
});
96+
97+
test("Multiplication and jump over instruction", function() {
98+
let inputFile = new File(__dirname + 'input/08 - multiplication and jump over instruction.txt');
99+
100+
execute(inputFile.readline.bind(inputFile));
101+
102+
assert.strictEqual(
103+
console.log.getCall(0).args[0],
104+
"105 0 0 0"
105+
);
106+
});
107+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 2 3 -4
2+
2
3+
MOV b 3
4+
MOV c a
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2 3 4 5
2+
3
3+
ADD a b 1
4+
ADD b 2 7
5+
ADD c a b
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
14 2 21 9
2+
3
3+
SUB a a a
4+
SUB d 12 a
5+
SUB b 15 3
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3 5 7 9
2+
2
3+
SUB b b 1
4+
JNE 0 b 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
0 -2 -3 -4
2+
4
3+
MOV a -1
4+
SUB b c -3
5+
ADD d d -1
6+
JNE 2 d -10
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0 10 0 0
2+
3
3+
ADD a a b
4+
SUB b b 1
5+
JNE 0 b 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1 3 3 7
2+
9
3+
MOV a 10
4+
MOV b 5
5+
MOV c b
6+
SUB c c 1
7+
ADD a a c
8+
JNE 3 c 0
9+
SUB b b 1
10+
JNE 2 b c
11+
SUB d 0 d

0 commit comments

Comments
 (0)