-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.c
47 lines (38 loc) · 1.25 KB
/
example_test.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
#include "cbench.h"
#include "obsidian.h"
int add(int a, int b) { return a + b; }
int main(int argc, char *argv[]) {
OBS_SETUP("TestingAdd", argc, argv);
// a test group represents a selection of tests
OBS_TEST_GROUP("Fuzzy Tests", {
OBS_TEST("Basic", {
obs_test_eq(int, add(5, 1), 6);
obs_test_neq(int, add(10, 5), 15);
})
OBS_TEST("Pass", {
obs_test_eq(int, add(10, -1), 9);
})
// purposefully wrong (10 + 2 != 15) just to show what happens when a test fails
OBS_TEST("10 + 2", {
// custom test assertion
obs_test(add(10, 2) == 15, "add(%d, %d) = %d which is not 15", 10, 2, add(10, 2));
})
})
OBS_BENCHMARK("Convert a bunch of stuff", 10, {
for (double i = 0; i < 10000; i++) {
printf("%lf %d %lf", i, (int)i, i * i);
}
})
OBS_BENCHMARK("Find track parent", 10, {
// should be 0, 0 but wall time won't be 0 since it's blocking
system("find .");
})
OBS_BENCHMARK_CHILD("Find track children", 10, {
system("find .");
})
OBS_BENCHMARK_SYS("Find using sys", 10, "find .")
// And so on
// report the results
OBS_REPORT;
return tests_failed;
}