2024-01-08 22:52:46 +00:00
|
|
|
import std/sequtils
|
|
|
|
import pkg/chronos
|
2024-01-11 21:13:55 +00:00
|
|
|
import pkg/asynctest/chronos/unittest
|
2024-01-08 22:52:46 +00:00
|
|
|
|
2024-01-15 16:45:04 +00:00
|
|
|
import pkg/codex/utils/asynciter
|
|
|
|
|
2024-01-08 22:52:46 +00:00
|
|
|
import ./helpers
|
|
|
|
|
|
|
|
import pkg/codex/indexingstrategy
|
|
|
|
|
|
|
|
for offset in @[0, 1, 2, 100]:
|
|
|
|
suite "Indexing strategies (Offset: " & $offset & ")":
|
|
|
|
let
|
|
|
|
firstIndex = 0 + offset
|
|
|
|
lastIndex = 12 + offset
|
|
|
|
nIters = 3
|
|
|
|
linear = LinearIndexingStrategy.new(firstIndex, lastIndex, nIters)
|
|
|
|
stepped = SteppedIndexingStrategy.new(firstIndex, lastIndex, nIters)
|
|
|
|
|
|
|
|
test "linear":
|
|
|
|
check:
|
2024-01-16 20:51:30 +00:00
|
|
|
toSeq(linear.getIndices(0)) == @[0, 1, 2, 3, 4].mapIt(it + offset)
|
|
|
|
toSeq(linear.getIndices(1)) == @[5, 6, 7, 8, 9].mapIt(it + offset)
|
|
|
|
toSeq(linear.getIndices(2)) == @[10, 11, 12].mapIt(it + offset)
|
2024-01-08 22:52:46 +00:00
|
|
|
|
|
|
|
test "stepped":
|
|
|
|
check:
|
2024-01-16 20:51:30 +00:00
|
|
|
toSeq(stepped.getIndices(0)) == @[0, 3, 6, 9, 12].mapIt(it + offset)
|
|
|
|
toSeq(stepped.getIndices(1)) == @[1, 4, 7, 10].mapIt(it + offset)
|
|
|
|
toSeq(stepped.getIndices(2)) == @[2, 5, 8, 11].mapIt(it + offset)
|
2024-01-08 22:52:46 +00:00
|
|
|
|
|
|
|
suite "Indexing strategies":
|
|
|
|
let
|
|
|
|
linear = LinearIndexingStrategy.new(0, 10, 3)
|
|
|
|
stepped = SteppedIndexingStrategy.new(0, 10, 3)
|
|
|
|
|
|
|
|
test "smallest range 0":
|
|
|
|
let
|
|
|
|
l = LinearIndexingStrategy.new(0, 0, 1)
|
|
|
|
s = SteppedIndexingStrategy.new(0, 0, 1)
|
|
|
|
check:
|
2024-01-16 20:51:30 +00:00
|
|
|
toSeq(l.getIndices(0)) == @[0]
|
|
|
|
toSeq(s.getIndices(0)) == @[0]
|
2024-01-08 22:52:46 +00:00
|
|
|
|
|
|
|
test "smallest range 1":
|
|
|
|
let
|
|
|
|
l = LinearIndexingStrategy.new(0, 1, 1)
|
|
|
|
s = SteppedIndexingStrategy.new(0, 1, 1)
|
|
|
|
check:
|
2024-01-16 20:51:30 +00:00
|
|
|
toSeq(l.getIndices(0)) == @[0, 1]
|
|
|
|
toSeq(s.getIndices(0)) == @[0, 1]
|
2024-01-08 22:52:46 +00:00
|
|
|
|
|
|
|
test "first index must be smaller than last index":
|
2024-01-15 16:45:04 +00:00
|
|
|
expect IndexingWrongIndexError:
|
2024-01-08 22:52:46 +00:00
|
|
|
discard LinearIndexingStrategy.new(10, 0, 1)
|
|
|
|
|
|
|
|
test "numberOfIterations must be greater than zero":
|
2024-01-15 16:45:04 +00:00
|
|
|
expect IndexingWrongIterationsError:
|
2024-01-08 22:52:46 +00:00
|
|
|
discard LinearIndexingStrategy.new(0, 10, 0)
|
|
|
|
|
|
|
|
test "linear - oob":
|
2024-01-15 16:45:04 +00:00
|
|
|
expect IndexingError:
|
2024-01-11 21:13:55 +00:00
|
|
|
discard linear.getIndices(3)
|
2024-01-08 22:52:46 +00:00
|
|
|
|
|
|
|
test "stepped - oob":
|
2024-01-15 16:45:04 +00:00
|
|
|
expect IndexingError:
|
2024-01-11 21:13:55 +00:00
|
|
|
discard stepped.getIndices(3)
|