Skip to content

Commit

Permalink
Run quotient tests only on the Jack interpreter
Browse files Browse the repository at this point in the history
And fix an error
  • Loading branch information
mossprescott committed Mar 25, 2024
1 parent 9cd4b62 commit 96db8c2
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions alt/scheme/test_rvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
SHOW_ALL_LABELS = False


# TODO: put this somewhere common:
def parameterize(f):
def vector(chip, **args):
return run_to_halt(chip, simulator="vector", interpreter="assembly", **args)
def codegen(chip, **args):
return run_to_halt(chip, simulator="codegen", interpreter="assembly", **args)
def jack(chip, **args):
return run_to_halt(chip, simulator="codegen", interpreter="jack", **args)
return pytest.mark.parametrize("run", [vector, codegen, jack])(f)
def vector(program, **args):
return run_to_halt(program, simulator="vector", interpreter="jack", **args)
def codegen(program, **args):
return run_to_halt(program, simulator="codegen", interpreter="jack", **args)
def assembly(program, **args):
return run_to_halt(program, simulator="codegen", interpreter="assembly", **args)
return pytest.mark.parametrize("run", [vector, codegen, assembly])(f)


def run_jack(program):
return run_to_halt(program=program, simulator="codegen", interpreter="jack")


@parameterize
def test_trivial(run):
Expand Down Expand Up @@ -93,21 +97,21 @@ def test_mul_mixed_signs(run):
assert output == []


@parameterize
def test_quotient(run):
# Note: not implemented in assembly
def test_quotient():
program = "(quotient 123 10)"

inspect, output = run(program)
inspect, output = run_jack(program)

assert inspect.stack() == [12]
assert output == []


@parameterize
def test_quotient_mixed_signs(run):
program = several("(quotient 6 -3)", "(quotient -14 -3)", "(* 21 -2)")
# Note: not implemented in assembly
def test_quotient_mixed_signs():
program = several("(quotient 6 -3)", "(quotient -14 -3)", "(quotient 21 -2)")

inspect, output = run(program)
inspect, output = run_jack(program)

assert inspect.stack() == [[-2, 4, -10]]
assert output == []
Expand Down

0 comments on commit 96db8c2

Please sign in to comment.