mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-13 19:03:10 +00:00
Fixes issue where indexing strategy stepped gives wrong values for smallest of ranges
This commit is contained in:
parent
d4ed43bc05
commit
6a3102246d
@ -54,5 +54,5 @@ method getIndicies*(self: SteppedIndexingStrategy, iteration: int): seq[int] =
|
||||
|
||||
let
|
||||
first = self.firstIndex + iteration
|
||||
last = first + (self.step * self.numberOfIterations)
|
||||
toSeq(countup(first, last - 1, self.numberOfIterations))
|
||||
last = max(first, first - 1 + (self.step * self.numberOfIterations))
|
||||
toSeq(countup(first, last, self.numberOfIterations))
|
||||
|
||||
@ -27,16 +27,21 @@ for offset in @[0, 1, 100]:
|
||||
stepped.getIndicies(1) == @[1, 4, 7, 10].mapIt(it + offset)
|
||||
stepped.getIndicies(2) == @[2, 5, 8, 11].mapIt(it + offset)
|
||||
|
||||
checksuite "Indexing strategies - oob":
|
||||
checksuite "Indexing strategies":
|
||||
let
|
||||
linear = LinearIndexingStrategy.new(0, 10, 3)
|
||||
stepped = SteppedIndexingStrategy.new(0, 10, 3)
|
||||
|
||||
test "linear":
|
||||
test "smallest range":
|
||||
let s = SteppedIndexingStrategy.new(0, 0, 1)
|
||||
check:
|
||||
s.getIndicies(0) == @[0]
|
||||
|
||||
test "linear - oob":
|
||||
expect AssertionDefect:
|
||||
discard linear.getIndicies(3)
|
||||
|
||||
test "stepped":
|
||||
test "stepped - oob":
|
||||
expect AssertionDefect:
|
||||
discard stepped.getIndicies(3)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user