Skip to content

Commit ab7de1f

Browse files
committed
Adding tests for "Unary".
1 parent 8485df3 commit ab7de1f

File tree

8 files changed

+84
-0
lines changed

8 files changed

+84
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Base files to the project.
10+
- Tests for "Unary".

lib/training/easy/unary/unary.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* The "Unary" puzzle.
3+
*/
4+
function execute(readline) {
5+
const MESSAGE = readline();
6+
7+
// Write an answer using console.log()
8+
// To debug: console.error('Debug messages...');
9+
10+
console.log('answer');
11+
}
12+
13+
export { execute };

test/training/easy/unary/CGTest.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../File.js';
4+
import { execute } from '../../../../lib/training/easy/unary/unary.js';
5+
6+
/**
7+
* Tests for the "Unary" puzzle.
8+
*/
9+
suite('Unary', 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('can execute "Character C"', function() {
22+
let inputFile = new File('./test/training/easy/unary/input/01 - character C.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
'0 0 00 0000 0 00'
29+
);
30+
});
31+
32+
test('can execute "Message CC"', function() {
33+
let inputFile = new File('./test/training/easy/unary/input/02 - message CC.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
'0 0 00 0000 0 000 00 0000 0 00'
40+
);
41+
});
42+
43+
test('can execute "Character %"', function() {
44+
let inputFile = new File('./test/training/easy/unary/input/03 - character %.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
'00 0 0 0 00 00 0 0 00 0 0 0'
51+
);
52+
});
53+
54+
test('can execute "Message from Chuck Norris"', function() {
55+
let inputFile = new File('./test/training/easy/unary/input/04 - message from Chuck Norris.txt');
56+
let outputFile = new File('./test/training/easy/unary/output/04 - message from Chuck Norris.txt');
57+
58+
execute(inputFile.readline.bind(inputFile));
59+
60+
assert.strictEqual(
61+
console.log.getCall(0).args[0],
62+
outputFile.readline()
63+
);
64+
});
65+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CC
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
%
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chuck Norris' keyboard has 2 keys: 0 and white space.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 0 00 0000 0 0000 00 0 0 0 00 000 0 000 00 0 0 0 00 0 0 000 00 000 0 0000 00 0 0 0 00 0 0 00 00 0 0 0 00 00000 0 0 00 00 0 000 00 0 0 00 00 0 0 0000000 00 00 0 0 00 0 0 000 00 00 0 0 00 0 0 00 00 0 0 0 00 00 0 0000 00 00 0 00 00 0 0 0 00 00 0 000 00 0 0 0 00 00000 0 00 00 0 0 0 00 0 0 0000 00 00 0 0 00 0 0 00000 00 00 0 000 00 000 0 0 00 0 0 00 00 0 0 000000 00 0000 0 0000 00 00 0 0 00 0 0 00 00 00 0 0 00 000 0 0 00 00000 0 00 00 0 0 0 00 000 0 00 00 0000 0 0000 00 00 0 00 00 0 0 0 00 000000 0 00 00 00 0 0 00 00 0 0 00 00000 0 00 00 0 0 0 00 0 0 0000 00 00 0 0 00 0 0 00000 00 00 0 0000 00 00 0 00 00 0 0 000 00 0 0 0 00 00 0 0 00 000000 0 00 00 00000 0 0 00 00000 0 00 00 0000 0 000 00 0 0 000 00 0 0 00 00 00 0 0 00 000 0 0 00 00000 0 000 00 0 0 00000 00 0 0 0 00 000 0 00 00 0 0 0 00 00 0 0000 00 0 0 0 00 00 0 00 00 00 0 0 00 0 0 0 00 0 0 0 00 00000 0 000 00 00 0 00000 00 0000 0 00 00 0000 0 000 00 000 0 0000 00 00 0 0 00 0 0 0 00 0 0 0 00 0 0 000 00 0

0 commit comments

Comments
 (0)