File tree 1 file changed +74
-0
lines changed
1 file changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ package acc
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/mmcloughlin/addchain/acc/eval"
7
+ "github.com/mmcloughlin/addchain/acc/pass"
8
+ "github.com/mmcloughlin/addchain/alg/ensemble"
9
+ "github.com/mmcloughlin/addchain/alg/exec"
10
+ "github.com/mmcloughlin/addchain/internal/bigint"
11
+ "github.com/mmcloughlin/addchain/internal/results"
12
+ "github.com/mmcloughlin/addchain/internal/test"
13
+ )
14
+
15
+ func TestResults (t * testing.T ) {
16
+ timer := test .Start ()
17
+ as := ensemble .Ensemble ()
18
+ for _ , c := range results .Results {
19
+ c := c // scopelint
20
+ t .Run (c .Slug , func (t * testing.T ) {
21
+ timer .Check (t )
22
+
23
+ // Execute.
24
+ ex := exec .NewParallel ()
25
+ rs := ex .Execute (c .Target (), as )
26
+
27
+ // Check each result.
28
+ for _ , r := range rs {
29
+ if r .Err != nil {
30
+ t .Fatalf ("error with %s: %v" , r .Algorithm , r .Err )
31
+ }
32
+
33
+ // Decompile into IR.
34
+ p , err := Decompile (r .Program )
35
+ if err != nil {
36
+ t .Fatal (err )
37
+ }
38
+
39
+ // Allocate.
40
+ a := pass.Allocator {
41
+ Input : "x" ,
42
+ Output : "z" ,
43
+ Format : "t%d" ,
44
+ }
45
+ if err := a .Execute (p ); err != nil {
46
+ t .Fatal (err )
47
+ }
48
+
49
+ // Evaluate.
50
+ i := eval .NewInterpreter ()
51
+ x := bigint .One ()
52
+ i .Store (a .Input , x )
53
+ i .Store (a .Output , x )
54
+
55
+ if err := i .Execute (p ); err != nil {
56
+ t .Fatal (err )
57
+ }
58
+
59
+ // Verify output.
60
+ output , ok := i .Load (a .Output )
61
+ if ! ok {
62
+ t .Fatalf ("missing output variable %q" , a .Output )
63
+ }
64
+
65
+ expect := r .Chain .End ()
66
+
67
+ if ! bigint .Equal (output , expect ) {
68
+ t .FailNow ()
69
+ }
70
+
71
+ }
72
+ })
73
+ }
74
+ }
You can’t perform that action at this time.
0 commit comments