1 #include "jitcs_int_adt_smallheap.h"
8 template <unsigned N
, bool B
>
9 void dump(const char* msg
, SmallTopHeap
<u32
, N
, B
>& th
) {
10 printf("%s: SmallTopHeap:\n", msg
);
12 for (size_t i
= 0; i
< th
.size
; ++i
) {
14 printf(" %d:%d(%d)", i
, th
.heap
[i
], th
.values
[i
]);
16 printf(" %d:%d", i
, th
.heap
[i
]);
21 for (size_t i
= 0; i
< th
.NUM
; ++i
) {
22 if (th
.hpos
[i
] >= th
.size
) continue;
23 if (th
.heap
[th
.hpos
[i
]] != i
) continue;
25 printf(" %d->%d", i
, th
.hpos
[i
]);
27 printf(" %d(%d)->%d", i
, th
.values
[i
], th
.hpos
[i
]);
33 static void test(UnitTest
& t
) {
34 SmallTopHeap
<u32
, 32, false> h1
;
35 t
.check("unordered val/empty", h1
.isEmpty());
44 t
.check("unordered val/check 1", h1
.check());
45 t
.check("unordered val/top",
46 h1
.peekTop() == 1 && h1
.peekTopValue() == 2000);
48 t
.check("unordered val/check after droptop", h1
.check());
49 t
.check("unordered val/top 2",
50 h1
.peekTop() == 3 && h1
.peekTopValue() == 1800);
52 t
.check("unordered val/check after drop", h1
.check());
53 t
.check("unordered val/top 3",
54 h1
.peekTop() == 3 && h1
.peekTopValue() == 1800);
60 t
.check("unordered val/check after drop 5", h1
.check());
61 t
.check("unordered val/top last",
62 h1
.peekTop() == 9 && h1
.peekTopValue() == 800);
64 t
.check("unordered val/check empty", h1
.isEmpty());
66 SmallTopHeap
<u32
, 32, true> h2
;
67 t
.check("ordered val/empty", h2
.isEmpty());
76 t
.check("ordered val/check 1", h2
.check());
77 t
.check("ordered val/top",
78 h2
.peekTop() == 1 && h2
.peekTopValue() == 2000);
80 t
.check("ordered val/check after droptop", h2
.check());
81 t
.check("ordered val/top 2",
82 h2
.peekTop() == 3 && h2
.peekTopValue() == 1800);
84 t
.check("ordered val/check after drop", h2
.check());
85 t
.check("ordered val/top 3",
86 h2
.peekTop() == 3 && h2
.peekTopValue() == 1800);
92 t
.check("ordered val/check after drop 5", h2
.check());
93 t
.check("ordered val/top last",
94 h2
.peekTop() == 9 && h2
.peekTopValue() == 800);
96 t
.check("ordered val/check empty", h2
.isEmpty());
99 static UnitTestRun
_1("ADT/SmallTopHeap", test
);