mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
test: gofmt a few tests
I'm planning to change these tests, but the gofmt changes are fairly extensive, so I'm separating the gofmt changes from the substantive changes. R=golang-dev, rsc, r CC=golang-dev https://golang.org/cl/5557052
This commit is contained in:
parent
20812c4907
commit
6b3462820f
8 changed files with 242 additions and 248 deletions
|
|
@ -8,7 +8,6 @@ package main
|
|||
|
||||
type Number *Number
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Peano primitives
|
||||
|
||||
|
|
@ -16,24 +15,20 @@ func zero() *Number {
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
func is_zero(x *Number) bool {
|
||||
return x == nil
|
||||
}
|
||||
|
||||
|
||||
func add1(x *Number) *Number {
|
||||
e := new(Number)
|
||||
*e = x
|
||||
return e
|
||||
}
|
||||
|
||||
|
||||
func sub1(x *Number) *Number {
|
||||
return *x
|
||||
}
|
||||
|
||||
|
||||
func add(x, y *Number) *Number {
|
||||
if is_zero(y) {
|
||||
return x
|
||||
|
|
@ -42,7 +37,6 @@ func add(x, y *Number) *Number {
|
|||
return add(add1(x), sub1(y))
|
||||
}
|
||||
|
||||
|
||||
func mul(x, y *Number) *Number {
|
||||
if is_zero(x) || is_zero(y) {
|
||||
return zero()
|
||||
|
|
@ -51,7 +45,6 @@ func mul(x, y *Number) *Number {
|
|||
return add(mul(x, sub1(y)), x)
|
||||
}
|
||||
|
||||
|
||||
func fact(n *Number) *Number {
|
||||
if is_zero(n) {
|
||||
return add1(zero())
|
||||
|
|
@ -60,7 +53,6 @@ func fact(n *Number) *Number {
|
|||
return mul(fact(sub1(n)), n)
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Helpers to generate/count Peano integers
|
||||
|
||||
|
|
@ -72,7 +64,6 @@ func gen(n int) *Number {
|
|||
return zero()
|
||||
}
|
||||
|
||||
|
||||
func count(x *Number) int {
|
||||
if is_zero(x) {
|
||||
return 0
|
||||
|
|
@ -81,7 +72,6 @@ func count(x *Number) int {
|
|||
return count(sub1(x)) + 1
|
||||
}
|
||||
|
||||
|
||||
func check(x *Number, expected int) {
|
||||
var c = count(x)
|
||||
if c != expected {
|
||||
|
|
@ -90,7 +80,6 @@ func check(x *Number, expected int) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Test basic functionality
|
||||
|
||||
|
|
@ -115,7 +104,6 @@ func init() {
|
|||
check(fact(gen(5)), 120)
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Factorial
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue