Turn some test outputs into actual tests

This commit is contained in:
Oleh Prypin 2015-04-21 15:45:30 +03:00
commit 22db40e5e4
13 changed files with 84 additions and 52 deletions

View file

@ -286,6 +286,8 @@ proc `$`*[T](c: CritBitTree[T]): string =
result.add("}")
when isMainModule:
import sequtils
var r: CritBitTree[void]
r.incl "abc"
r.incl "xyz"
@ -295,12 +297,8 @@ when isMainModule:
doAssert r.contains"def"
when not defined(testing):
#r.del "def"
r.excl "def"
for w in r.items:
echo w
for w in r.itemsWithPrefix("de"):
echo w
assert toSeq(r.items) == @["abc", "definition", "prefix", "xyz"]
assert toSeq(r.itemsWithPrefix("de")) == @["definition"]

View file

@ -197,15 +197,22 @@ proc empty*(s: IntSet): bool {.inline, deprecated.} =
## worked reliably and so is deprecated.
result = s.counter == 0
when not defined(testing) and isMainModule:
when isMainModule:
import sequtils, algorithm
var x = initIntSet()
x.incl(1)
x.incl(2)
x.incl(7)
x.incl(1056)
for e in items(x): echo e
var y: TIntSet
var xs = toSeq(items(x))
xs.sort(cmp[int])
assert xs == @[1, 2, 7, 1056]
var y: IntSet
assign(y, x)
for e in items(y): echo e
var ys = toSeq(items(y))
ys.sort(cmp[int])
assert ys == @[1, 2, 7, 1056]

View file

@ -492,10 +492,8 @@ when isMainModule:
block: # filter iterator test
let numbers = @[1, 4, 5, 8, 9, 7, 4]
for n in filter(numbers, proc (x: int): bool = x mod 2 == 0):
when not defined(testing):
echo($n)
# echoes 4, 8, 4 in separate lines
assert toSeq(filter(numbers, proc (x: int): bool = x mod 2 == 0)) ==
@[4, 8, 4]
block: # keepIf test
var floats = @[13.0, 12.5, 5.8, 2.0, 6.1, 9.9, 10.1]