Breaking things out, adding test, all that good crap
This commit is contained in:
parent
f3712555d5
commit
631472da41
@ -1,6 +1,8 @@
|
|||||||
CLEAN_GOPATH := $(shell echo $(GOPATH) | tr ":" "\n" | grep -v '^$$' | grep -v $(PWD) | tr "\n" ":")
|
CLEAN_GOPATH := $(shell echo $(GOPATH) | tr ":" "\n" | grep -v '^$$' | grep -v $(PWD) | tr "\n" ":")
|
||||||
GOPATH := $(PWD):$(CLEAN_GOPATH)
|
GOPATH := $(PWD):$(CLEAN_GOPATH)
|
||||||
PACKAGES := meatballhat.com/algs4-gcd
|
PACKAGES := \
|
||||||
|
meatballhat.com/algs4 \
|
||||||
|
meatballhat.com/algs4-gcd
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
go test $(PACKAGES)
|
go test $(PACKAGES)
|
||||||
|
@ -6,15 +6,11 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const USAGE string = `Usage: algs4-gcd <int> <int>`
|
import (
|
||||||
|
"meatballhat.com/algs4"
|
||||||
|
)
|
||||||
|
|
||||||
func gcd(p, q uint64) uint64 {
|
const USAGE string = `Usage: algs4-gcd <uint> <uint>`
|
||||||
if q == 0 {
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
r := p % q
|
|
||||||
return gcd(q, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) < 3 {
|
if len(os.Args) < 3 {
|
||||||
@ -34,5 +30,5 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(gcd(p, q))
|
fmt.Println(algs4.Gcd(p, q))
|
||||||
}
|
}
|
||||||
|
9
algs4/src/meatballhat.com/algs4/gcd.go
Normal file
9
algs4/src/meatballhat.com/algs4/gcd.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package algs4
|
||||||
|
|
||||||
|
func Gcd(p, q uint64) uint64 {
|
||||||
|
if q == 0 {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
r := p % q
|
||||||
|
return Gcd(q, r)
|
||||||
|
}
|
16
algs4/src/meatballhat.com/algs4/gcd_test.go
Normal file
16
algs4/src/meatballhat.com/algs4/gcd_test.go
Normal file
@ -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…
Reference in New Issue
Block a user