49 lines
1.6 KiB
Nim
49 lines
1.6 KiB
Nim
# Copyright 2022 Mattia Giambirtone
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
import strformat
|
|
import ../src/nimdeque
|
|
|
|
|
|
when isMainModule:
|
|
const size = 10000
|
|
var deque = newLinkedDeque[int]()
|
|
echo &"Generating {size} values"
|
|
for i in countup(0, size, 1):
|
|
deque.add(i)
|
|
echo "Checking iteration"
|
|
for i in countup(0, size, 1):
|
|
doAssert deque[i] == i
|
|
echo "Checking contains"
|
|
for i in countup(0, size, 1):
|
|
doAssert i in deque
|
|
echo "Popping off the head"
|
|
doAssert deque.pop() == 0
|
|
echo "Popping off the tail"
|
|
doAssert deque.pop(deque.high()) == size
|
|
echo "Checking new head"
|
|
doAssert deque[0] == 1
|
|
echo "Checking new tail"
|
|
doAssert deque[deque.high()] == size - 1
|
|
echo "Re-checking values"
|
|
for i in countup(0, size - 2, 1):
|
|
doAssert deque[i] == i + 1
|
|
echo "Appending value at the beginning"
|
|
deque.addLeft(0)
|
|
echo "Re-checking head"
|
|
doAssert deque[0] == 0
|
|
echo "Re-checking values"
|
|
for i in countup(0, size - 1, 1):
|
|
doAssert deque[i] == i
|
|
echo "All tests passed!"
|