-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindborder_test.go
44 lines (35 loc) · 1.28 KB
/
findborder_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 (
"os"
"testing"
)
func TestFindBorderIn1byteFile(t *testing.T) {
file, err := os.Open("test_files/tiny.txt")
if err != nil {
t.Error("Can't open tiny.txt")
}
defer file.Close()
maxBufferSize := int64(2)
left, err := findBorder(file, 0, 0, -1, maxBufferSize)
assertEqual(t, err, int64(-1), left, "left border from the beginning tiny.txt")
right, err := findBorder(file, 0, 0, 1, maxBufferSize)
assertEqual(t, err, int64(-1), right, "right border from the end of tiny.txt")
}
func TestFindBorderInborderFile(t *testing.T) {
file, err := os.Open("test_files/small.txt")
if err != nil {
t.Error("Can't open small.txt")
}
defer file.Close()
maxBufferSize := int64(2)
for i := 0; i <= 100; i++ {
left, err := findBorder(file, 0, 32, -1, maxBufferSize)
assertEqual(t, err, int64(22), left, "left border from the end of small.txt")
right, err := findBorder(file, 0, 33, 1, maxBufferSize)
assertEqual(t, err, int64(10), right, "right border from the beginning of small.txt")
left, err = findBorder(file, 0, 16, -1, maxBufferSize)
assertEqual(t, err, int64(10), left, "left border from the end of small.txt")
right, err = findBorder(file, 16, 33, 1, maxBufferSize)
assertEqual(t, err, int64(22), right, "right border from the beginning of small.txt")
}
}