From 665e21b4427f40fd8317001b144be66b313955e8 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 4 Jul 2019 15:37:06 -0700 Subject: [PATCH] Added basic tests for stack and arithmetic IMPs. --- Makefile | 2 +- tests/1001_stack_push.pvvs | 5 +++++ tests/1002_stack_dup.pvvs | 7 +++++++ ...stack_operations.pvvs => 1003_stack_swap.pvvs} | 6 ++---- tests/1004_stack_drop.pvvs | 7 +++++++ tests/2001_arithmetic_addition.pvvs | 7 +++++++ tests/2002_arithmetic_subtraction.pvvs | 7 +++++++ tests/2003_arithmetic_multiplication.pvvs | 7 +++++++ tests/2004_arithmetic_division.pvvs | 7 +++++++ tests/2005_arithmetic_remainder.pvvs | 7 +++++++ vv_test.py | 15 ++++++++++++--- 11 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 tests/1001_stack_push.pvvs create mode 100644 tests/1002_stack_dup.pvvs rename tests/{1001_stack_operations.pvvs => 1003_stack_swap.pvvs} (64%) create mode 100644 tests/1004_stack_drop.pvvs create mode 100644 tests/2001_arithmetic_addition.pvvs create mode 100644 tests/2002_arithmetic_subtraction.pvvs create mode 100644 tests/2003_arithmetic_multiplication.pvvs create mode 100644 tests/2004_arithmetic_division.pvvs create mode 100644 tests/2005_arithmetic_remainder.pvvs diff --git a/Makefile b/Makefile index 6759c97..1412ac5 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ vvc: $(CC) $(CC_FLAGS) -o $@ vv_compiler.c test: all - @echo "Starting test suite..." + @echo "Starting test suite:" @./vv_test.py clean: diff --git a/tests/1001_stack_push.pvvs b/tests/1001_stack_push.pvvs new file mode 100644 index 0000000..234d4c7 --- /dev/null +++ b/tests/1001_stack_push.pvvs @@ -0,0 +1,5 @@ +# This test verifies stack IMP push. + +SSSTSSSSSTN | ST: Push +65 (ASCII A) +TNSS | IO: Output character +NNN | FC: Terminate program diff --git a/tests/1002_stack_dup.pvvs b/tests/1002_stack_dup.pvvs new file mode 100644 index 0000000..f405eeb --- /dev/null +++ b/tests/1002_stack_dup.pvvs @@ -0,0 +1,7 @@ +# This test verifies stack IMP duplicate. + +SSSTSSSSSTN | ST: Push +65 (ASCII A) +SNS | ST: Duplicate TOS +TNSS | IO: Output character +TNSS | IO: Output character +NNN | FC: Terminate program diff --git a/tests/1001_stack_operations.pvvs b/tests/1003_stack_swap.pvvs similarity index 64% rename from tests/1001_stack_operations.pvvs rename to tests/1003_stack_swap.pvvs index d8333e4..9e18a9f 100644 --- a/tests/1001_stack_operations.pvvs +++ b/tests/1003_stack_swap.pvvs @@ -1,10 +1,8 @@ -# This test verifies operations under the Stack IMP ([Space]). +# This test verifies stack IMP swap. SSSTSSSSSTN | ST: Push +65 (ASCII A) SSSTSSSSTSN | ST: Push +66 (ASCII B) -SNS | ST: Duplicate TOS -TNSS | IO: Output character SNT | ST: Swap TOS and NOS -SNN | ST: Discard TOS +TNSS | IO: Output character TNSS | IO: Output character NNN | FC: Terminate program diff --git a/tests/1004_stack_drop.pvvs b/tests/1004_stack_drop.pvvs new file mode 100644 index 0000000..55dd6b6 --- /dev/null +++ b/tests/1004_stack_drop.pvvs @@ -0,0 +1,7 @@ +# This test verifies stack IMP drop. + +SSSTSSSSSTN | ST: Push +65 (ASCII A) +SSSTSSSSTSN | ST: Push +66 (ASCII B) +SNN | ST: Discard TOS +TNSS | IO: Output character +NNN | FC: Terminate program diff --git a/tests/2001_arithmetic_addition.pvvs b/tests/2001_arithmetic_addition.pvvs new file mode 100644 index 0000000..40b3c82 --- /dev/null +++ b/tests/2001_arithmetic_addition.pvvs @@ -0,0 +1,7 @@ +# This test verifies arithmetic IMP addition. + +SSSTSSSSSTN | ST: Push +65 (ASCII A) +SSSTN | ST: Push +1 +TSSS | MA: Add +TNSS | IO: Output character +NNN | FC: Terminate program diff --git a/tests/2002_arithmetic_subtraction.pvvs b/tests/2002_arithmetic_subtraction.pvvs new file mode 100644 index 0000000..574e6e1 --- /dev/null +++ b/tests/2002_arithmetic_subtraction.pvvs @@ -0,0 +1,7 @@ +# This test verifies arithmetic IMP subtraction. + +SSSTSSSSTSN | ST: Push +66 (ASCII B) +SSSTN | ST: Push +1 +TSST | MA: Subtract +TNSS | IO: Output character +NNN | FC: Terminate program diff --git a/tests/2003_arithmetic_multiplication.pvvs b/tests/2003_arithmetic_multiplication.pvvs new file mode 100644 index 0000000..7aa1c7c --- /dev/null +++ b/tests/2003_arithmetic_multiplication.pvvs @@ -0,0 +1,7 @@ +# This test verifies arithmetic IMP multiplication. + +SSSTSSSSTN | ST: Push +33 +SSSTSN | ST: Push +2 +TSSN | MA: Multiply +TNSS | IO: Output character +NNN | FC: Terminate program diff --git a/tests/2004_arithmetic_division.pvvs b/tests/2004_arithmetic_division.pvvs new file mode 100644 index 0000000..a21f5af --- /dev/null +++ b/tests/2004_arithmetic_division.pvvs @@ -0,0 +1,7 @@ +# This test verifies arithmetic IMP division. + +SSSTSSSSSTSN | ST: Push +130 +SSSTSN | ST: Push +2 +TSTS | MA: Divide +TNSS | IO: Output character +NNN | FC: Terminate program diff --git a/tests/2005_arithmetic_remainder.pvvs b/tests/2005_arithmetic_remainder.pvvs new file mode 100644 index 0000000..d54c381 --- /dev/null +++ b/tests/2005_arithmetic_remainder.pvvs @@ -0,0 +1,7 @@ +# This test verifies arithmetic IMP remainder. + +SSSTTSSSSTSN | ST: Push +194 +SSSTSSSSSSTN | ST: Push +128 +TSTT | MA: Remainder +TNSS | IO: Output character +NNN | FC: Terminate program diff --git a/vv_test.py b/vv_test.py index 46f5bc9..4a31280 100755 --- a/vv_test.py +++ b/vv_test.py @@ -15,16 +15,25 @@ src_extension = '.pvvs' tests = [ ['0001_push_printchar_exit', 'A'], - ['1001_stack_operations', 'BB'] + ['1001_stack_push', 'A'], + ['1002_stack_dup', 'AA'], + ['1003_stack_swap', 'AB'], + ['1004_stack_drop', 'A'], + ['2001_arithmetic_addition', 'B'], + ['2002_arithmetic_subtraction', 'A'], + ['2003_arithmetic_multiplication', 'B'], + ['2004_arithmetic_division', 'A'], + ['2005_arithmetic_remainder', 'A'], ] for test in tests: + # TODO: Catch stderr subprocess.run([compiler_path, '-i', path_to_tests + test[0] + src_extension, '-o', temp_file]) result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE) if result.stdout.decode('utf-8') != test[1]: - print(test[0]) + print('\n' + test[0]) else: - print('.', end='') + print('.', end='', flush=True) os.remove(temp_file) print("") -- 2.20.1