mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update Fib function to return time.Duration in seconds instead of int
This commit is contained in:
committed by
Dan Christian Bogos
parent
89bcb7a474
commit
d53d785c34
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user