forked from Snaipe/Criterion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathordered-set.c
48 lines (37 loc) · 1.19 KB
/
ordered-set.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
#include <csptr/smalloc.h>
#include "criterion/criterion.h"
#include "criterion/internal/ordered-set.h"
int compare_gt(void *a, void *b) {
int *ia = a, *ib = b;
return *ia == *ib ? 0 : (*ia > *ib ? -1 : 1);
}
int compare_lt(void *a, void *b) {
int *ia = a, *ib = b;
return *ia == *ib ? 0 : (*ia < *ib ? -1 : 1);
}
Test(ordered_set, contract_lt) {
struct criterion_ordered_set *set = new_ordered_set(compare_lt, NULL);
insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int));
insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int));
insert_ordered_set(set, &(int[1]) { 3 }, sizeof (int));
int *prev = NULL;
FOREACH_SET(int *e, set) {
if (prev)
cr_assert_lt(*prev, *e);
prev = e;
}
sfree(set);
}
Test(ordered_set, contract_gt) {
struct criterion_ordered_set *set = new_ordered_set(compare_gt, NULL);
insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int));
insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int));
insert_ordered_set(set, &(int[1]) { 3 }, sizeof (int));
int *prev = NULL;
FOREACH_SET(int *e, set) {
if (prev)
cr_assert_gt(*prev, *e);
prev = e;
}
sfree(set);
}