mirror of
https://github.com/status-im/nim-ranges.git
synced 2025-01-12 22:04:17 +00:00
MutRange advance() tests.
This commit is contained in:
parent
6efa5b365a
commit
1e8fff3854
@ -103,7 +103,7 @@ suite "Typed ranges":
|
||||
var a = toRange(@[1,2,3])
|
||||
check $a.toOpenArray == "[1, 2, 3]"
|
||||
|
||||
test "tryAdvance":
|
||||
test "tryAdvance(Range)":
|
||||
var a: Range[int]
|
||||
check:
|
||||
a.tryAdvance(1) == false
|
||||
@ -124,7 +124,7 @@ suite "Typed ranges":
|
||||
b.tryAdvance(1) == false
|
||||
$b.toOpenArray == "[]"
|
||||
|
||||
test "advance":
|
||||
test "advance(Range)":
|
||||
template aecheck(a, b): int =
|
||||
var res = 0
|
||||
try:
|
||||
@ -153,3 +153,56 @@ suite "Typed ranges":
|
||||
$b.toOpenArray == "[]"
|
||||
b.aecheck(1) == 2
|
||||
$b.toOpenArray == "[]"
|
||||
|
||||
test "tryAdvance(MutRange)":
|
||||
var a: MutRange[int]
|
||||
check:
|
||||
a.tryAdvance(1) == false
|
||||
a.tryAdvance(-1) == false
|
||||
a.tryAdvance(0) == true
|
||||
var buf = @[1, 2, 3]
|
||||
var b = toRange(buf)
|
||||
check:
|
||||
b.tryAdvance(-1) == false
|
||||
$b.toOpenArray == "[1, 2, 3]"
|
||||
b.tryAdvance(0) == true
|
||||
$b.toOpenArray == "[1, 2, 3]"
|
||||
b.tryAdvance(1) == true
|
||||
$b.toOpenArray == "[2, 3]"
|
||||
b.tryAdvance(1) == true
|
||||
$b.toOpenArray == "[3]"
|
||||
b.tryAdvance(1) == true
|
||||
$b.toOpenArray == "[]"
|
||||
b.tryAdvance(1) == false
|
||||
$b.toOpenArray == "[]"
|
||||
|
||||
test "advance(MutRange)":
|
||||
template aecheck(a, b): int =
|
||||
var res = 0
|
||||
try:
|
||||
a.advance(b)
|
||||
res = 1
|
||||
except IndexError:
|
||||
res = 2
|
||||
res
|
||||
|
||||
var a: MutRange[int]
|
||||
check:
|
||||
a.aecheck(1) == 2
|
||||
a.aecheck(-1) == 2
|
||||
a.aecheck(0) == 1
|
||||
var buf = @[1, 2, 3]
|
||||
var b = toRange(buf)
|
||||
check:
|
||||
b.aecheck(-1) == 2
|
||||
$b.toOpenArray == "[1, 2, 3]"
|
||||
b.aecheck(0) == 1
|
||||
$b.toOpenArray == "[1, 2, 3]"
|
||||
b.aecheck(1) == 1
|
||||
$b.toOpenArray == "[2, 3]"
|
||||
b.aecheck(1) == 1
|
||||
$b.toOpenArray == "[3]"
|
||||
b.aecheck(1) == 1
|
||||
$b.toOpenArray == "[]"
|
||||
b.aecheck(1) == 2
|
||||
$b.toOpenArray == "[]"
|
||||
|
Loading…
x
Reference in New Issue
Block a user