summaryrefslogtreecommitdiff
path: root/tests/modules/queue/test.lua
blob: b577e04c97fe0f909c9413464debe6ae7b2fe84f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import("core.base.queue")

function test_push(t)
    local d = queue.new()
    d:push(1)
    d:push(2)
    d:push(3)
    d:push(4)
    d:push(5)
    t:are_equal(d:first(), 1)
    t:are_equal(d:last(), 5)
    local idx = 1
    for item in d:items() do
        t:are_equal(item, idx)
        idx = idx + 1
    end
end

function test_pop(t)
    local d = queue.new()
    d:push(1)
    d:push(2)
    d:push(3)
    d:push(4)
    d:push(5)
    d:pop()
    t:are_equal(d:first(), 2)
    t:are_equal(d:last(), 5)
    local idx = 2
    for item in d:items() do
        t:are_equal(item, idx)
        idx = idx + 1
    end
end