AoC19/test/intcode/assembler_test.exs

80 lines
1.4 KiB
Elixir

defmodule AssemblerTest do
use ExUnit.Case
doctest Assembler
test "assembles empty program" do
assert Assembler.assemble("") == []
end
test "assembles simple program" do
program = """
add 1, 2, 10
mul 2, 3, 11
add $10, $11, 12
hlt
"""
assert Assembler.assemble(program) == [
1101,
1,
2,
10,
1102,
2,
3,
11,
1,
10,
11,
12,
99
]
end
test "assembles simple program with a label" do
program = """
add 1, 2, 10
jnz $10, nonZero
nonZero:
hlt
"""
assert Assembler.assemble(program) == [
1101,
1,
2,
10,
1005,
10,
7,
99
]
end
test "assembles a simple program with a data label" do
program = """
add 1, 2, var
out $var
var: 0
"""
assert Assembler.assemble(program) == [
1101,
1,
2,
6,
4,
6,
0
]
end
test "assembles a program with a _self label" do
program = """
add 1, 2, _self
"""
assert Assembler.assemble(program) == [1101, 1, 2, 3]
end
end