-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary_test.go
73 lines (52 loc) · 1.91 KB
/
library_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
67
68
69
70
71
72
73
package guerillaradio
import "testing"
func TestAddFileToLibrary(t *testing.T) {
library := Library{}
err := library.AddSourceDocument("fixtures/oneline.txt")
if err != nil {
t.Errorf("Received an error adding source document %v", err)
}
number_of_documents := library.Size()
expected_number := 1
if expected_number != number_of_documents {
t.Errorf("Expected number of documens to be %v, was %v", expected_number, number_of_documents)
}
}
func TestAddFilesToLibrary(t *testing.T) {
library := Library{}
filenames := []string{"fixtures/oneline.txt", "fixtures/twolines.txt"}
num_files, err := library.AddSourceDocuments(filenames)
if err != nil {
t.Errorf("Received an error adding documents to Library: %v", err)
}
expected_number_of_documents := 2
if expected_number_of_documents != num_files {
t.Errorf("Expected %v files to be added but library contains: %v", expected_number_of_documents, num_files)
}
}
func TestCanRetrieveRequestedLines(t *testing.T) {
library := Library{}
filenames := []string{"fixtures/oneline.txt", "fixtures/twolines.txt", "fixtures/sixlines.txt"}
num_files, err := library.AddSourceDocuments(filenames)
if err != nil || num_files != 3 {
t.Errorf("Received an error adding documents to Library: %v", err)
}
lines_to_retrieve := 12
lines := library.RetrieveLines(lines_to_retrieve)
//fmt.Println(lines)
if len(lines) != lines_to_retrieve {
t.Errorf("Received %v lines instead of the request %v", len(lines), lines_to_retrieve)
}
}
func TestCanReadAllFilesInADirectoryTree(t *testing.T) {
library := Library{}
directory := "fixtures"
err := library.AddDirectory(directory)
if err != nil {
t.Errorf("Received an error adding documents to Library: %v", err)
}
expected_number_of_documents := 4
if expected_number_of_documents != library.Size() {
t.Errorf("Expected %v files to be added but library contains: %v", expected_number_of_documents, library.Size())
}
}