Skip to content

Commit

Permalink
new option "npm run microtest" to run just a couple of tests quickly
Browse files Browse the repository at this point in the history
  • Loading branch information
davidedc committed Apr 26, 2016
1 parent 2665108 commit b236474
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 77 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"test": "tests"
},
"scripts": {
"test": "cat runtime/defs.coffee sources/*.coffee runtime/alloc.coffee runtime/display.coffee runtime/find.coffee runtime/init.coffee runtime/mcmp.coffee runtime/otherCFunctions.coffee runtime/run.coffee runtime/stack.coffee runtime/symbol.coffee runtime/zombocom.coffee tests/*.coffee run-tests.coffee | coffee -cs | node",
"microtest": "cat runtime/defs.coffee sources/*.coffee runtime/alloc.coffee runtime/display.coffee runtime/find.coffee runtime/init.coffee runtime/mcmp.coffee runtime/otherCFunctions.coffee runtime/run.coffee runtime/stack.coffee runtime/symbol.coffee runtime/zombocom.coffee test-harness.coffee run-micro-tests.coffee | coffee -cs | node",
"test": "cat runtime/defs.coffee sources/*.coffee runtime/alloc.coffee runtime/display.coffee runtime/find.coffee runtime/init.coffee runtime/mcmp.coffee runtime/otherCFunctions.coffee runtime/run.coffee runtime/stack.coffee runtime/symbol.coffee runtime/zombocom.coffee tests/*.coffee test-harness.coffee run-tests.coffee | coffee -cs | node",
"build": "cat runtime/defs.coffee sources/*.coffee runtime/alloc.coffee runtime/display.coffee runtime/find.coffee runtime/init.coffee runtime/mcmp.coffee runtime/otherCFunctions.coffee runtime/run.coffee runtime/stack.coffee runtime/symbol.coffee runtime/zombocom.coffee | coffee -sc > dist/algebrite.js"
},
"repository": {
Expand Down
12 changes: 12 additions & 0 deletions run-micro-tests.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


# quick and dirty way to run a few tests

run_test [

"1+1",
"2",

]

# alert "passed tests: " + ok_tests + " / failed tests: " + ko_tests
92 changes: 16 additions & 76 deletions run-tests.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# self test functions

test_low_level = ->
run("clear"); # to initialize stack and memory

ok_tests = 0
ko_tests = 0
test_signs_in_rationals()
test_madd()
test_msub()
test_mmul()
test_mdiv()
test_mmod()
test_mprime()
test_mgcd()
test_mpow()
test_mroot()
# commenting out because it takes a looong time
# with the current logging. But it works now
# as I'm commenting it out.
#test_quickfactor()

selftest = ->

test_low_level()

test_multiply()
Expand Down Expand Up @@ -90,77 +103,4 @@ selftest = ->
return


logout = (s) ->
console.log s


run_test = (s) ->
i = 0
t = ""

test_flag = 1

run("clear")

run("e=quote(e)")

for i in [0...s.length] by 2

console.log("starting example: " + s[i])
#alert("starting example: " + s[i])
# document.write("starting example: " + s[i] )


out_count = 0

try
resultFromRun = run(s[i])
catch error
console.log error
init()


if (resultFromRun == s[i+1])
# document.write(" ...ok</br>")
console.log("ok example: " + s[i])
# alert("ok example: " + s[i])
ok_tests++
continue

ko_tests++
# document.write(" ...fail</br>")
console.log("\n")
console.log("test failed: " + s[i])

console.log("expected: " + s[i+1])

console.log("obtained: " + resultFromRun)
console.log("\n")

# alert "test failed: " + s[i] + " expected: " + s[i+1] + " obtained: " + resultFromRun


test_flag = 0

# these tests do not use "run" but still need a "stop" context


test_low_level = ->
run("clear"); # to initialize stack and memory

test_signs_in_rationals()
test_madd()
test_msub()
test_mmul()
test_mdiv()
test_mmod()
test_mprime()
test_mgcd()
test_mpow()
test_mroot()
# commenting out because it takes a looong time
# with the current logging. But it works now
# as I'm commenting it out.
#test_quickfactor()

selftest()
56 changes: 56 additions & 0 deletions test-harness.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ok_tests = 0
ko_tests = 0

logout = (s) ->
console.log s


run_test = (s) ->
i = 0
t = ""

test_flag = 1

run("clear")

run("e=quote(e)")

for i in [0...s.length] by 2

console.log("starting example: " + s[i])
#alert("starting example: " + s[i])
# document.write("starting example: " + s[i] )


out_count = 0

try
resultFromRun = run(s[i])
catch error
console.log error
init()


if (resultFromRun == s[i+1])
# document.write(" ...ok</br>")
console.log("ok example: " + s[i])
# alert("ok example: " + s[i])
ok_tests++
continue

ko_tests++
# document.write(" ...fail</br>")
console.log("\n")
console.log("test failed: " + s[i])

console.log("expected: " + s[i+1])

console.log("obtained: " + resultFromRun)
console.log("\n")

# alert "test failed: " + s[i] + " expected: " + s[i+1] + " obtained: " + resultFromRun


test_flag = 0

# these tests do not use "run" but still need a "stop" context

0 comments on commit b236474

Please sign in to comment.