forked from didasy/tldr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtldr_test.go
61 lines (54 loc) · 1.43 KB
/
tldr_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
package tldr_test
import (
. "github.com/JesusIslam/tldr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"strings"
)
var (
err error
raw []byte
text, result, shortResult string
summarizer *Bag
)
func init() {
raw, err = ioutil.ReadFile("./sample.txt")
if err != nil {
panic(err)
}
text = string(raw)
raw, err = ioutil.ReadFile("./result.txt")
if err != nil {
panic(err)
}
result = string(raw)
raw, err = ioutil.ReadFile("./short.result.txt")
if err != nil {
panic(err)
}
shortResult = string(raw)
summarizer = New()
}
var _ = Describe("tldr", func() {
Describe("Test summarizing", func() {
Context("Summarize sample.txt to 3 sentences", func() {
It("Should return a string match with result.txt without error", func() {
sum, err := summarizer.Summarize(text, 3)
Expect(err).To(BeNil())
Expect(sum).To(BeAssignableToTypeOf(""))
Expect(sum).NotTo(BeEmpty())
Expect(sum).To(Equal(strings.TrimSpace(result)))
})
})
Context("Summarize sample.txt to 1 sentence but by giving it invalid parameter", func() {
It("Should return a string with one sentence without error", func() {
sum, err := summarizer.Summarize(text, 10000)
Expect(err).To(BeNil())
Expect(sum).To(BeAssignableToTypeOf(""))
Expect(sum).NotTo(BeEmpty())
Expect(sum).To(Equal(strings.TrimSpace(string(shortResult))))
})
})
})
})