-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshape_test.c
More file actions
42 lines (35 loc) · 1.17 KB
/
Copy pathshape_test.c
File metadata and controls
42 lines (35 loc) · 1.17 KB
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
#include "shape_test.h"
#include "shape.h"
#include <assert.h>
static void assert_within_delta(float delta, float expected, float actual) {
assert(expected - actual < delta && actual - expected < delta);
}
static void setup_shape(Shape * shape) {
shape_alloc(shape, 5);
shape_add(shape, vector_create(0, 0));
shape_add(shape, vector_create(2, 0));
shape_add(shape, vector_create(3, 1));
shape_add(shape, vector_create(2, 2));
shape_add(shape, vector_create(0, 2));
shape_initialize(shape);
}
static void test_shape_initialize() {
Shape shape;
setup_shape(&shape);
assert_within_delta(0.1, 0, shape.bounds_min.x);
assert_within_delta(0.1, 0, shape.bounds_min.y);
assert_within_delta(0.1, 3, shape.bounds_max.x);
assert_within_delta(0.1, 2, shape.bounds_max.y);
}
static void test_shape_contains() {
Shape shape;
setup_shape(&shape);
assert(!shape_contains_point(&shape, vector_create(4, 0)));
assert(!shape_contains_point(&shape, vector_create(2.6, 0.5)));
assert(shape_contains_point(&shape, vector_create(2.4, 0.5)));
assert(shape_contains_point(&shape, vector_create(1, 1)));
}
void test_shape() {
test_shape_initialize();
test_shape_contains();
}