Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidb80 committed Oct 13, 2022
1 parent ae95944 commit 61bea0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
play.*
tests/test
htmldocs/
12 changes: 6 additions & 6 deletions tests/test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import emath, emath/exceptions, emath/defaults


func `~=`(f1, f2: float): bool =
0.01 > abs f1 - f2
0.0001 > abs f1 - f2

template matche(expr, answer): untyped =
let ast = parse expr
Expand All @@ -24,10 +24,10 @@ suite "operator priority":
matche expr, answer

suite "pars":
const expr = "(1) + (2 * 3) - 4"
const expr = "(((((((1)))))-1)) + (-(-2) * 4) ^ -3 + 2"

test expr:
matche expr, 3.0
matche expr, 2.001953125

suite "fn call":
var
Expand All @@ -38,7 +38,7 @@ suite "fn call":
assert a.len == 0
9.0

const expr = "cos(0) + log(16, 2) - nine() + 10"
const expr = "cos(-(0 * 4)) + log(16, 2) - nine() + 10"
test expr:
check expr.parse.eval(vars, fns) == +6.0

Expand All @@ -49,7 +49,7 @@ suite "var":
template checkUndef(k, n, body): untyped =
var raised = false

try: body
try: body
except EMathNotDefined:
raised = true
var e = (ref EMathNotDefined)(getCurrentException())
Expand All @@ -61,7 +61,7 @@ suite "var":
test "not exists":
checkUndef mskVar, "me":
discard "me + 2 * 3".parse.eval


suite "correctness":
for expr in [
Expand Down

0 comments on commit 61bea0f

Please sign in to comment.