/
check_barbershop.c
88 lines (84 loc) · 2.66 KB
/
check_barbershop.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdlib.h>
#include <stdio.h>
#include <check.h>
#include <assert.h>
#include "../src/scores.h"
START_TEST (test_pools_empty) {
PoolNode *a = NULL;
fail_unless(a == NULL, "empty pools are NULL.");
int next;
a = NextItem(a, &next);
fail_unless(next == -1, "Empty buckets return no items.");
} END_TEST
// Assert that counts are maintained while adding.
START_TEST (test_pools_add) {
PoolNode *head_b = NULL;
int next = -1;
head_b = promoteItem(head_b, 1, 5000, -1);
fail_if(head_b->score != 1);
fail_if(head_b->count != 1);
head_b = NextItem(head_b, &next);
printf("next %d\n", next);
fail_unless(next == 5000);
pool_foreach(head_b, pool_print);
fail_if(head_b->score != 1);
fail_if(head_b->count != 0);
head_b = NextItem(head_b, &next);
printf("next %d\n", next);
fail_unless(next == -1);
fail_if(head_b->score != 1);
fail_if(head_b->count != 0);
} END_TEST
//
// // Assert insert order is maintained.
// START_TEST (test_pools_add_several) {
// PoolNode *head_c = NULL;
// head_c = promoteItem(head_c, 1, 5000, -1);
// fail_if(head_c->score != 1);
// fail_if(head_c->count != 1);
// head_c = promoteItem(head_c, 1, 5001, -1);
// fail_if(head_c->count != 2);
// head_c = promoteItem(head_c, 1, 5002, -1);
// fail_if(head_c->score != 1);
// fail_if(head_c->count != 3);
// fail_unless(NextItem(head_c) == 5000);
// fail_if(head_c->count != 2);
// fail_unless(NextItem(head_c) == 5001);
// fail_if(head_c->count != 1);
// fail_unless(NextItem(head_c) == 5002);
// fail_if(head_c->count != 0);
// } END_TEST
//
// // Assert promoting ensures accurate counts and membership
// START_TEST (test_pools_promote) {
// PoolNode *head_d = NULL;
// head_d = promoteItem(head_d, 1, 5000, -1);
// head_d = promoteItem(head_d, 1, 5001, -1);
// head_d = promoteItem(head_d, 2, 5000, 1);
// head_d = promoteItem(head_d, 3, 5000, 2);
// fail_if(head_d->score != 3);
// fail_if(head_d->count != 1);
// fail_if(head_d->next->score != 2);
// fail_if(head_d->next->count != 0);
// fail_if(head_d->next->next->score != 1);
// fail_if(head_d->next->next->count != 1);
// } END_TEST
Suite * barbershop_suite(void) {
Suite *s = suite_create("Barbershop");
TCase *tc_core = tcase_create("Core");
tcase_add_test(tc_core, test_pools_empty);
tcase_add_test(tc_core, test_pools_add);
// tcase_add_test(tc_core, test_pools_add_several);
// tcase_add_test(tc_core, test_pools_promote);
suite_add_tcase(s, tc_core);
return s;
}
int main (void) {
int number_failed;
Suite *s = barbershop_suite();
SRunner *sr = srunner_create(s);
srunner_run_all(sr, CK_VERBOSE);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}