diff --git a/algs4/Makefile b/algs4/Makefile index 7df9fa2..fa5000b 100644 --- a/algs4/Makefile +++ b/algs4/Makefile @@ -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) diff --git a/algs4/src/meatballhat.com/algs4-gcd/main.go b/algs4/src/meatballhat.com/algs4-gcd/main.go index c7fa5f1..a2a7223 100644 --- a/algs4/src/meatballhat.com/algs4-gcd/main.go +++ b/algs4/src/meatballhat.com/algs4-gcd/main.go @@ -6,15 +6,11 @@ import ( "strconv" ) -const USAGE string = `Usage: algs4-gcd ` +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 ` 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)) } diff --git a/algs4/src/meatballhat.com/algs4/gcd.go b/algs4/src/meatballhat.com/algs4/gcd.go new file mode 100644 index 0000000..0a06355 --- /dev/null +++ b/algs4/src/meatballhat.com/algs4/gcd.go @@ -0,0 +1,9 @@ +package algs4 + +func Gcd(p, q uint64) uint64 { + if q == 0 { + return p + } + r := p % q + return Gcd(q, r) +} diff --git a/algs4/src/meatballhat.com/algs4/gcd_test.go b/algs4/src/meatballhat.com/algs4/gcd_test.go new file mode 100644 index 0000000..0ae6c38 --- /dev/null +++ b/algs4/src/meatballhat.com/algs4/gcd_test.go @@ -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") + } +}