-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrds8_test.go
109 lines (103 loc) · 2 KB
/
trds8_test.go
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
99
100
101
102
103
104
105
106
107
108
109
package trds8
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/thzoid/trds-8/in"
)
func TestSimpleTemporalBranchProgram(t *testing.T) {
program := []byte{
in.O(in.OPEN_U),
in.O(in.LOAD_A),
in.V(0xE),
in.O(in.SUB),
in.R2(in.REG_U, in.REG_A),
in.O(in.JUMP_Z),
in.V(0x9),
in.O(in.HALT),
in.V(0xF),
in.O(in.LOAD_U),
in.V(0xF),
in.O(in.CLOSE_U),
in.O(in.HALT),
in.V(0xE),
in.S(0),
in.S(1),
}
results, _ := RunTemporal(program, 2)
assert.Equal(t, results[0], int8(0))
assert.Equal(t, results[1], int8(1))
}
func TestTemporalParadoxicalProgram(t *testing.T) {
program := []byte{
in.O(in.OPEN_U),
in.O(in.LOAD_A),
in.V(0x11),
in.O(in.SUB),
in.R2(in.REG_U, in.REG_A),
in.O(in.JUMP_Z),
in.V(0xC),
in.O(in.LOAD_U),
in.V(0x11),
in.O(in.CLOSE_U),
in.O(in.HALT),
in.V(0x11),
in.O(in.LOAD_U),
in.V(0x12),
in.O(in.CLOSE_U),
in.O(in.HALT),
in.V(0x12),
in.S(0),
in.S(1),
}
results, _ := RunTemporal(program, 4)
assert.Equal(t, results[0], results[2])
assert.Equal(t, results[1], results[3])
assert.NotEqual(t, results[0], results[1])
}
func TestTemporalIterationReductionProgram(t *testing.T) {
// Program
program := []byte{
in.O(in.OPEN_U),
in.O(in.LOAD_A),
in.V(0x22),
in.O(in.SUB),
in.R2(in.REG_U, in.REG_A),
in.O(in.OPEN_V),
in.O(in.JUMP_Z),
in.V(0xC),
in.O(in.STORE_V),
in.V(0x26),
in.O(in.HALT),
in.V(0x26),
in.O(in.LOAD_A),
in.V(0x24),
in.O(in.LOAD_B),
in.V(0x25),
in.O(in.MUL),
in.R2(in.REG_A, in.REG_B),
in.O(in.ADD),
in.R2(in.REG_A, in.REG_B),
in.O(in.MUL),
in.R2(in.REG_A, in.REG_B),
in.O(in.XOR),
in.R2(in.REG_A, in.REG_B),
in.O(in.STORE_A),
in.V(0x26),
in.O(in.LOAD_V),
in.V(0x26),
in.O(in.CLOSE_V),
in.O(in.LOAD_U),
in.V(0x23),
in.O(in.CLOSE_U),
in.O(in.HALT),
in.V(0x26),
in.S(0),
in.S(1),
in.S(-2),
in.S(3),
in.S(0),
}
results, iterations := RunTemporal(program, 2)
assert.Equal(t, results[0], results[1])
assert.Greater(t, iterations[0], iterations[1])
}