-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
67 lines (58 loc) · 1.69 KB
/
test.js
File metadata and controls
67 lines (58 loc) · 1.69 KB
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
const assert = require('assert');
const Agent = require('./agent');
const ZERO_OPERATORS_LEN = 3; // i.e. "(9)"
const ONE_OPERATOR_LEN = 7; // i.e. "(9 + 5)"
const TWO_OPERATORS_LEN = 13; // i.e. "((9 + 5) * 2)"
// instantiate to null expression
(() => {
const agent = new Agent();
assert.equal(agent.expression(), null);
})();
// initialize to "(operand operator operand)"
(() => {
const agent = new Agent();
agent.guess();
assert.equal(agent.expression().length, ONE_OPERATOR_LEN);
})();
// extend to "((operand operator operand) operator operand)"
(() => {
const agent = new Agent();
agent.guess();
let expr = agent.expression();
assert.equal(agent.extend(expr).length, TWO_OPERATORS_LEN);
})();
// mutate to "(operand operator operand)"
(() => {
const agent = new Agent();
agent.guess();
let expr = agent.expression();
assert.equal(agent.mutate(expr).length, ONE_OPERATOR_LEN);
})();
// remove: zero operators is a no-op
(() => {
const agent = new Agent();
agent._expression = "(9)";
let expr = agent.expression();
assert.equal(agent.remove(expr).length, ZERO_OPERATORS_LEN);
})();
// remove: one operator is shortened to zero operators
(() => {
const agent = new Agent();
agent.guess();
let expr = agent.expression();
assert.equal(agent.remove(expr).length, ZERO_OPERATORS_LEN);
})();
// remove: two operators is shortened to one operator
(() => {
const agent = new Agent();
agent.guess();
let expr = agent.extend(agent.expression());
assert.ok(agent.remove(expr).length < TWO_OPERATORS_LEN);
})();
// no-op
(() => {
const agent = new Agent();
agent.guess();
let expr = agent.expression();
assert.equal(agent.noOp(expr).length, ONE_OPERATOR_LEN);
})();