corrected docs and tests

This commit is contained in:
Simon Hafner 2014-02-01 16:07:44 -06:00
commit 9f29bb8d9e
2 changed files with 11 additions and 15 deletions

View file

@ -226,11 +226,11 @@ proc `$`*[A](s: TOrderedSet[A]): string =
dollarImpl() dollarImpl()
proc `<`*[A](s, t: TSet[A]): bool = proc `<`*[A](s, t: TSet[A]): bool =
## Is a a strict subset of b? ## Is s a strict subset of t?
s.counter != t.counter and s <= t s.counter != t.counter and s <= t
proc `<=`*[A](s, t: TSet[A]): bool = proc `<=`*[A](s, t: TSet[A]): bool =
## Is a a subset of b? ## Is s a subset of t?
result = false result = false
if s.counter > t.counter: return if s.counter > t.counter: return
result = true result = true

View file

@ -1,16 +1,12 @@
import unittest import unittest
import sets import sets
suite "sets": doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3,4]), "equivalent or subset")
test "equivalent or subset": doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3]), "equivalent or subset")
check toSet(@[1,2,3]) <= toSet(@[1,2,3,4]) doAssert((not(toSet(@[1,2,3]) <= toSet(@[1,2]))), "equivalent or subset")
check toSet(@[1,2,3]) <= toSet(@[1,2,3]) doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3,4]), "strict subset")
check(not(toSet(@[1,2,3]) <= toSet(@[1,2]))) doAssert((not(toSet(@[1,2,3]) < toSet(@[1,2,3]))), "strict subset")
test "strict subset": doAssert((not(toSet(@[1,2,3]) < toSet(@[1,2]))), "strict subset")
check toSet(@[1,2,3]) <= toSet(@[1,2,3,4]) doAssert((not(toSet(@[1,2,3]) == toSet(@[1,2,3,4]))), "==")
check(not(toSet(@[1,2,3]) < toSet(@[1,2,3]))) doAssert(toSet(@[1,2,3]) == toSet(@[1,2,3]), "==")
check(not(toSet(@[1,2,3]) < toSet(@[1,2]))) doAssert((not(toSet(@[1,2,3]) == toSet(@[1,2]))), "==")
test "==":
check(not(toSet(@[1,2,3]) == toSet(@[1,2,3,4])))
check toSet(@[1,2,3]) == toSet(@[1,2,3])
check(not(toSet(@[1,2,3]) == toSet(@[1,2])))