-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.go
More file actions
37 lines (31 loc) · 729 Bytes
/
Copy pathscript.go
File metadata and controls
37 lines (31 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package clock
import "time"
const (
// Default added duration in Script.Now.
DefaultScriptNow time.Duration = time.Millisecond
// Default speed Script.Ratio for fake timer/ticker.
DefaultScriptRatio time.Duration = 10
)
type Script struct {
// How much duration clock.Now() will advance.
Now time.Duration
// The speed ratio between test's fake timer/ticker and real.
Ratio time.Duration
}
func (s Script) canon() Script {
if s.Now <= 0 {
s.Now = DefaultScriptNow
}
if s.Ratio <= 0 {
s.Ratio = DefaultScriptRatio
}
return s
}
func getScript(l [][]Script, no int, i *int, def Script) Script {
if no <= len(l) && len(l[no-1]) > *i {
*i++
return l[no-1][*i-1].canon()
} else {
return def.canon()
}
}