Fix the failing overlaps test

This commit is contained in:
Zahary Karadjov 2019-08-19 18:09:15 +03:00 committed by zah
parent 3689c58d1b
commit 888a5aa82d
2 changed files with 12 additions and 9 deletions

View File

@ -82,7 +82,7 @@ template loopOverWords(lhs, rhs: BitSeq,
var lhsWord: WordType
when hasRhs:
var rhsWord: WordType
var firstByteOfLastWord, lastByteOfLastWord, markerPos: int
var firstByteOfLastWord, lastByteOfLastWord: int
# TODO: Returing a `var` value from an iterator is always safe due to
# the way inlining works, but currently the compiler reports an error
@ -103,14 +103,13 @@ template loopOverWords(lhs, rhs: BitSeq,
if lastWordSize == 0:
firstByteOfLastWord = bytesCount - sizeof(WordType)
lastByteOfLastWord = bytesCount - 1
initBitsVars()
markerPos = sizeof(WordType) * 8 - 1
dec fullWordsCount
else:
firstByteOfLastWord = bytesCount - lastWordSize
lastByteOfLastWord = bytesCount - 1
initBitsVars()
markerPos = log2trunc(lhsWord)
let markerPos = log2trunc(lhsWord)
when hasRhs: doAssert log2trunc(rhsWord) == markerPos
lhsWord.lowerBit markerPos

View File

@ -57,14 +57,18 @@ suite "Bit fields":
check b[j] == (j == 1)
test "overlaps":
for bitCount in [63, 62]:
for bitCount in [1, 62, 63, 64, 91, 127, 128, 129]:
checkpoint &"trying bit count {bitCount}"
var
a = BitSeq.init(bitCount)
b = BitSeq.init(bitCount)
a.raiseBit(4)
b.raiseBit(5)
for pos in [4, 8, 9, 12, 29, 32, 63, 64, 67]:
if pos + 2 < bitCount:
a.raiseBit(pos)
b.raiseBit(pos + 2)
check:
not a.overlaps(b)
not b.overlaps(a)