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:
parent
766e407cc3
commit
5d5410000f
@ -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 {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user