-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0-arithmetic-feature.js
90 lines (74 loc) · 2.44 KB
/
0-arithmetic-feature.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { fakeStdin, fakeStdout } from "../helpers/fake-process.js";
import { run } from "../../app.js";
Feature("Arithmetic", () => {
Scenario("Start counting at zero", () => {
let stdout, stdin;
Given("we have a fake stdout and stdin", () => {
stdout = fakeStdout();
stdin = fakeStdin();
});
When("we print an empty cell", async () => {
const program = ".";
await run(program, stdin, stdout);
});
Then("The output should be null (0)", () => {
expect(stdout.getData()).to.eql("\u0000");
});
});
Scenario("1+1 equals 2", () => {
let stdout, stdin;
Given("we have a fake stdout and stdin", () => {
stdout = fakeStdout();
stdin = fakeStdin();
});
When("we run 1+1 and print", async () => {
const program = "++.";
await run(program, stdin, stdout);
});
Then("The output should be 2", () => {
expect(stdout.getData()).to.eql("\u0002");
});
});
Scenario("1+1-1 equals 1", () => {
let stdout, stdin;
Given("we have a fake stdout and stdin", () => {
stdout = fakeStdout();
stdin = fakeStdin();
});
When("we run 1+1-1 and print", async () => {
const program = "++-.";
await run(program, stdin, stdout);
});
Then("The output should be 1", () => {
expect(stdout.getData()).to.eql("\u0001");
});
});
Scenario("Addition wraps", () => {
let stdout, stdin;
Given("we have a fake stdout and stdin", () => {
stdout = fakeStdout();
stdin = fakeStdin();
});
When("we are adding 256 and end up back at null", async () => {
const program = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.";
await run(program, stdin, stdout);
});
Then("The output should be null", () => {
expect(stdout.getData()).to.eql("\u0000");
});
});
Scenario("Subtraction wraps", () => {
let stdout, stdin;
Given("we have a fake stdout and stdin", () => {
stdout = fakeStdout();
stdin = fakeStdin();
});
When("we are subtracting 1 and wrap", async () => {
const program = "-.";
await run(program, stdin, stdout);
});
Then("The output should be ÿ", () => {
expect(stdout.getData()).to.eql("ÿ");
});
});
});