blob: 8ec7d40f5e58104b6260a1066cb8e18b0359a315 [file] [log] [blame]
Ken Thompsonf229c8b2010-03-09 12:49:24 -08001// $G $D/$F.go && $L $F.$A && ./$A.out
Ken Thompson7d4b1e42010-03-02 18:32:11 -08002
Ken Thompsonf229c8b2010-03-09 12:49:24 -08003// Copyright 2010 The Go Authors. All rights reserved.
Ken Thompson7d4b1e42010-03-02 18:32:11 -08004// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package main
8
9const (
10 R = 5
11 I = 6i
12
13 C1 = R + I // ADD(5,6)
14)
15
16func main() {
17 var b bool
18
19 // constants
20 b = (5 + 6i) == C1
21 if !b {
Rob Pike325cf8e2010-03-24 16:46:53 -070022 println("const bool 1", b)
23 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080024 }
25
26 b = (5 + 6i) != C1
27 if b {
Rob Pike325cf8e2010-03-24 16:46:53 -070028 println("const bool 2", b)
29 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080030 }
31
32 b = C1 == (5 + 6i)
33 if !b {
Rob Pike325cf8e2010-03-24 16:46:53 -070034 println("const bool 3", b)
35 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080036 }
37
38 b = C1 != (5 + 6i)
39 if b {
Rob Pike325cf8e2010-03-24 16:46:53 -070040 println("const bool 4", b)
41 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080042 }
43
44 // vars passed through parameters
45 booltest(5+6i, true)
46 booltest(5+7i, false)
47 booltest(6+6i, false)
48 booltest(6+9i, false)
49}
50
Russ Coxf2b5a072011-01-19 23:09:00 -050051func booltest(a complex64, r bool) {
Ken Thompson7d4b1e42010-03-02 18:32:11 -080052 var b bool
53
54 b = a == C1
55 if b != r {
Rob Pike325cf8e2010-03-24 16:46:53 -070056 println("param bool 1", a, b, r)
57 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080058 }
59
60 b = a != C1
61 if b == r {
Rob Pike325cf8e2010-03-24 16:46:53 -070062 println("param bool 2", a, b, r)
63 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080064 }
65
66 b = C1 == a
67 if b != r {
Rob Pike325cf8e2010-03-24 16:46:53 -070068 println("param bool 3", a, b, r)
69 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080070 }
71
72 b = C1 != a
73 if b == r {
Rob Pike325cf8e2010-03-24 16:46:53 -070074 println("param bool 4", a, b, r)
75 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080076 }
77
78 if r {
79 if a != C1 {
Rob Pike325cf8e2010-03-24 16:46:53 -070080 println("param bool 5", a, b, r)
81 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080082 }
83 if C1 != a {
Rob Pike325cf8e2010-03-24 16:46:53 -070084 println("param bool 6", a, b, r)
85 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080086 }
87 } else {
88 if a == C1 {
Rob Pike325cf8e2010-03-24 16:46:53 -070089 println("param bool 6", a, b, r)
90 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080091 }
92 if C1 == a {
Rob Pike325cf8e2010-03-24 16:46:53 -070093 println("param bool 7", a, b, r)
94 panic("fail")
Ken Thompson7d4b1e42010-03-02 18:32:11 -080095 }
96 }
97}