-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblook_test.go
66 lines (50 loc) · 1.61 KB
/
blook_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"os"
"testing"
)
func TestBlookForward(t *testing.T) {
file, err := os.Open("test_files/small.txt")
if err != nil {
t.Error("Can't open small.txt")
}
defer file.Close()
position, err := blook("aaa", file, 34, true)
assertEqual(t, err, int64(0), position, "")
position, err = blook("first", file, 34, true)
assertEqual(t, err, int64(0), position, "")
position, err = blook("second", file, 34, true)
assertEqual(t, err, int64(11), position, "")
position, err = blook("third", file, 34, true)
assertEqual(t, err, int64(23), position, "")
position, err = blook("zzz", file, 34, true)
assertEqual(t, err, int64(-1), position, "")
}
func TestBlookBackward(t *testing.T) {
file, err := os.Open("test_files/small.txt")
if err != nil {
t.Error("Can't open small.txt")
}
defer file.Close()
position, err := blook("aaa", file, 34, false)
assertEqual(t, err, int64(-1), position, "")
position, err = blook("first", file, 34, false)
assertEqual(t, err, int64(9), position, "")
position, err = blook("second", file, 34, false)
assertEqual(t, err, int64(21), position, "")
position, err = blook("third", file, 34, false)
assertEqual(t, err, int64(32), position, "")
position, err = blook("zzz", file, 34, false)
assertEqual(t, err, int64(32), position, "")
}
func TestEmpty(t *testing.T) {
file, err := os.Open("test_files/empty.txt")
if err != nil {
t.Error("Can't open empty.txt")
}
defer file.Close()
position, err := blook("aaa", file, 0, true)
assertEqual(t, err, int64(-1), position, "")
position, err = blook("aaa", file, 0, false)
assertEqual(t, err, int64(-1), position, "")
}