Software /
code /
prosody
Comparison
spec/util_queue_spec.lua @ 8240:c803624cae3d
spec/util_queue: Add iterator and peek tests for 100% line coverage
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 16 Sep 2017 10:16:08 +0100 |
parent | 8236:4878e4159e12 |
child | 9901:c8b75239846c |
comparison
equal
deleted
inserted
replaced
8239:20e3d5689cce | 8240:c803624cae3d |
---|---|
35 for _ = 1, 10 do | 35 for _ = 1, 10 do |
36 assert.are.equal(q:pop(), "hello", "queue item incorrect"); | 36 assert.are.equal(q:pop(), "hello", "queue item incorrect"); |
37 end | 37 end |
38 | 38 |
39 assert.are.equal(q:count(), 0, "queue count incorrect"); | 39 assert.are.equal(q:count(), 0, "queue count incorrect"); |
40 assert.are.equal(q:pop(), nil, "empty queue pops non-nil result"); | |
41 assert.are.equal(q:count(), 0, "popping empty queue affects count"); | |
42 | |
43 assert.are.equal(q:peek(), nil, "empty queue peeks non-nil result"); | |
44 assert.are.equal(q:count(), 0, "peeking empty queue affects count"); | |
40 | 45 |
41 assert.is_true(q:push(1)); | 46 assert.is_true(q:push(1)); |
42 for i = 1, 1001 do | 47 for i = 1, 1001 do |
43 assert.are.equal(q:pop(), i); | 48 assert.are.equal(q:pop(), i); |
44 assert.are.equal(q:count(), 0); | 49 assert.are.equal(q:count(), 0); |
66 assert.are.equal(q:count(), 10); | 71 assert.are.equal(q:count(), 10); |
67 | 72 |
68 assert.is_true(q:push(11)); | 73 assert.is_true(q:push(11)); |
69 assert.are.equal(q:count(), 10); | 74 assert.are.equal(q:count(), 10); |
70 assert.are.equal(q:pop(), 2); -- First item should have been purged | 75 assert.are.equal(q:pop(), 2); -- First item should have been purged |
76 assert.are.equal(q:peek(), 3); | |
71 | 77 |
72 for i = 12, 32 do | 78 for i = 12, 32 do |
73 assert.is_true(q:push(i)); | 79 assert.is_true(q:push(i)); |
74 end | 80 end |
75 | 81 |
76 assert.are.equal(q:count(), 10); | 82 assert.are.equal(q:count(), 10); |
77 assert.are.equal(q:pop(), 23); | 83 assert.are.equal(q:pop(), 23); |
78 end | 84 end |
79 | 85 |
86 do | |
87 -- Test iterator | |
88 local q = queue.new(10, true); | |
89 | |
90 for i = 1, 10 do | |
91 q:push(i); | |
92 end | |
93 | |
94 local i = 0; | |
95 for item in q:items() do | |
96 i = i + 1; | |
97 assert.are.equal(item, i, "unexpected item returned by iterator") | |
98 end | |
99 end | |
100 | |
80 end); | 101 end); |
81 end); | 102 end); |
82 end); | 103 end); |