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

View File

@ -57,14 +57,18 @@ suite "Bit fields":
check b[j] == (j == 1) check b[j] == (j == 1)
test "overlaps": test "overlaps":
for bitCount in [63, 62]: for bitCount in [1, 62, 63, 64, 91, 127, 128, 129]:
checkpoint &"trying bit count {bitCount}" checkpoint &"trying bit count {bitCount}"
var var
a = BitSeq.init(bitCount) a = BitSeq.init(bitCount)
b = 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: check:
not a.overlaps(b) not a.overlaps(b)
not b.overlaps(a) not b.overlaps(a)