Skip to content

Commit

Permalink
Fix more typos
Browse files Browse the repository at this point in the history
why:
  Not all generic functions were pulled while unit testing.
  • Loading branch information
mjfh committed Sep 1, 2021
1 parent 74f5b54 commit c7dca49
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
6 changes: 3 additions & 3 deletions nimbus/utils/keequ.nim
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ proc shift*[K,V](rq: var KeeQu[K,V]): Result[KeeQuPair[K,V],void]
if 0 < rq.tab.len:
let kvp = KeeQuPair[K,V](
key: rq.first,
val: rq.tab[rq.first].data)
data: rq.tab[rq.first].data)
rq.shiftImpl
return ok(KeeQuPair[K,V](kvp))
err()
Expand Down Expand Up @@ -296,9 +296,9 @@ proc pop*[K,V](rq: var KeeQu[K,V]): Result[KeeQuPair[K,V],void]
if 0 < rq.tab.len:
let kvp = KeeQuPair[K,V](
key: rq.last,
val: rq.tab[rq.last].data)
data: rq.tab[rq.last].data)
rq.popImpl
return ok(KeeQuPair[K,V](key,val))
return ok(KeeQuPair[K,V](kvp))
err()

proc popKey*[K,V](rq: var KeeQu[K,V]):
Expand Down
45 changes: 40 additions & 5 deletions tests/test_keequ.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ proc addOrFlushGroupwise(rq: var KeeQu[uint,uint];
doAssert rqLen == seen.len + rq.len
seen.setLen(0)

proc compileGenericFunctions(rq: var KeeQu[uint,uint]) =
## Verifies that functions compile, at all
rq.del(0)
rq[0] = 0 # so `rq[0]` works
discard rq[0]

let ignoreValues = (
(rq.append(0,0), rq.push(0,0),
rq.replace(0,0),
rq.prepend(0,0), rq.unshift(0,0),
rq.shift, rq.shiftKey, rq.shiftValue,
rq.pop, rq.popKey, rq.popValue,
rq.delete(0)),

(rq.hasKey(0), rq.eq(0)),

(rq.firstKey, rq.secondKey, rq.beforeLastKey, rq.lastKey,
rq.nextKey(0), rq.prevKey(0)),

(rq.first, rq.second, rq.beforeLast, rq.last,
rq.next(0), rq.prev(0)),

(rq.firstValue, rq.secondValue, rq.beforeLastValue, rq.lastValue),

(rq == rq, rq.len),

(toSeq(rq.nextKeys), toSeq(rq.nextValues), toSeq(rq.nextPairs),
toSeq(rq.prevKeys), toSeq(rq.prevValues), toSeq(rq.prevPairs)))

# ------------------------------------------------------------------------------
# Test Runners
# ------------------------------------------------------------------------------
Expand All @@ -97,6 +126,10 @@ proc runKeeQu(noisy = true) =
fwdRq, revRq: KeeQu[uint,uint]
fwdRej, revRej: seq[int]

test &"All functions smoke test":
var rq: KeeQu[uint,uint]
rq.compileGenericFunctions

test &"Append/traverse {keyList.len} items, " &
&"rejecting {numKeyDups} duplicates":
var
Expand Down Expand Up @@ -198,9 +231,10 @@ proc runKeeQu(noisy = true) =
const groupLen = 7
let veryNoisy = noisy and false

test &"Load/forward iterate {numUniqeKeys} items, "&
test &"Load/forward/reverse iterate {numUniqeKeys} items, "&
&"deleting in groups of at most {groupLen}":

# forward ...
block:
var
rq = keyList.toQueue
Expand Down Expand Up @@ -255,8 +289,7 @@ proc runKeeQu(noisy = true) =
check seen.len < groupLen
check uniqueKeys == all

test &"Load/reverse iterate {numUniqeKeys} items, "&
&"deleting in groups of at most {groupLen}":
# reverse ...
block:
var
rq = keyList.toQueue
Expand Down Expand Up @@ -311,7 +344,9 @@ proc runKeeQu(noisy = true) =
check seen.len < groupLen
check uniqueKeys == all.reversed

test &"Load/forward steps {numUniqeKeys} key/item consistency":
test &"Load/forward/reverse steps {numUniqeKeys} key/item consistency":

# forward ...
block:
var
rq = keyList.toQueue
Expand All @@ -335,7 +370,7 @@ proc runKeeQu(noisy = true) =
check rq.verify.isOK
check count == uniqueKeys.len

test &"Load/reverse steps {numUniqeKeys} key/item consistency":
# reverse ...
block:
var
rq = keyList.toQueue
Expand Down

0 comments on commit c7dca49

Please sign in to comment.