diff options
| author | Russ Cox <rsc@golang.org> | 2010-03-30 10:34:57 -0700 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2010-03-30 10:34:57 -0700 |
| commit | 00f9f0c0560ce35b9d006eacbeeacf897d19a2bf (patch) | |
| tree | d56b07c89674ed7162eb30f924600574d0cf464b /test/ken/array.go | |
| parent | 5d0ec6c076978846f7cbbf4bd2c0dc55d946b0f9 (diff) | |
| download | go-00f9f0c0560ce35b9d006eacbeeacf897d19a2bf.tar.xz | |
single argument panic
note that sortmain.go has been run through hg gofmt;
only the formatting of the day initializers changed.
i'm happy to revert that formatting if you'd prefer.
stop on error in doc/progs/run
R=r
CC=golang-dev
https://golang.org/cl/850041
Diffstat (limited to 'test/ken/array.go')
| -rw-r--r-- | test/ken/array.go | 161 |
1 files changed, 75 insertions, 86 deletions
diff --git a/test/ken/array.go b/test/ken/array.go index 9600e8a1a6..7785cdf8f6 100644 --- a/test/ken/array.go +++ b/test/ken/array.go @@ -4,141 +4,130 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package main +package main -func -setpd(a []int) { -// print("setpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); - for i:=0; i<len(a); i++ { - a[i] = i; +func setpd(a []int) { + // print("setpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); + for i := 0; i < len(a); i++ { + a[i] = i } } -func -sumpd(a []int) int { -// print("sumpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); - t := 0; - for i:=0; i<len(a); i++ { - t += a[i]; +func sumpd(a []int) int { + // print("sumpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); + t := 0 + for i := 0; i < len(a); i++ { + t += a[i] } -// print("sumpd t=", t, "\n"); - return t; + // print("sumpd t=", t, "\n"); + return t } -func -setpf(a *[20]int) { -// print("setpf a=", a, " len=", len(a), " cap=", cap(a), "\n"); - for i:=0; i<len(a); i++ { - a[i] = i; +func setpf(a *[20]int) { + // print("setpf a=", a, " len=", len(a), " cap=", cap(a), "\n"); + for i := 0; i < len(a); i++ { + a[i] = i } } -func -sumpf(a *[20]int) int { -// print("sumpf a=", a, " len=", len(a), " cap=", cap(a), "\n"); - t := 0; - for i:=0; i<len(a); i++ { - t += a[i]; +func sumpf(a *[20]int) int { + // print("sumpf a=", a, " len=", len(a), " cap=", cap(a), "\n"); + t := 0 + for i := 0; i < len(a); i++ { + t += a[i] } -// print("sumpf t=", t, "\n"); - return t; + // print("sumpf t=", t, "\n"); + return t } -func -res(t int, lb, hb int) { - sb := (hb-lb)*(hb+lb-1)/2; +func res(t int, lb, hb int) { + sb := (hb - lb) * (hb + lb - 1) / 2 if t != sb { - print( "lb=", lb, + print("lb=", lb, "; hb=", hb, "; t=", t, "; sb=", sb, - "\n"); + "\n") panic("res") } } // call ptr dynamic with ptr dynamic -func -testpdpd() { - a := make([]int, 10, 100); +func testpdpd() { + a := make([]int, 10, 100) if len(a) != 10 && cap(a) != 100 { - panic("len and cap from new: ", len(a), " ", cap(a), "\n"); + print("len and cap from new: ", len(a), " ", cap(a), "\n") + panic("fail") } - a = a[0:100]; - setpd(a); + a = a[0:100] + setpd(a) - a = a[0:10]; - res(sumpd(a), 0, 10); + a = a[0:10] + res(sumpd(a), 0, 10) - a = a[5:25]; - res(sumpd(a), 5, 25); + a = a[5:25] + res(sumpd(a), 5, 25) } // call ptr fixed with ptr fixed -func -testpfpf() { - var a [20]int; +func testpfpf() { + var a [20]int - setpf(&a); - res(sumpf(&a), 0, 20); + setpf(&a) + res(sumpf(&a), 0, 20) } // call ptr dynamic with ptr fixed from new -func -testpdpf1() { - a := new([40]int); - setpd(a); - res(sumpd(a), 0, 40); +func testpdpf1() { + a := new([40]int) + setpd(a) + res(sumpd(a), 0, 40) - b := (*a)[5:30]; - res(sumpd(b), 5, 30); + b := (*a)[5:30] + res(sumpd(b), 5, 30) } // call ptr dynamic with ptr fixed from var -func -testpdpf2() { - var a [80]int; +func testpdpf2() { + var a [80]int - setpd(&a); - res(sumpd(&a), 0, 80); + setpd(&a) + res(sumpd(&a), 0, 80) } // generate bounds error with ptr dynamic -func -testpdfault() { - a := make([]int, 100); +func testpdfault() { + a := make([]int, 100) - print("good\n"); - for i:=0; i<100; i++ { - a[i] = 0; + print("good\n") + for i := 0; i < 100; i++ { + a[i] = 0 } - print("should fault\n"); - a[100] = 0; - print("bad\n"); + print("should fault\n") + a[100] = 0 + print("bad\n") } // generate bounds error with ptr fixed -func -testfdfault() { - var a [80]int; +func testfdfault() { + var a [80]int - print("good\n"); - for i:=0; i<80; i++ { - a[i] = 0; + print("good\n") + for i := 0; i < 80; i++ { + a[i] = 0 } - print("should fault\n"); - x := 80; - a[x] = 0; - print("bad\n"); + print("should fault\n") + x := 80 + a[x] = 0 + print("bad\n") } -func -main() { - testpdpd(); - testpfpf(); - testpdpf1(); - testpdpf2(); -// print("testpdfault\n"); testpdfault(); -// print("testfdfault\n"); testfdfault(); +func main() { + testpdpd() + testpfpf() + testpdpf1() + testpdpf2() + // print("testpdfault\n"); testpdfault(); + // print("testfdfault\n"); testfdfault(); } |
