Source file
test/mergemul.go
1
2
3
4
5
6
7 package main
8
9 import "fmt"
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 func makeMergeAddTest(m1, m2, k int, size string) string {
28
29 model := " a" + size + ", b" + size
30 model += fmt.Sprintf(" = %%d*n%s + %%d*(n%s+%%d), (%%d+%%d)*n%s + (%%d*%%d)", size, size, size)
31
32 test := fmt.Sprintf(model, m1, m2, k, m1, m2, m2, k)
33 test += fmt.Sprintf(`
34 if a%s != b%s {
35 fmt.Printf("MergeAddTest(%d, %d, %d, %s) failed\n")
36 fmt.Printf("%%d != %%d\n", a%s, b%s)
37 panic("FAIL")
38 }
39 `, size, size, m1, m2, k, size, size, size)
40 return test + "\n"
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 func makeMergeSubTest(m1, m2, k int, size string) string {
60
61 model := " a" + size + ", b" + size
62 model += fmt.Sprintf(" = %%d*n%s - %%d*(n%s+%%d), (%%d-%%d)*n%s - (%%d*%%d)", size, size, size)
63
64 test := fmt.Sprintf(model, m1, m2, k, m1, m2, m2, k)
65 test += fmt.Sprintf(`
66 if a%s != b%s {
67 fmt.Printf("MergeSubTest(%d, %d, %d, %s) failed\n")
68 fmt.Printf("%%d != %%d\n", a%s, b%s)
69 panic("FAIL")
70 }
71 `, size, size, m1, m2, k, size, size, size)
72 return test + "\n"
73 }
74
75 func makeAllSizes(m1, m2, k int) string {
76 var tests string
77 tests += makeMergeAddTest(m1, m2, k, "8")
78 tests += makeMergeAddTest(m1, m2, k, "16")
79 tests += makeMergeAddTest(m1, m2, k, "32")
80 tests += makeMergeAddTest(m1, m2, k, "64")
81 tests += makeMergeSubTest(m1, m2, k, "8")
82 tests += makeMergeSubTest(m1, m2, k, "16")
83 tests += makeMergeSubTest(m1, m2, k, "32")
84 tests += makeMergeSubTest(m1, m2, k, "64")
85 tests += "\n"
86 return tests
87 }
88
89 func main() {
90 fmt.Println(`package main
91
92 import "fmt"
93
94 var n8 int8 = 42
95 var n16 int16 = 42
96 var n32 int32 = 42
97 var n64 int64 = 42
98
99 func main() {
100 var a8, b8 int8
101 var a16, b16 int16
102 var a32, b32 int32
103 var a64, b64 int64
104 `)
105
106 fmt.Println(makeAllSizes(03, 05, 0))
107 fmt.Println(makeAllSizes(17, 33, 0))
108 fmt.Println(makeAllSizes(80, 45, 0))
109 fmt.Println(makeAllSizes(32, 64, 0))
110
111 fmt.Println(makeAllSizes(7, 11, +1))
112 fmt.Println(makeAllSizes(9, 13, +2))
113 fmt.Println(makeAllSizes(11, 16, -1))
114 fmt.Println(makeAllSizes(17, 9, -2))
115
116 fmt.Println("}")
117 }
118
View as plain text