Home | History | Annotate | Download | only in ken
      1 // run
      2 
      3 // Copyright 2010 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 // Test compound types made of complex numbers.
      8 
      9 package main
     10 
     11 var a [12]complex128
     12 var s []complex128
     13 var c chan complex128
     14 var f struct {
     15 	c complex128
     16 }
     17 var m map[complex128]complex128
     18 
     19 func main() {
     20 	// array of complex128
     21 	for i := 0; i < len(a); i++ {
     22 		a[i] = complex(float64(i), float64(-i))
     23 	}
     24 	if a[5] != 5-5i {
     25 		panic(a[5])
     26 	}
     27 
     28 	// slice of complex128
     29 	s = make([]complex128, len(a))
     30 	for i := 0; i < len(s); i++ {
     31 		s[i] = a[i]
     32 	}
     33 	if s[5] != 5-5i {
     34 		panic(s[5])
     35 	}
     36 
     37 	// chan
     38 	c = make(chan complex128)
     39 	go chantest(c)
     40 	vc := <-c
     41 	if vc != 5-5i {
     42 		panic(vc)
     43 	}
     44 
     45 	// pointer of complex128
     46 	v := a[5]
     47 	pv := &v
     48 	if *pv != 5-5i {
     49 		panic(*pv)
     50 	}
     51 
     52 	// field of complex128
     53 	f.c = a[5]
     54 	if f.c != 5-5i {
     55 		panic(f.c)
     56 	}
     57 
     58 	// map of complex128
     59 	m = make(map[complex128]complex128)
     60 	for i := 0; i < len(s); i++ {
     61 		m[-a[i]] = a[i]
     62 	}
     63 	if m[5i-5] != 5-5i {
     64 		panic(m[5i-5])
     65 	}
     66 	vm := m[complex(-5, 5)]
     67 	if vm != 5-5i {
     68 		panic(vm)
     69 	}
     70 }
     71 
     72 func chantest(c chan complex128) { c <- a[5] }
     73