Fixes issue where indexing strategy stepped gives wrong values for smallest of ranges

This commit is contained in:
benbierens 2023-12-04 13:35:49 +01:00 committed by Dmitriy Ryajov
parent d4ed43bc05
commit 6a3102246d
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 10 additions and 5 deletions

View File

@ -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))

View File

@ -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)