Source file
test/strength.go
1
2
3
4
5
6
7
8
9
10 package main
11
12 import "fmt"
13
14 func testMul(fact, bits int) string {
15 n := fmt.Sprintf("testMul_%d_%d", fact, bits)
16 fmt.Printf("func %s(s int%d) {\n", n, bits)
17
18 want := 0
19 for i := 0; i < 200; i++ {
20 fmt.Printf(` if want, got := int%d(%d), s*%d; want != got {
21 failed = true
22 fmt.Printf("got %d * %%d == %%d, wanted %d\n", s, got)
23 }
24 `, bits, want, i, i, want)
25 want += fact
26 }
27
28 fmt.Printf("}\n")
29 return fmt.Sprintf("%s(%d)", n, fact)
30 }
31
32 func main() {
33 fmt.Printf("package main\n")
34 fmt.Printf("import \"fmt\"\n")
35 fmt.Printf("var failed = false\n")
36
37 f1 := testMul(17, 32)
38 f2 := testMul(131, 64)
39
40 fmt.Printf("func main() {\n")
41 fmt.Println(f1)
42 fmt.Println(f2)
43 fmt.Printf("if failed {\n panic(\"multiplication failed\")\n}\n")
44 fmt.Printf("}\n")
45 }
46
View as plain text