-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.lua
More file actions
91 lines (75 loc) · 1.81 KB
/
test.lua
File metadata and controls
91 lines (75 loc) · 1.81 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
local LinkedList = require "init"
dumptbl = function(tbl, indent, cb)
if not indent then indent = 0 end
if not cb then cb = print end
if indent > 6 then
cb(string.rep(" ", indent) .. "...")
return
end
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then
cb(formatting)
dumptbl(v, indent+1, cb)
elseif type(v) == 'boolean' then
cb(formatting .. tostring(v))
elseif type(v) == "function" then
cb(formatting .. "()")
else
cb(formatting .. v)
end
end
end
local t = LinkedList.new({
"i'm gone",
"hahaha",
34,
{e=3},
5.4
})
t:push_back(6.6)
assert(t:back() == 6.6)
assert(t:get(t.size) == 6.6)
t:pop_back()
assert(t:back() ~= 6.6)
assert(t:get(t.size) ~= 6.6)
t:push_front(7.7)
assert(t:front() == 7.7)
assert(t:get(1) == 7.7)
t:pop_front()
assert(t:front() ~= 7.7)
assert(t:get(1) ~= 7.7)
assert(t:pop_front() == "i'm gone")
t:insert_after(1, ":Oo")
assert(t:get(2) == ":Oo")
t:insert_after(t.size, ":u")
assert(t:get(t.size) == ":u")
assert(t:back() == ":u")
t:push_back(":P")
t:push_back(":8")
assert(t:get(t.size - 1) == ":P")
t:remove(t.size - 1)
assert(t:get(t.size - 1) == ":u")
assert(t:pop_back() == ":8")
assert(t:back() == ":u")
dumptbl(t:to_list())
assert(#t:to_list() == #t:to_reversed_list())
do
local l = t:to_list()
for i, v in t:ipairs() do
assert(v == l[i])
end
for i, v in t:revipairs() do
assert(v == l[i])
end
end
do
local ts = LinkedList.new({"one", "two"})
ts:remove(1)
assert(ts:front() == "two")
assert(ts:back() == "two")
ts = LinkedList.new({"one", "two"})
ts:remove(2)
assert(ts:front() == "one")
assert(ts:back() == "one")
end