-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.coffee
71 lines (54 loc) · 1.97 KB
/
test.coffee
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
fs = require 'fs'
Jit = require './jit'
assert = require 'assert'
{printJSONGrid} = require './util'
require('./log').quiet = yes
assert.gridEquals = (expected, actual, step) ->
try
@deepEqual expected, actual
catch e
console.log "====== EXPECTED ====== (step #{step})"
printJSONGrid expected
console.log '====== ACTUAL ======'
printJSONGrid actual
throw e
describe 'jit', ->
describe 'from test data', ->
files = fs.readdirSync "#{__dirname}/testdata"
for filename in files when filename.match /\.json$/
do (filename) -> it filename, ->
lines = fs.readFileSync("#{__dirname}/testdata/#{filename}", 'utf8').split '\n'
initial = JSON.parse lines.shift()
#console.log "===== #{filename} Initial:"
#printJSONGrid initial
s = new Jit initial
for l,i in lines when l
expected = JSON.parse l
s.step()
actual = s.toJSON()
assert.gridEquals expected, actual, i
describe 'from gendata', ->
@timeout 10000
if !fs.existsSync "#{__dirname}/gendata"
console.warn 'Note: Skipping checking previously generated data - data not found. Use gendata to generate'
return
files = fs.readdirSync "#{__dirname}/gendata"
for filename in files when filename.match /\.json$/
do (filename) -> it filename, ->
lines = fs.readFileSync("#{__dirname}/gendata/#{filename}", 'utf8').split '\n'
for l,i in lines when l
{initial, steps} = JSON.parse l
jit = new Jit initial
for expected, k in steps
jit.step()
try
assert.gridEquals expected, jit.toJSON(), "#{i}, #{k}"
catch e
console.log '======================== context:'
printJSONGrid initial
console.log '-- steps --'
printJSONGrid s for s in steps
console.log JSON.stringify initial
throw e
after ->
console.log Jit.stats