@@ -15,33 +15,6 @@ return {
1515 end)
1616 },
1717
18− group 'new' {
19− test('make table usable as list', function ()
20− local test = List:new{1, 1, 2, 3, 5}
21− assert.are_same(
22− {1, 1, 4, 9, 25},
23− test:map(function (x) return x^2 end)
24− )
25− end),
26− test('return empty list if no argument is given', function ()
27− assert.are_same({}, List:new())
28− end),
29− test('metatable of result is pandoc.List', function ()
30− local test = List:new{5}
31− assert.are_equal(List, getmetatable(test))
32− end)
33− },
34−
35− group 'includes' {
36− test('finds elements in list', function ()
37− local lst = List:new {'one', 'two', 'three'}
38− assert.is_truthy(lst:includes('one'))
39− assert.is_truthy(lst:includes('two'))
40− assert.is_truthy(lst:includes('three'))
41− assert.is_falsy(lst:includes('four'))
42− end)
43− },
44−
4518 group 'clone' {
4619 test('changing the clone does not affect original', function ()
4720 local orig = List:new {23, 42}
@@ -54,7 +27,25 @@ return {
5427 local orig = List:new {23, 42}
5528 assert.are_equal(List, getmetatable(orig:clone()))
5629 end),
57− },
30+ },
31+
32+ group 'extend' {
33+ test('extends list with other list', function ()
34+ local primes = List:new {2, 3, 5, 7}
35+ primes:extend {11, 13, 17}
36+ assert.are_same({2, 3, 5, 7, 11, 13, 17}, primes)
37+ end)
38+ },
39+
40+ group 'filter' {
41+ test('keep elements for which property is truthy', function ()
42+ local is_small_prime = function (x)
43+ return List.includes({2, 3, 5, 7}, x)
44+ end
45+ local numbers = List:new {4, 7, 2, 9, 5, 11}
46+ assert.are_same({7, 2, 5}, numbers:filter(is_small_prime))
47+ end),
48+ },
5849
5950 group 'find' {
6051 test('returns element and index if found', function ()
@@ -87,11 +78,26 @@ return {
8778 end),
8879 },
8980
90− group 'extend' {
91− test('extends list with other list', function ()
92− local primes = List:new {2, 3, 5, 7}
93− primes:extend {11, 13, 17}
94− assert.are_same({2, 3, 5, 7, 11, 13, 17}, primes)
81+ group 'includes' {
82+ test('finds elements in list', function ()
83+ local lst = List:new {'one', 'two', 'three'}
84+ assert.is_truthy(lst:includes('one'))
85+ assert.is_truthy(lst:includes('two'))
86+ assert.is_truthy(lst:includes('three'))
87+ assert.is_falsy(lst:includes('four'))
88+ end)
89+ },
90+
91+ group 'insert' {
92+ test('insert value at end of list.', function ()
93+ local count_norsk = List {'en', 'to', 'tre'}
94+ count_norsk:insert('fire')
95+ assert.are_same({'en', 'to', 'tre', 'fire'}, count_norsk)
96+ end),
97+ test('insert value in the middle of list.', function ()
98+ local count_norsk = List {'fem', 'syv'}
99+ count_norsk:insert(2, 'seks')
100+ assert.are_same({'fem', 'seks', 'syv'}, count_norsk)
95101 end)
96102 },
97103
@@ -108,13 +114,47 @@ return {
108114 end)
109115 },
110116
111− group 'filter' {
112− test('keep elements for which property is truthy', function ()
113− local is_small_prime = function (x)
114− return List.includes({2, 3, 5, 7}, x)
115− end
116− local numbers = List:new {4, 7, 2, 9, 5, 11}
117− assert.are_same({7, 2, 5}, numbers:filter(is_small_prime))
117+ group 'new' {
118+ test('make table usable as list', function ()
119+ local test = List:new{1, 1, 2, 3, 5}
120+ assert.are_same(
121+ {1, 1, 4, 9, 25},
122+ test:map(function (x) return x^2 end)
123+ )
124+ end),
125+ test('return empty list if no argument is given', function ()
126+ assert.are_same({}, List:new())
127+ end),
128+ test('metatable of result is pandoc.List', function ()
129+ local test = List:new{5}
130+ assert.are_equal(List, getmetatable(test))
131+ end)
132+ },
133+
134+ group 'remove' {
135+ test('remove value at end of list.', function ()
136+ local understand = List {'jeg', 'forstår', 'ikke'}
137+ local norsk_not = understand:remove()
138+ assert.are_same({'jeg', 'forstår'}, understand)
139+ assert.are_equal('ikke', norsk_not)
118140 end),
141+ test('remove value at beginning of list.', function ()
142+ local count_norsk = List {'en', 'to', 'tre'}
143+ count_norsk:remove(1)
144+ assert.are_same({'to', 'tre'}, count_norsk)
145+ end)
146+ },
147+
148+ group 'sort' {
149+ test('sort numeric list', function ()
150+ local numbers = List {71, 5, -1, 42, 23, 0, 1}
151+ numbers:sort()
152+ assert.are_same({-1, 0, 1, 5, 23, 42, 71}, numbers)
153+ end),
154+ test('reverse-sort numeric', function ()
155+ local numbers = List {71, 5, -1, 42, 23, 0, 1}
156+ numbers:sort(function (x, y) return x > y end)
157+ assert.are_same({71, 42, 23, 5, 1, 0, -1}, numbers)
158+ end)
119159 },
120160}