1 // $G $D/$F.go && $L $F.$A && ./$A.out
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.
14 testi(i
int, t1
,t2
,t3
int) {
15 n
:= ((t1
*3) + t2
)*2 + t3
;
17 print("itest ", t1
,t2
,t3
,pass
,
18 " is ", i
, " sb ", ians
[n
], "\n");
23 index(t1
,t2
,t3
int) int {
24 return ((t1
*3) + t2
)*2 + t3
;
28 testu(u
uint, t1
,t2
,t3
int) {
31 print("utest ", t1
,t2
,t3
,pass
,
32 " is ", u
, " sb ", uans
[n
], "\n");
42 * test constant evaluations
44 pass
= "con"; // constant part
46 testi( int(1234) << 0, 0,0,0);
47 testi( int(1234) >> 0, 0,0,1);
48 testi( int(1234) << 5, 0,1,0);
49 testi( int(1234) >> 5, 0,1,1);
51 testi(int(-1234) << 0, 1,0,0);
52 testi(int(-1234) >> 0, 1,0,1);
53 testi(int(-1234) << 5, 1,1,0);
54 testi(int(-1234) >> 5, 1,1,1);
56 testu(uint(5678) << 0, 2,0,0);
57 testu(uint(5678) >> 0, 2,0,1);
58 testu(uint(5678) << 5, 2,1,0);
59 testu(uint(5678) >> 5, 2,1,1);
62 * test variable evaluations
64 pass
= "var"; // variable part
66 for t1
:=0; t1
<3; t1
++ { // +int, -int, uint
67 for t2
:=0; t2
<3; t2
++ { // 0, +small, +large
68 for t3
:=0; t3
<2; t3
++ { // <<, >>
80 case 0: i
<<= c
; u
<<= c
;
81 case 1: i
>>= c
; u
>>= c
;
84 case 0: testi(i
,t1
,t2
,t3
);
85 case 1: testi(i
,t1
,t2
,t3
);
86 case 2: testu(u
,t1
,t2
,t3
);
96 * set the 'correct' answer
99 ians
[index(0,0,0)] = 1234;
100 ians
[index(0,0,1)] = 1234;
101 ians
[index(0,1,0)] = 39488;
102 ians
[index(0,1,1)] = 38;
103 ians
[index(0,2,0)] = 0;
104 ians
[index(0,2,1)] = 0;
106 ians
[index(1,0,0)] = -1234;
107 ians
[index(1,0,1)] = -1234;
108 ians
[index(1,1,0)] = -39488;
109 ians
[index(1,1,1)] = -39;
110 ians
[index(1,2,0)] = 0;
111 ians
[index(1,2,1)] = -1;
113 uans
[index(2,0,0)] = 5678;
114 uans
[index(2,0,1)] = 5678;
115 uans
[index(2,1,0)] = 181696;
116 uans
[index(2,1,1)] = 177;
117 uans
[index(2,2,0)] = 0;
118 uans
[index(2,2,1)] = 0;