diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-02-28 13:05:24 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-02-28 13:05:24 -0500 |
| commit | 1ff716ddb9b2ad508e583a10b0c0090ce8d1634d (patch) | |
| tree | d34aac66fbcd954554fdf93f18355f7c1e353e5c | |
| parent | d8b658e75bc6165e059a13cb2fef5474fa9ff4f5 (diff) | |
| download | volute-1ff716ddb9b2ad508e583a10b0c0090ce8d1634d.zip | |
angular speed tests
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 14 | ||||
| -rw-r--r-- | test_unit.c | 55 |
3 files changed, 67 insertions, 3 deletions
@@ -1,2 +1,3 @@ /volute *.o +test_unit @@ -1,7 +1,7 @@ -CFLAGS = -std=c99 -Wall -Wextra -pedantic -Wno-deprecated-declarations +CFLAGS = -std=c99 -Wall -Wextra -pedantic -Wno-deprecated-declarations -D_XOPEN_SOURCE=700L LDFLAGS = -lSDL2 -lSDL2_ttf -SRC = main.c microui.c renderer.c widget.c ui.c +SRC = main.c microui.c renderer.c widget.c ui.c unit.c OBJ = ${SRC:.c=.o} all: volute @@ -9,10 +9,18 @@ all: volute clean: rm -f volute *.o +test: test_unit + for t in $^; do \ + ./$$t; \ + done + +test_unit: test_unit.o unit.o + ${CC} -o $@ $^ ${LDFLAGS} + volute: ${OBJ} ${CC} -o $@ $^ ${LDFLAGS} %.o: %.c ${CC} -c ${CFLAGS} $< -${OBJ}: microui.h renderer.h widget.h ui.h +${OBJ}: microui.h renderer.h widget.h ui.h unit.h diff --git a/test_unit.c b/test_unit.c new file mode 100644 index 0000000..dc7de3e --- /dev/null +++ b/test_unit.c @@ -0,0 +1,55 @@ +#include <assert.h> +#include <stdio.h> + +#include "unit.h" + + +#define EPSILON (1e-7) + +#define test(got, want) { \ + if (got < want-EPSILON || got > want+EPSILON) { \ + fprintf(stderr, "got %lf; want %lf\n", got, want); \ + assert(got == want); \ + } \ +} + + +void +test_rad_per_sec(void) { + test(rad_per_sec(123.456), 123.456); +} + +void +test_deg_per_sec(void) { + test(deg_per_sec(123.456), 2.15471367888); +} + +void +test_rpm(void) { + test(rpm(123.456), 12.92828207328); +} + +void +test_as_rad_per_sec(void) { + test(as_rad_per_sec(rad_per_sec(123.456)), 123.456); +} + +void +test_as_deg_per_sec(void) { + test(as_deg_per_sec(deg_per_sec(123.456)), 123.456); +} + +void +test_as_rpm(void) { + test(as_rpm(rpm(123.456)), 123.456); +} + +int +main(void) { + test_rad_per_sec(); + test_deg_per_sec(); + test_rpm(); + test_as_rad_per_sec(); + test_as_deg_per_sec(); + test_as_rpm(); +} |