Skip to content

Commit

Permalink
Added adv. test 5 and 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sirmc committed May 24, 2018
1 parent 6f11f55 commit ec3c84e
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Binary file modified files/advanced/SimpleCalc.ijvm
Binary file not shown.
4 changes: 2 additions & 2 deletions files/advanced/SimpleCalc.jas
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ recurse:
INVOKEVIRTUAL printNumber
POP
INVOKEVIRTUAL printNum
POP
//POP
IRETURN
small:
LDC_W OBJREF
ILOAD a
INVOKEVIRTUAL printNum
POP
//POP
IRETURN
.end-method

Expand Down
27 changes: 27 additions & 0 deletions files/task3/IFEQ1.jas
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.constant
.end-constant

.main

L1:
BIPUSH 0x05
L2:
DUP
BIPUSH 0x30
IADD
OUT
BIPUSH 0x01
ISUB
DUP
IFEQ L3
GOTO L2
L3:
BIPUSH 0x65
BIPUSH 0x6E
BIPUSH 0x6F
BIPUSH 0x64
OUT
OUT
OUT
OUT
.end-main
Binary file modified files/task3/IFLT1.ijvm
Binary file not shown.
31 changes: 31 additions & 0 deletions files/task3/IFLT1.jas
Original file line number Diff line number Diff line change
@@ -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

60 changes: 60 additions & 0 deletions tests/testadvanced5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <stdio.h>
#include <string.h>
#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();
}
55 changes: 55 additions & 0 deletions tests/testadvanced6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <stdio.h>
#include <string.h>
#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();
}

0 comments on commit ec3c84e

Please sign in to comment.