]> Cypherpunks.ru repositories - gostls13.git/blob - test/simassign.go
missed a couple of files in test
[gostls13.git] / test / simassign.go
1 // $G $F.go && $L $F.$A && ./$A.out
2
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package main
8
9 var     a,b,c,d,e,f,g,h,i int;
10
11 func
12 printit() {
13         println(a,b,c,d,e,f,g,h,i);
14 }
15
16 func
17 testit(permuteok bool) bool {
18         if a+b+c+d+e+f+g+h+i != 45 {
19                 print("sum does not add to 45\n");
20                 printit();
21                 return false;
22         }
23         return  permuteok ||
24                 a == 1 &&
25                 b == 2 &&
26                 c == 3 &&
27                 d == 4 &&
28                 e == 5 &&
29                 f == 6 &&
30                 g == 7 &&
31                 h == 8 &&
32                 i == 9;
33 }
34
35 func
36 swap(x, y int) (u, v int) {
37         return y, x
38 }
39
40 func
41 main() {
42         a = 1;
43         b = 2;
44         c = 3;
45         d = 4;
46         e = 5;
47         f = 6;
48         g = 7;
49         h = 8;
50         i = 9;
51
52         if !testit(false) { panic("init val\n"); }
53
54         for z:=0; z<100; z++ {
55                 a,b,c,d, e,f,g,h,i = b,c,d,a, i,e,f,g,h;
56
57                 if !testit(z%20 != 19) {
58                         print("on ", z, "th iteration\n");
59                         printit();
60                         panic();
61                 }
62         }
63
64         if !testit(false) {
65                 print("final val\n");
66                 printit();
67                 panic();
68         }
69
70         a, b = swap(1, 2);
71         if a != 2 || b != 1 {
72                 panic("bad swap");
73         }
74
75         a, b = swap(swap(a, b));
76         if a != 2 || b != 1 {
77                 panic("bad swap");
78         }
79 }