From d53d785c34923a5a58b40e2687d3ac7878a6343e Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Mon, 23 May 2022 16:25:52 +0300 Subject: [PATCH] Update Fib function to return time.Duration in seconds instead of int --- utils/coreutils.go | 10 +++++----- utils/coreutils_test.go | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/utils/coreutils.go b/utils/coreutils.go index 4086b9ead..80498fa02 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -479,18 +479,18 @@ func copyFile(rc io.ReadCloser, path string, fm os.FileMode) (err error) { return } -// successive Fibonacci numbers. -func Fib() func() int { +// Fib returns successive Fibonacci numbers converted to seconds. +func Fib() func() time.Duration { a, b := 0, 1 - return func() int { + return func() time.Duration { a, b = b, a+b - return a + return time.Duration(a) * time.Second } } func FibDuration(mult time.Duration) func() time.Duration { fib := Fib() return func() time.Duration { - return time.Duration(fib()) * mult + return fib() * mult } } diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go index e1821e66c..50cd3b9ec 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -1081,20 +1081,20 @@ func TestClone(t *testing.T) { func TestFib(t *testing.T) { fib := Fib() - if tmp := fib(); tmp != 1 { - t.Error("Expecting: 1, received ", tmp) + if tmp := fib(); tmp != 1*time.Second { + t.Error("Expecting: 1s, received ", tmp) } - if tmp := fib(); tmp != 1 { - t.Error("Expecting: 1, received ", tmp) + if tmp := fib(); tmp != 1*time.Second { + t.Error("Expecting: 1s, received ", tmp) } - if tmp := fib(); tmp != 2 { - t.Error("Expecting: 2, received ", tmp) + if tmp := fib(); tmp != 2*time.Second { + t.Error("Expecting: 2s, received ", tmp) } - if tmp := fib(); tmp != 3 { - t.Error("Expecting: 3, received ", tmp) + if tmp := fib(); tmp != 3*time.Second { + t.Error("Expecting: 3s, received ", tmp) } - if tmp := fib(); tmp != 5 { - t.Error("Expecting: 5, received ", tmp) + if tmp := fib(); tmp != 5*time.Second { + t.Error("Expecting: 5s, received ", tmp) } }