aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile23
-rw-r--r--test.c20
-rw-r--r--test.h25
-rw-r--r--test_angular_speed.c35
-rw-r--r--test_unit.c106
-rw-r--r--test_volume.c45
7 files changed, 137 insertions, 119 deletions
diff --git a/.gitignore b/.gitignore
index e371b4c..ace2437 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
/volute
*.o
-test_unit
+/test
diff --git a/Makefile b/Makefile
index 37303d1..485a08a 100644
--- a/Makefile
+++ b/Makefile
@@ -3,24 +3,23 @@ LDFLAGS = -lSDL2 -lSDL2_ttf
SRC = main.c microui.c renderer.c widget.c ui.c unit.c engine.c
OBJ = ${SRC:.c=.o}
+HDR = microui.h renderer.h widget.h ui.h unit.h engine.h
-all: volute
+TEST_SRC = test.c test_angular_speed.c test_volume.c unit.c
+TEST_OBJ = ${TEST_SRC:.c=.o}
-clean:
- rm -f volute *.o
-
-test: test_unit
- for t in $^; do \
- ./$$t; \
- done
-
-test_unit: test_unit.o unit.o
+volute: ${OBJ}
${CC} -o $@ $^ ${LDFLAGS}
-volute: ${OBJ}
+test: ${TEST_OBJ}
${CC} -o $@ $^ ${LDFLAGS}
+ ./$@
+
+clean:
+ rm -f volute test *.o
%.o: %.c
${CC} -c ${CFLAGS} $<
-${OBJ}: microui.h renderer.h widget.h ui.h unit.h engine.h
+${OBJ}: ${HDR}
+${TEST_OBJ}: ${HDR} test.h
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..0a0b4a9
--- /dev/null
+++ b/test.c
@@ -0,0 +1,20 @@
+#include "test.h"
+
+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();
+
+ test_cubic_centimetre();
+ test_litre();
+ test_cubic_metre();
+ test_cubic_inch();
+ test_as_cubic_centimetre();
+ test_as_litre();
+ test_as_cubic_metre();
+ test_as_cubic_inch();
+}
diff --git a/test.h b/test.h
new file mode 100644
index 0000000..033a955
--- /dev/null
+++ b/test.h
@@ -0,0 +1,25 @@
+#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);
+void test_deg_per_sec(void);
+void test_rpm(void);
+void test_as_rad_per_sec(void);
+void test_as_deg_per_sec(void);
+void test_as_rpm(void);
+
+void test_cubic_centimetre(void);
+void test_litre(void);
+void test_cubic_metre(void);
+void test_cubic_inch(void);
+void test_as_cubic_centimetre(void);
+void test_as_litre(void);
+void test_as_cubic_metre(void);
+void test_as_cubic_inch(void);
diff --git a/test_angular_speed.c b/test_angular_speed.c
new file mode 100644
index 0000000..41f9ab6
--- /dev/null
+++ b/test_angular_speed.c
@@ -0,0 +1,35 @@
+#include <assert.h>
+#include <stdio.h>
+
+#include "test.h"
+#include "unit.h"
+
+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);
+}
diff --git a/test_unit.c b/test_unit.c
deleted file mode 100644
index d19d694..0000000
--- a/test_unit.c
+++ /dev/null
@@ -1,106 +0,0 @@
-#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);
-}
-
-
-void
-test_cubic_centimetre(void) {
- assert(0);
-}
-
-void
-test_litre(void) {
- assert(0);
-}
-
-void
-test_cubic_metre(void) {
- assert(0);
-}
-
-void
-test_cubic_inch(void) {
- assert(0);
-}
-
-void
-test_as_cubic_centimetre(void) {
- assert(0);
-}
-
-void
-test_as_litre(void) {
- assert(0);
-}
-
-void
-test_as_cubic_metre(void) {
- assert(0);
-}
-
-void
-test_as_cubic_inch(void) {
- assert(0);
-}
-
-
-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();
-
- test_cubic_centimetre();
- test_litre();
- test_cubic_metre();
- test_cubic_inch();
- test_as_cubic_centimetre();
- test_as_litre();
- test_as_cubic_metre();
- test_as_cubic_inch();
-}
diff --git a/test_volume.c b/test_volume.c
new file mode 100644
index 0000000..1dac319
--- /dev/null
+++ b/test_volume.c
@@ -0,0 +1,45 @@
+#include <assert.h>
+#include <stdio.h>
+
+#include "test.h"
+#include "unit.h"
+
+void
+test_cubic_centimetre(void) {
+ assert(0);
+}
+
+void
+test_litre(void) {
+ assert(0);
+}
+
+void
+test_cubic_metre(void) {
+ assert(0);
+}
+
+void
+test_cubic_inch(void) {
+ assert(0);
+}
+
+void
+test_as_cubic_centimetre(void) {
+ assert(0);
+}
+
+void
+test_as_litre(void) {
+ assert(0);
+}
+
+void
+test_as_cubic_metre(void) {
+ assert(0);
+}
+
+void
+test_as_cubic_inch(void) {
+ assert(0);
+}