File: ordered-set.c

package info (click to toggle)
criterion 2.3.3git1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,832 kB
  • sloc: ansic: 17,852; cpp: 795; python: 72; sh: 27; makefile: 23
file content (52 lines) | stat: -rw-r--r-- 1,219 bytes parent folder | download | duplicates (2)
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
#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);
}