-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinder_test.go
44 lines (40 loc) · 1015 Bytes
/
finder_test.go
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
38
39
40
41
42
43
44
package main
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestFinder_FindDistinct(t *testing.T) {
finder := NewFinder(0, oneSecondDelayTimeProvider())
list := []Path{
buildPath("a"),
buildPath("b"),
buildPath("c"),
}
assert.Equal(t, 0, finder.Find(list, 'a'))
assert.Equal(t, 1, finder.Find(list, 'b'))
assert.Equal(t, 2, finder.Find(list, 'c'))
assert.Equal(t, -1, finder.Find(list, 'd'))
}
func TestFinder_FindSeq(t *testing.T) {
finder := NewFinder(2*time.Second, oneSecondDelayTimeProvider())
list := []Path{
buildPath("abc"),
buildPath("aab"),
buildPath("aac"),
buildPath("acdc"),
}
assert.Equal(t, 0, finder.Find(list, 'a'))
assert.Equal(t, 1, finder.Find(list, 'a'))
assert.Equal(t, 2, finder.Find(list, 'c'))
assert.Equal(t, 2, finder.Find(list, 'd'))
}
func oneSecondDelayTimeProvider() func() time.Time {
startTime := time.Now()
step := time.Second
i := 0
return func() time.Time {
i++
return startTime.Add(time.Duration(i) * step)
}
}