From 5d5410000fcbf1cfcabcaf88ad5eefb5984395f1 Mon Sep 17 00:00:00 2001 From: William Dillon Date: Thu, 26 Feb 2026 15:09:45 -0500 Subject: [PATCH] fixing go.mod file - use correct module name and valid Go version. Fixed bug in fibonacci_test.go - test wasn't testing the correct method, it was calling the same one twice --- cli/main.go | 3 ++- fibonacci/fibonacci.go | 8 +++++--- fibonacci/fibonacci_test.go | 5 +++-- go.mod | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cli/main.go b/cli/main.go index db95402..c59fa9a 100644 --- a/cli/main.go +++ b/cli/main.go @@ -1,7 +1,6 @@ package main import ( - "backoff/fibonacci" "context" "flag" "fmt" @@ -10,6 +9,8 @@ import ( "strconv" "strings" "time" + + "code.wmdillon.com/wmdillon/backoff/fibonacci" ) func FormatOutput(pause time.Duration, format string) string { diff --git a/fibonacci/fibonacci.go b/fibonacci/fibonacci.go index 2738fe3..e7179f0 100644 --- a/fibonacci/fibonacci.go +++ b/fibonacci/fibonacci.go @@ -1,10 +1,11 @@ package fibonacci import ( - "backoff/utilities" "context" "fmt" "time" + + "code.wmdillon.com/wmdillon/backoff/utilities" ) var ( @@ -74,13 +75,14 @@ func (f *FibonacciBackoff) Next() time.Duration { func (f *FibonacciBackoff) After(ctx context.Context) <-chan time.Time { pause := f.Next() results := make(chan time.Time, 1) + timer := time.NewTimer(pause) go func() { defer close(results) + defer timer.Stop() select { - case t := <-time.After(pause): + case t := <-timer.C: results <- t case <-ctx.Done(): - results <- time.Now() } }() return results diff --git a/fibonacci/fibonacci_test.go b/fibonacci/fibonacci_test.go index 2a37e86..5d4ac3c 100644 --- a/fibonacci/fibonacci_test.go +++ b/fibonacci/fibonacci_test.go @@ -1,12 +1,13 @@ package fibonacci import ( - "backoff/utilities" "context" "fmt" "math/big" "testing" "time" + + "code.wmdillon.com/wmdillon/backoff/utilities" ) func wouldOverflow(a, b int64) (product int64, overflows bool) { @@ -41,7 +42,7 @@ func TestFibonacciResultsArray(t *testing.T) { func TestFibonacciFunc(t *testing.T) { for n := range len(TheFibonacciSequence) { want := fibonacci(int64(n)) - got := fibonacci(int64(n)) + got := Fibonacci(int64(n)) if want != got { t.Fatalf("error for input %d: wanted %d; got %d\n", n, want, got) } diff --git a/go.mod b/go.mod index 5a309f3..5ec3968 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module backoff +module code.wmdillon.com/wmdillon/backoff -go 1.25.5 +go 1.25