1
0
mirror of https://github.com/golang/go synced 2024-11-24 05:50:13 -07:00

test/peano: use directly recursive type def

Test case for http://code.google.com/p/go/issues/detail?id=999

R=r
CC=golang-dev
https://golang.org/cl/1892050
This commit is contained in:
Robert Griesemer 2010-08-06 15:07:54 -07:00
parent 64f24107e1
commit 1dd8840800

View File

@ -6,9 +6,7 @@
package main package main
type Number struct { type Number *Number
next *Number
}
// ------------------------------------- // -------------------------------------
@ -26,13 +24,13 @@ func is_zero(x *Number) bool {
func add1(x *Number) *Number { func add1(x *Number) *Number {
e := new(Number) e := new(Number)
e.next = x *e = x
return e return e
} }
func sub1(x *Number) *Number { func sub1(x *Number) *Number {
return x.next return *x
} }
@ -96,7 +94,7 @@ func check(x *Number, expected int) {
// ------------------------------------- // -------------------------------------
// Test basic functionality // Test basic functionality
func verify() { func init() {
check(zero(), 0) check(zero(), 0)
check(add1(zero()), 1) check(add1(zero()), 1)
check(gen(10), 10) check(gen(10), 10)
@ -121,10 +119,7 @@ func verify() {
// ------------------------------------- // -------------------------------------
// Factorial // Factorial
func main() { func main() {
verify()
for i := 0; i <= 9; i++ { for i := 0; i <= 9; i++ {
print(i, "! = ", count(fact(gen(i))), "\n") print(i, "! = ", count(fact(gen(i))), "\n")
} }