-
Notifications
You must be signed in to change notification settings - Fork 0
/
intcode_controller_test.py
74 lines (55 loc) · 1.88 KB
/
intcode_controller_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from intcode_controller import *
def test_program_from_text():
# Normal text
out = Program.from_text("1,2,3,4")
assert out == [1, 2, 3, 4]
# Text with newlines
out = Program.from_text("1,2,\n\n3,4")
assert out == [1, 2, 3, 4]
# Text with multiple commas
out = Program.from_text("1,2,,,3,,4")
assert out == [1, 2, 3, 4]
# Text with newlines and multiple commas
out = Program.from_text("1,2,\n,,\n,3,4")
assert out == [1, 2, 3, 4]
# Text with newlines, multiple commas and spaces
out = Program.from_text("1 2,\n,,\n,3, 4")
assert out == [1, 2, 3, 4]
# Text with newlines, multiple commas, spaces and comments
out = Program.from_text("1 2,\n# Comment,\n\n,3, 4")
assert out == [1, 2, 3, 4]
# Text with newlines, multiple commas, spaces and comments at beginning
out = Program.from_text("#Comment at begin\n1 2,\n# Comment,\n\n,3, 4")
assert out == [1, 2, 3, 4]
def test_program_getitem():
program = Program([1, 2, 3, 4])
# Normal get
assert 1 == program[0]
assert 4 == program[3]
assert 0 == program[4]
# Expecting automatic extending with default value 0
assert 0 == program[42]
def test_program_setitem():
program = Program([1, 2, 3, 4])
# Normal set
program[0] = 42
assert 42 == program[0]
# Expecting automatic extending
program[42] = 1337
assert 1337 == program[42]
def test_program_exec():
program = Program([1, 2, 3, 4])
# Normal get
out = program.exec(['GET', '0'])
assert out == 1
# Normal set
program.exec(['SET', '0', '42'])
out = program.exec(['GET', '0'])
assert out == 42
# Get with automatic extending with default value 0
out = program.exec(['GET', '20'])
assert out == 0
# Set with automatic extending
program.exec(['SET', '42', '1337'])
out = program.exec(['GET', '42'])
assert out == 1337