/
test_cheap.c
62 lines (55 loc) · 1.34 KB
/
test_cheap.c
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
#include <stdint.h>
#include <stdlib.h>
#include <conio.h>
#include "test.h"
#include "cheap.h"
#include "test_data.h"
#include "test_cheap.h"
void test_cheap_push(void) {
TESTBegin("C heap push");
cheap_init();
TESTAssertEqual(cheap_size, 0);
cheap_push(12);
TESTAssertEqual(cheap_size, 1);
cheap_push(23);
TESTAssertEqual(cheap_size, 2);
cheap_push(34);
TESTAssertEqual(cheap_size, 3);
TESTEnd();
}
void test_cheap_pop(void) {
TESTBegin("C heap pop");
cheap_init();
TESTAssertEqual(cheap_size, 0);
cheap_push(12);
cheap_push(23);
cheap_push(34);
TESTAssertEqual(cheap_size, 3);
TESTAssertEqual(cheap_pop(), 12);
TESTAssertEqual(cheap_size, 2);
TESTAssertEqual(cheap_pop(), 23);
TESTAssertEqual(cheap_size, 1);
TESTAssertEqual(cheap_pop(), 34);
TESTAssertEqual(cheap_size, 0);
TESTEnd();
}
void test_cheap_sort(void) {
uint8_t i;
TESTBegin("C heap sort 128 elements");
cheap_init();
for (i = 0; i < 128; ++i) {
cheap_push(test_data_random[i]);
}
for (i = 0; i < 128; ++i) {
TESTAssertEqual(cheap_pop(), test_data_sorted[i]);
}
TESTEnd();
}
void test_cheap(void) {
cputs("C heap tests:\r\n");
test_cheap_push();
test_cheap_pop();
test_cheap_sort();
//test_cheap_benchmark();
cputs("\r\n");
}