From ec3c84e34496d3faf2fff9b78ee42092fbcca404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20=C3=96sterlund?= Date: Thu, 24 May 2018 15:58:14 +0200 Subject: [PATCH] Added adv. test 5 and 6 --- Makefile | 6 ++-- files/advanced/SimpleCalc.ijvm | Bin 516 -> 514 bytes files/advanced/SimpleCalc.jas | 4 +-- files/task3/IFEQ1.jas | 27 +++++++++++++++ files/task3/IFLT1.ijvm | Bin 57 -> 57 bytes files/task3/IFLT1.jas | 31 +++++++++++++++++ tests/testadvanced5.c | 60 +++++++++++++++++++++++++++++++++ tests/testadvanced6.c | 55 ++++++++++++++++++++++++++++++ 8 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 files/task3/IFEQ1.jas create mode 100644 files/task3/IFLT1.jas create mode 100644 tests/testadvanced5.c create mode 100644 tests/testadvanced6.c diff --git a/Makefile b/Makefile index 5130b1c..55f46fd 100644 --- a/Makefile +++ b/Makefile @@ -65,9 +65,9 @@ run_test%: test% testbasic: run_test1 run_test2 run_test3 run_test4 run_test5 -testadvanced: run_testadvanced1 run_testadvanced2 run_testadvanced3 run_testadvanced4 run_testadvancedstack +testadvanced: run_testadvanced1 run_testadvanced2 run_testadvanced3 run_testadvanced4 run_testadvanced5 run_testadvanced6 run_testadvancedstack testall: testbasic testadvanced -build_tests: test1 test2 test3 test4 test5 testadvanced1 testadvanced2 testadvanced3 testadvanced4 testadvancedstack +build_tests: test1 test2 test3 test4 test5 testadvanced1 testadvanced2 testadvanced3 testadvanced4 testadvanced5 testadvanced6 testadvancedstack # Uses LLVM sanitizers testasan: CC=clang @@ -94,6 +94,8 @@ testleaks: build_tests valgrind --leak-check=full ./testadvanced2 valgrind --leak-check=full ./testadvanced3 valgrind --leak-check=full ./testadvanced4 + valgrind --leak-check=full ./testadvanced5 + valgrind --leak-check=full ./testadvanced6 valgrind --leak-check=full ./testadvancedstack coverage: CFLAGS+=-fprofile-instr-generate -fcoverage-mapping diff --git a/files/advanced/SimpleCalc.ijvm b/files/advanced/SimpleCalc.ijvm index c85f24bd9cec1ad3e576a3991591d470b89fd9f4..204f99fd6d2094debdcc6397294310ed53ca861f 100644 GIT binary patch delta 55 zcmZo+X=0gRFUiNiz$gR6Za|y|#GMRaz_@B+#3M%4$<~aDoNI&`7(^MjG4M=IXPgTF D`1T4W delta 57 zcmZo-X?*IS* delta 9 QcmcDtoFLCwKT$yv01Sx&YybcN diff --git a/files/task3/IFLT1.jas b/files/task3/IFLT1.jas new file mode 100644 index 0000000..fda66dd --- /dev/null +++ b/files/task3/IFLT1.jas @@ -0,0 +1,31 @@ +.constant +.end-constant + +.main + +L1: + BIPUSH 0x00 + IFLT L6 +L2: + BIPUSH 0x01 + IFLT L6 +L3: + BIPUSH 0x02 + IFLT L6 +L4: + BIPUSH 0x10 + BIPUSH 0x11 + ISUB + IFLT L6 +L5: + BIPUSH 0x00 + BIPUSH 0x00 + BIPUSH 0x00 + BIPUSH 0x00 + BIPUSH 0x00 + HALT +L6: + BIPUSH 0x37 + HALT +.end-main + diff --git a/tests/testadvanced5.c b/tests/testadvanced5.c new file mode 100644 index 0000000..b56b922 --- /dev/null +++ b/tests/testadvanced5.c @@ -0,0 +1,60 @@ +#include +#include +#include "ijvm.h" +#include "testutil.h" + +void run_calc_inp(char *input, char *expected) +{ + int res = init_ijvm("files/advanced/SimpleCalc.ijvm"); + assert(res != -1); + + char buf[128]; + FILE *f = tmpfile(); + fprintf(f, "%s", input); + rewind(f); + set_input(f); + + FILE *out_file = tmpfile(); + set_output(out_file); + + // Run program + run(); + + rewind(out_file); + memset(buf, '\0', 128); + fread(buf, 1, 127, out_file); + + // Compare output + assert(strncmp(buf, expected, strlen(expected)) == 0); + + destroy_ijvm(); + +} + +void test_calc_1() +{ + run_calc_inp("0 0 + ? .", "0\n"); + run_calc_inp("0 9 + ? .", "9\n"); + run_calc_inp("9 0 + ? .", "9\n"); + run_calc_inp("9 9 - ? .", "0\n"); +} + +void test_calc_2() +{ + run_calc_inp(" 5 4 -?.", "1\n"); + run_calc_inp(" 8 8 8 - + ?.", "8\n"); +} + +void test_calc_3() +{ + run_calc_inp("1 1 + 1 1 + 1 1 + 1 1 + 1 1 + +-++?.", "2\n"); + run_calc_inp("9 8 -9 7-9 6-9 5-9 4-9 3-9 2-9 1-9 0- -+-+-+-+?.", "1\n"); +} + +int main() +{ + RUN_TEST(test_calc_1); + RUN_TEST(test_calc_2); + RUN_TEST(test_calc_3); + return END_TEST(); +} diff --git a/tests/testadvanced6.c b/tests/testadvanced6.c new file mode 100644 index 0000000..66b73a3 --- /dev/null +++ b/tests/testadvanced6.c @@ -0,0 +1,55 @@ +#include +#include +#include "ijvm.h" +#include "testutil.h" + +void run_calc_inp(char *input, char *expected) +{ + int res = init_ijvm("files/advanced/SimpleCalc.ijvm"); + assert(res != -1); + + char buf[128]; + FILE *f = tmpfile(); + fprintf(f, "%s", input); + rewind(f); + set_input(f); + + FILE *out_file = tmpfile(); + set_output(out_file); + + // Run program + run(); + + rewind(out_file); + memset(buf, '\0', 128); + fread(buf, 1, 127, out_file); + + // Compare output + assert(strncmp(buf, expected, strlen(expected)) == 0); + + destroy_ijvm(); + +} + +void test_rec_1() +{ + run_calc_inp("2!?.", "2\n"); +} + +void test_rec_2() +{ + run_calc_inp("7!?.", "5040\n"); +} + +void test_rec_3() +{ + run_calc_inp("8!?.", "40320\n"); +} + +int main() +{ + RUN_TEST(test_rec_1); + RUN_TEST(test_rec_2); + RUN_TEST(test_rec_3); + return END_TEST(); +}