Breaking things out, adding test, all that good crap

cat-town
Dan Buch 12 years ago
parent f3712555d5
commit 631472da41

@ -1,6 +1,8 @@
CLEAN_GOPATH := $(shell echo $(GOPATH) | tr ":" "\n" | grep -v '^$$' | grep -v $(PWD) | tr "\n" ":")
GOPATH := $(PWD):$(CLEAN_GOPATH)
PACKAGES := meatballhat.com/algs4-gcd
PACKAGES := \
meatballhat.com/algs4 \
meatballhat.com/algs4-gcd
test: build
go test $(PACKAGES)

@ -6,15 +6,11 @@ import (
"strconv"
)
const USAGE string = `Usage: algs4-gcd <int> <int>`
import (
"meatballhat.com/algs4"
)
func gcd(p, q uint64) uint64 {
if q == 0 {
return p
}
r := p % q
return gcd(q, r)
}
const USAGE string = `Usage: algs4-gcd <uint> <uint>`
func main() {
if len(os.Args) < 3 {
@ -34,5 +30,5 @@ func main() {
os.Exit(1)
}
fmt.Println(gcd(p, q))
fmt.Println(algs4.Gcd(p, q))
}

@ -0,0 +1,9 @@
package algs4
func Gcd(p, q uint64) uint64 {
if q == 0 {
return p
}
r := p % q
return Gcd(q, r)
}

@ -0,0 +1,16 @@
package algs4_test
import (
"testing"
)
import (
"meatballhat.com/algs4"
)
func TestGcd(t *testing.T) {
d := algs4.Gcd(uint64(81), uint64(72))
if d != 9 {
t.Error("WRONG")
}
}
Loading…
Cancel
Save