summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/runner.c14
-rw-r--r--src/tests/test.h3
-rw-r--r--src/tests/ui_elements.c35
3 files changed, 51 insertions, 1 deletions
diff --git a/src/tests/runner.c b/src/tests/runner.c
index bdc4031..58861da 100644
--- a/src/tests/runner.c
+++ b/src/tests/runner.c
@@ -1,10 +1,13 @@
#include "test.h"
#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
const UnitTest TESTS[] = {
(UnitTest) { .Name = "Arena out of mem", .Function = ArenaOutOfMemory },
(UnitTest) { .Name = "Arena allocation", .Function = ArenaAllocation },
- (UnitTest) { .Name = "Test difficulty calculation", .Function = difficultyCalculator},
+ (UnitTest) { .Name = "Test difficulty calculation", .Function = difficultyCalculator },
+ (UnitTest) { .Name = "Timer display", .Function = timerPrintDisplay },
};
void SetGreenColor() {
@@ -36,3 +39,12 @@ int main(void) {
ResetColor();
return 0;
}
+
+char *reportError(const char *format, ...) {
+ char outp[16656];
+ va_list argptr;
+ va_start(argptr, format);
+ vsprintf(outp, format, argptr);
+ va_end(argptr);
+ return strdup(outp);
+}
diff --git a/src/tests/test.h b/src/tests/test.h
index 5994ecb..456c9e2 100644
--- a/src/tests/test.h
+++ b/src/tests/test.h
@@ -8,10 +8,13 @@ typedef struct {
char *(*Function)();
} UnitTest;
+char *reportError(const char *format, ...);
+
// ========== TESTS ==========
char *ArenaAllocation();
char *ArenaOutOfMemory();
char *difficultyCalculator();
+char *timerPrintDisplay();
#endif // TESTS_H
diff --git a/src/tests/ui_elements.c b/src/tests/ui_elements.c
new file mode 100644
index 0000000..a13492d
--- /dev/null
+++ b/src/tests/ui_elements.c
@@ -0,0 +1,35 @@
+#include "../ui_elements/UI.h"
+#include "test.h"
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+
+char *timerPrintDisplay() {
+ char buf[16];
+
+ size_t time = 0;
+ PrintTime(buf, time);
+ if (strcmp(buf, "00:00")) return reportError("The 00:00 test failed: got: '%s'", buf);
+
+ time = 3;
+ PrintTime(buf, time);
+ if (strcmp(buf, "00:03")) return reportError("The 00:03 test failed: got: '%s'", buf);
+
+ time = 30;
+ PrintTime(buf, time);
+ if (strcmp(buf, "00:30")) return reportError("The 00:30 test failed: got: '%s'", buf);
+
+ time = 60;
+ PrintTime(buf, time);
+ if (strcmp(buf, "01:00")) return reportError("The 01:00 test failed: got: '%s'", buf);
+
+ time = 63;
+ PrintTime(buf, time);
+ if (strcmp(buf, "01:03")) return reportError("The 01:03 test failed: got: '%s'", buf);
+
+ time = 60 * 100;
+ PrintTime(buf, time);
+ if (strcmp(buf, "100:00")) return reportError("The 100:00 test failed: got: '%s'", buf);
+
+ return NULL;
+}