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

This commit is contained in:
William Dillon 2026-02-26 15:09:45 -05:00
parent 766e407cc3
commit 5d5410000f
4 changed files with 12 additions and 8 deletions

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"backoff/fibonacci"
"context" "context"
"flag" "flag"
"fmt" "fmt"
@ -10,6 +9,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"code.wmdillon.com/wmdillon/backoff/fibonacci"
) )
func FormatOutput(pause time.Duration, format string) string { func FormatOutput(pause time.Duration, format string) string {

View File

@ -1,10 +1,11 @@
package fibonacci package fibonacci
import ( import (
"backoff/utilities"
"context" "context"
"fmt" "fmt"
"time" "time"
"code.wmdillon.com/wmdillon/backoff/utilities"
) )
var ( var (
@ -74,13 +75,14 @@ func (f *FibonacciBackoff) Next() time.Duration {
func (f *FibonacciBackoff) After(ctx context.Context) <-chan time.Time { func (f *FibonacciBackoff) After(ctx context.Context) <-chan time.Time {
pause := f.Next() pause := f.Next()
results := make(chan time.Time, 1) results := make(chan time.Time, 1)
timer := time.NewTimer(pause)
go func() { go func() {
defer close(results) defer close(results)
defer timer.Stop()
select { select {
case t := <-time.After(pause): case t := <-timer.C:
results <- t results <- t
case <-ctx.Done(): case <-ctx.Done():
results <- time.Now()
} }
}() }()
return results return results

View File

@ -1,12 +1,13 @@
package fibonacci package fibonacci
import ( import (
"backoff/utilities"
"context" "context"
"fmt" "fmt"
"math/big" "math/big"
"testing" "testing"
"time" "time"
"code.wmdillon.com/wmdillon/backoff/utilities"
) )
func wouldOverflow(a, b int64) (product int64, overflows bool) { func wouldOverflow(a, b int64) (product int64, overflows bool) {
@ -41,7 +42,7 @@ func TestFibonacciResultsArray(t *testing.T) {
func TestFibonacciFunc(t *testing.T) { func TestFibonacciFunc(t *testing.T) {
for n := range len(TheFibonacciSequence) { for n := range len(TheFibonacciSequence) {
want := fibonacci(int64(n)) want := fibonacci(int64(n))
got := fibonacci(int64(n)) got := Fibonacci(int64(n))
if want != got { if want != got {
t.Fatalf("error for input %d: wanted %d; got %d\n", n, want, got) t.Fatalf("error for input %d: wanted %d; got %d\n", n, want, got)
} }

4
go.mod
View File

@ -1,3 +1,3 @@
module backoff module code.wmdillon.com/wmdillon/backoff
go 1.25.5 go 1.25