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.
7 // Test arrays and slices.
12 // print("setpd a=", a, " len=", len(a), " cap=", cap(a), "\n");
13 for i := 0; i < len(a); i++ {
18 func sumpd(a []int) int {
19 // print("sumpd a=", a, " len=", len(a), " cap=", cap(a), "\n");
21 for i := 0; i < len(a); i++ {
24 // print("sumpd t=", t, "\n");
28 func setpf(a *[20]int) {
29 // print("setpf a=", a, " len=", len(a), " cap=", cap(a), "\n");
30 for i := 0; i < len(a); i++ {
35 func sumpf(a *[20]int) int {
36 // print("sumpf a=", a, " len=", len(a), " cap=", cap(a), "\n");
38 for i := 0; i < len(a); i++ {
41 // print("sumpf t=", t, "\n");
45 func res(t int, lb, hb int) {
46 sb := (hb - lb) * (hb + lb - 1) / 2
57 // call ptr dynamic with ptr dynamic
59 a := make([]int, 10, 100)
60 if len(a) != 10 && cap(a) != 100 {
61 print("len and cap from new: ", len(a), " ", cap(a), "\n")
75 res(sumpd(a), 35, 100)
78 // call ptr fixed with ptr fixed
86 // call ptr dynamic with ptr fixed from new
90 res(sumpd(a[0:]), 0, 40)
96 // call ptr dynamic with ptr fixed from var
101 res(sumpd(a[0:]), 0, 80)
104 // generate bounds error with ptr dynamic
106 a := make([]int, 100)
109 for i := 0; i < 100; i++ {
112 print("should fault\n")
117 // generate bounds error with ptr fixed
122 for i := 0; i < 80; i++ {
125 print("should fault\n")
136 // print("testpdfault\n"); testpdfault();
137 // print("testfdfault\n"); testfdfault();