File: minunit.h

package info (click to toggle)
diskscan 0.21-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,656 kB
  • sloc: ansic: 11,136; python: 338; xml: 138; sh: 41; makefile: 34
file content (69 lines) | stat: -rw-r--r-- 1,459 bytes parent folder | download | duplicates (6)
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
/**
 * minunit.h
 * Written by Michael Barker and released to the public domain,
 * as explained at http://creativecommons.org/publicdomain/zero/1.0/
 */

#ifndef MINUNIT_H
#define MINUNIT_H

#include <math.h>
#include <inttypes.h>

struct mu_result
{
    char* test;
    char* message;
};

#define mu_assert(message, test) \
    do {                         \
        if (!(test))             \
            return message;      \
    } while (0)

#define mu_run_test(name)        \
    do {                         \
        char *message = name();  \
        tests_run++;             \
        if (message) {           \
            struct mu_result r;  \
            r.test = #name;      \
            r.message = message; \
            return r;            \
        }                        \
    } while (0)

#define mu_ok               \
    do {                    \
        struct mu_result r; \
        r.test = 0;         \
        r.message = 0;      \
        return r;           \
    } while (0)

extern int tests_run;

static bool compare_double(double a, double b, double delta)
{
    if (fabs(a - b) < delta)
    {
        return true;
    }

    printf("[compare_double] fabs(%f, %f) < %f == false\n", a, b, delta);
    return false;
}

static bool compare_int64(int64_t a, int64_t b)
{
    if (a == b)
    {
        return true;
    }

    printf("[compare_int64] %" PRIu64 " == %" PRIu64 " == false\n", a, b);
    return false;
}

#endif