-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntComputer-test.jl
99 lines (78 loc) · 2.49 KB
/
IntComputer-test.jl
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using Revise
using Test
includet("IntComputer.jl")
using .IntComputer
@testset "IntComputer" begin
code = [1,0,0,0,99]; run!(code)
@test code == [2,0,0,0,99]
code = [2,3,0,3,99]; run!(code)
@test code == [2,3,0,6,99]
code = [2,4,4,5,99,0]; run!(code)
@test code == [2,4,4,5,99,9801]
code = [1,1,1,4,99,5,6,0,99]; run!(code)
@test code == [30,1,1,4,2,5,6,0,99]
code = intcode_from_file("2.input");
code[2] = 12
code[3] = 2
run!(code)
@test code[1] == 4023471
code = intcode_from_file("5.input");
res = run!(code,input=[1])
@test res[end] == 12428642
function eq8(x)
codePos = [3,9,8,9,10,9,4,9,99,-1,8]
codeImm = [3,3,1108,-1,8,3,4,3,99]
first(run!(codePos,input=[x])) == 1 && first(run!(codeImm,input=[x])) == 1
end
function lt8(x)
codePos = [3,9,7,9,10,9,4,9,99,-1,8]
codeImm = [3,3,1107,-1,8,3,4,3,99]
first(run!(codePos,input=[x])) == 1 && first(run!(codeImm,input=[x])) == 1
end
@test eq8(8)
@test !eq8(-1)
@test !eq8(9)
@test !eq8(123)
@test !eq8(123234234)
@test !eq8(0)
@test !lt8(8)
@test lt8(-1)
@test !lt8(9)
@test !lt8(123)
@test !lt8(123234234)
@test lt8(0)
function isZero(x)
codePos = [3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9]
codeImm = [3,3,1105,-1,9,1101,0,0,12,4,12,99,1]
first(run!(codePos,input=[x])) == 0 && first(run!(codeImm,input=[x])) == 0
end
@test !isZero(1)
@test !isZero(-1)
@test !isZero(100)
@test !isZero(123123)
@test isZero(0)
function larger8(x)
code = [3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,
1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,
999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99]
first(run!(code,input=[x]))
end
@test larger8(10) == 1001
@test larger8(-9) == 999
@test larger8(8) == 1000
code = intcode_from_file("5.input");
@test run!(code,input=[5]) == [918655,]
code = [109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99]
res = run!(code)
@test code[1:16] == res
code = [1102,34915192,34915192,7,4,7,99,0]
res = run!(code)
@test length(digits(res[1])) == 16
code = [104,1125899906842624,99]
res = run!(code)
@test res[1] == code[2]
code = intcode_from_file("9.input")
@test run!(code,input=[1]) == [3063082071, ]
code = intcode_from_file("9.input")
@test run!(code,input=[2]) == [81348, ]
end