summaryrefslogtreecommitdiff
path: root/src/puzzles/puzzle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/puzzles/puzzle.c')
-rw-r--r--src/puzzles/puzzle.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/puzzles/puzzle.c b/src/puzzles/puzzle.c
index 6d0a4a0..e14708f 100644
--- a/src/puzzles/puzzle.c
+++ b/src/puzzles/puzzle.c
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <wren.h>
+#include <stdbool.h>
static const char *USER_MODULE_NAME = "main";
@@ -37,12 +38,20 @@ Puzzle *GetTestPuzzle() {
return outp;
}
+void FreePuzzleIO(PuzzleIO *io) {
+ if (io->value != NULL)
+ free(io->value);
+}
+
void FreeTests(Test *Tests, size_t TestC) {
if (TestC == 0 || Tests == NULL) return;
for (size_t i = 0; i < TestC; i++) {
Test *t = &Tests[i];
if (t->RecieverName != NULL) free(t->RecieverName);
if (t->MainMethodSignature != NULL) free(t->MainMethodSignature);
+ for (size_t j = 0; j < t->argc; j++) {
+ FreePuzzleIO(&t->argv[j]);
+ }
if (t->argv != NULL) free(t->argv);
}
free(Tests);
@@ -362,3 +371,44 @@ void FreeSunmitionResult(SubmitionResult *res) {
if (res->stdout_sb != NULL) free(res->stdout_sb);
free(res);
}
+
+void PrintPuzzle(Puzzle *puzzle) {
+ printf("Puzzle name: %s\n", puzzle->Name);
+ printf("Puzzle description: %s\n", puzzle->Description);
+ printf("Puzzle code: %s\n", puzzle->InitialCode);
+ printf("Puzzle TestC: %zu\n", puzzle->TestC);
+
+ for (int i = 0; i < puzzle->TestC; i++) {
+ Test t = puzzle->Tests[i];
+ printf("\nTest %d:\n", i);
+ printf("\tTest rec: %s\n", t.RecieverName);
+ printf("\tTest sig: %s\n", t.MainMethodSignature);
+ printf("\tTest argc: %zu\n", t.argc);
+ printf("\tArguments:\n");
+
+ for (int j = 0; j < t.argc; j++) {
+ PuzzleIO io = t.argv[j];
+ switch (io.type) {
+ case WREN_TYPE_BOOL:
+ printf("\t\t(bool)%s\n", *(bool *)io.value ? "true" : "false");
+ break;
+ case WREN_TYPE_NUM:
+ printf("\t\t(num)%f\n", *(float *)io.value);
+ break;
+ case WREN_TYPE_LIST:
+ printf("\t\t(list)NOT SUPPORTED\n");
+ break;
+ case WREN_TYPE_MAP:
+ printf("\t\t(list)NOT SUPPORTED\n");
+ break;
+ case WREN_TYPE_NULL:
+ printf("\t\t(null)\n");
+ break;
+ case WREN_TYPE_STRING:
+ printf("\t\t(string)%s\n", (char *)io.value);
+ break;
+ default: break;
+ }
+ }
+ }
+}