Skip to content

Commit

Permalink
more tests about complex/math; refine struct of tlib.nim
Browse files Browse the repository at this point in the history
  • Loading branch information
litlighilit committed Apr 24, 2024
1 parent f167134 commit 8d4f8dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
7 changes: 7 additions & 0 deletions tests/tcomplex.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

test "complex":
let z = complex(3.0, -4.0)
check z.imag == -4.0
check $z == "(3-4j)"
check z.conjugate() == complex(3.0, 4.0)
check abs(z) == 5.0
31 changes: 21 additions & 10 deletions tests/tlib.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# XXX: While the coverage is rather low,
# considering many `Lib` of nimpylib are mostly wrapper around Nim's stdlib,
# we shall mainly focus on the cases where Python differs Nim,
# and leave the rest to Nim's own stdlib test.

import pylib/Lib/[random]
import pylib/Lib/[random, string, math]

test "random":
# TODO: more test (maybe firstly set `seed`)
check randint(1,2) in 1..2

test "Lib/string":
check "hello δδ".capwords == "Hello Δδ" ## support Unicode
check "01234".capwords == "01234"

# TODO: more tests.
test "Lib/math":
checkpoint "log"
check log(1.0/math.e) == -1
check log(1.0) == 0
check log(32.0, 2.0) == 5


when not defined(js):
import pylib/Lib/os
Expand Down Expand Up @@ -37,12 +57,3 @@ when not defined(js):
check f.read() == cont
check not fileExists tname

test "random":
# TODO: more test (maybe firstly set `seed`)
check randint(1,2) in 1..2

import pylib/Lib/string

test "Lib/string":
check "hello δδ".capwords == "Hello Δδ" ## support Unicode
check "01234".capwords == "01234"

0 comments on commit 8d4f8dd

Please sign in to comment.