summaryrefslogtreecommitdiffstats
path: root/test/ken/cplx1.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:16:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:16:40 +0000
commit47ab3d4a42e9ab51c465c4322d2ec233f6324e6b (patch)
treea61a0ffd83f4a3def4b36e5c8e99630c559aa723 /test/ken/cplx1.go
parentInitial commit. (diff)
downloadgolang-1.18-upstream.tar.xz
golang-1.18-upstream.zip
Adding upstream version 1.18.10.upstream/1.18.10upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/ken/cplx1.go')
-rw-r--r--test/ken/cplx1.go99
1 files changed, 99 insertions, 0 deletions
diff --git a/test/ken/cplx1.go b/test/ken/cplx1.go
new file mode 100644
index 0000000..78240a5
--- /dev/null
+++ b/test/ken/cplx1.go
@@ -0,0 +1,99 @@
+// run
+
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test simple arithmetic and assignment for complex numbers.
+
+package main
+
+const (
+ R = 5
+ I = 6i
+
+ C1 = R + I // ADD(5,6)
+)
+
+func main() {
+ var b bool
+
+ // constants
+ b = (5 + 6i) == C1
+ if !b {
+ println("const bool 1", b)
+ panic("fail")
+ }
+
+ b = (5 + 6i) != C1
+ if b {
+ println("const bool 2", b)
+ panic("fail")
+ }
+
+ b = C1 == (5 + 6i)
+ if !b {
+ println("const bool 3", b)
+ panic("fail")
+ }
+
+ b = C1 != (5 + 6i)
+ if b {
+ println("const bool 4", b)
+ panic("fail")
+ }
+
+ // vars passed through parameters
+ booltest(5+6i, true)
+ booltest(5+7i, false)
+ booltest(6+6i, false)
+ booltest(6+9i, false)
+}
+
+func booltest(a complex64, r bool) {
+ var b bool
+
+ b = a == C1
+ if b != r {
+ println("param bool 1", a, b, r)
+ panic("fail")
+ }
+
+ b = a != C1
+ if b == r {
+ println("param bool 2", a, b, r)
+ panic("fail")
+ }
+
+ b = C1 == a
+ if b != r {
+ println("param bool 3", a, b, r)
+ panic("fail")
+ }
+
+ b = C1 != a
+ if b == r {
+ println("param bool 4", a, b, r)
+ panic("fail")
+ }
+
+ if r {
+ if a != C1 {
+ println("param bool 5", a, b, r)
+ panic("fail")
+ }
+ if C1 != a {
+ println("param bool 6", a, b, r)
+ panic("fail")
+ }
+ } else {
+ if a == C1 {
+ println("param bool 6", a, b, r)
+ panic("fail")
+ }
+ if C1 == a {
+ println("param bool 7", a, b, r)
+ panic("fail")
+ }
+ }
+}