Skip to content

Commit

Permalink
Add failing array test
Browse files Browse the repository at this point in the history
  • Loading branch information
iafisher committed Dec 18, 2018
1 parent a839ed5 commit 24e43dd
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
88 changes: 88 additions & 0 deletions test/assets/cs240/array.hera
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
CONSTANT(N, 100)
DLABEL(ARRAY)
DSKIP(N)
DLABEL(SUM)
INTEGER(0)

// R3: pointer to current array cell
SET(R3, ARRAY)
SET(Rt, N)
// R4: upper bound
ADD(R4, Rt, R3)
// R5: current array index plus 1 (i.e., R3 - ARRAY + 1)
SET(R5, 1)

LABEL(fill_loop)
CMP(R3, R4)
BZ(fill_end)
STORE(R5, 0, R3)
INC(R3, 1)
INC(R5, 1)
BR(fill_loop)
LABEL(fill_end)

// R3: pointer to current array cell
SET(R3, ARRAY)
// R5: current sum
SET(R5, 0)

LABEL(sum_loop)
CMP(R3, R4)
BZ(sum_end)
LOAD(Rt, 0, R3)
ADD(R5, R5, Rt)
INC(R3, 1)
BR(sum_loop)
LABEL(sum_end)

SET(R1, SUM)
STORE(R5, 0, R1)

/*
CODE:
e301
f3c0
eb64
fb00
a4b3
e501
f500
3068
b034
eb12
fb00
180b
6503
3380
3580
eb07
fb00
100b
e301
f3c0
e500
f500
3068
b034
eb21
fb00
180b
4b03
a55b
3380
eb16
fb00
100b
e165
f1c0
6501

OUTPUT:
r1 = 0x41cb = 040713 = 16843
r2 = 0x0000 = 00 = 0
r3 = 0x41cb = 040713 = 16843
r4 = 0x41cb = 040713 = 16843
r5 = 0x13ba = 011672 = 5050

Carry and zero are ON
*/
20 changes: 20 additions & 0 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,26 @@ def test_simple_include_dot_hera():
assert not vm.flag_carry_block


def test_cs240_array_dot_hera():
vm = VirtualMachine()
main(["test/assets/cs240/array.hera"], vm)

assert vm.registers[5] == 5050

for r in vm.registers[6:11]:
assert r == 0

assert not vm.flag_sign
assert vm.flag_zero
assert not vm.flagoverflow
assert vm.flag_carry
assert not vm.flag_carry_block

for i in range(100):
assert vm.memory[HERA_DATA_START+i] == i+1
assert vm.memory[HERA_DATA_START+100] == 5050


def test_error_message_for_missing_comma(capsys):
with pytest.raises(SystemExit):
# SETLO(R1 40)
Expand Down

0 comments on commit 24e43dd

Please sign in to comment.