-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_asserts.c
69 lines (61 loc) · 2.17 KB
/
test_asserts.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
#include "test_asserts.h"
#include <stdlib.h>
#include <stdio.h>
#include "rnd.h"
void
assert_sequence(uint32_t *expected_values,
uint32_t *actual_values,
int count,
char const *file,
int line)
{
for (int i = 0; i < count; ++i) {
if (expected_values[i] != actual_values[i]) {
fprintf(stderr,
"%s:%i: FAILURE: index %i: expected %lu, found %lu\n",
file, line, i,
(unsigned long)expected_values[i],
(unsigned long)actual_values[i]);
exit(EXIT_FAILURE);
}
}
}
void
assert_random_sequence(struct rnd *rnd,
uint32_t inclusive_lower_bound,
uint32_t inclusive_upper_bound,
uint32_t *expected_values,
int count,
char const *file,
int line)
{
uint32_t actual_values[count];
for (int i = 0; i < count; ++i) {
actual_values[i] = rnd_next_uniform_value_in_range(rnd,
inclusive_lower_bound,
inclusive_upper_bound);
}
assert_sequence(expected_values, actual_values, count, file, line);
}
void
assert_in_range(struct rnd *rnd,
uint32_t inclusive_lower_bound,
uint32_t inclusive_upper_bound,
int count,
char const *file,
int line)
{
for (int i = 0; i < count; ++i) {
uint32_t n = rnd_next_uniform_value_in_range(rnd,
inclusive_lower_bound,
inclusive_upper_bound);
if (n < inclusive_lower_bound || n > inclusive_upper_bound) {
fprintf(stderr,
"%s:%i: FAILURE: index %i: %lu is outside range [%lu, %lu]\n",
file, line, i, (unsigned long)n,
(unsigned long)inclusive_lower_bound,
(unsigned long)inclusive_upper_bound);
exit(EXIT_FAILURE);
}
}
}