import std/packedsets import std/sets import sequtils import algorithm block basicIntSetTests: var y = initPackedSet[int]() y.incl(1) y.incl(2) y.incl(7) y.incl(1056) y.incl(1044) y.excl(1044) doAssert y == [1, 2, 7, 1056].toPackedSet doAssert toSeq(y.items) == [1, 2, 7, 1056] doAssert y.containsOrIncl(888) == false doAssert 888 in y doAssert y.containsOrIncl(888) == true doAssert y.missingOrExcl(888) == false doAssert 888 notin y doAssert y.missingOrExcl(888) == true proc sortedPairs[T](t: T): auto = toSeq(t.pairs).sorted template sortedItems(t: untyped): untyped = sorted(toSeq(t)) type Id = distinct int proc `$`(x: Id): string {.borrow.} proc cmp(a: Id, b: Id): int {.borrow.} proc `==`(a: Id, b: Id): bool {.borrow.} proc `<`(a: Id, b: Id): bool {.borrow.} block genericTests: # we use HashSet as groundtruth, it's well tested elsewhere template testDel(A: typedesc, t: typed, t0: typed) = block: template checkEquals() = doAssert t.len == t0.len for k in t0: doAssert k in t for k in t: doAssert k in t0 doAssert sortedItems(t) == sortedItems(t0) template incl2(i) = t.incl i t0.incl i template excl2(i) = t.excl i t0.excl i var expected: seq[A] let n = 100 let n2 = n*2 for i in 0..