1 #include "jitcs_int_adt_heap.h"
10 HeapTest(const HeapTest
&) = default;
11 HeapTest(size_t id_
, size_t v
) : id(id_
), value(v
), heappos(0) {};
17 void dump(TopHeap
<HeapTest
>& th
) {
19 for (size_t i
= 0; i
< th
.data
.size(); ++i
) {
20 printf(" %d:%d(%d,%d)",
21 i
, th
.data
[i
].id
, th
.data
[i
].value
, th
.data
[i
].heappos
);
26 bool operator ==(const HeapTest
& h1
, const HeapTest
& h2
) {
27 return h1
.id
== h2
.id
;
29 bool operator !=(const HeapTest
& h1
, const HeapTest
& h2
) {
30 return h1
.id
!= h2
.id
;
33 static void test(UnitTest
& t
) {
35 t
.check("Heap/empty", h1
.isEmpty());
36 for (size_t i
= 0; i
< 10; ++i
) {
37 h1
.push(HeapTest(i
* 2 + 0, i
* 2 + 0));
38 t
.check("Heap/push", h1
.check());
40 for (size_t i
= 0; i
< 10; ++i
) {
41 h1
.push(HeapTest(i
* 2 + 1, i
* 2 + 1));
42 t
.check("Heap/push", h1
.check());
44 t
.check("Heap/top", h1
.peekTopValue() == 19 && h1
.peekTop().id
== 19);
46 t
.check("Heap/drop", h1
.check()
47 && h1
.peekTopValue() == 19 && h1
.peekTop().id
== 19);
49 t
.check("Heap/dropTop", h1
.check()
50 && h1
.peekTopValue() == 18 && h1
.peekTop().id
== 18);
51 while (!h1
.isEmpty()) {
53 t
.check("Heap/drop", h1
.check());
57 static UnitTestRun
_1("ADT/Heap", test
);