Skip to content

Commit

Permalink
Merge pull request #15 from JesusIslam/fix-12
Browse files Browse the repository at this point in the history
adding more tests
  • Loading branch information
didasy committed Apr 18, 2019
2 parents 68ecf53 + 331bdc6 commit 7e3d16f
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 6 deletions.
7 changes: 7 additions & 0 deletions result_centrality.txt
@@ -0,0 +1,7 @@
It should be a stunning addition to the collection of shoreline museums, but it has encountered opposition from open-space advocates and Bears fans, as the museum will occupy part of their tailgating field.

In honor of the Museum of Narrative Art and its star-studded cast of architects, here's a roundup of articles from Architizer that feature Star Wars-related architecture:

Jeff Bennett's Wars on Kinkade are hilarious paintings that ravage the peaceful landscapes of Thomas Kinkade with the brutal destruction of Star Wars.

These products were inspired by the movie and blend pop culture memorabilia with high design, including Hans Solo Carbonite Coffee Tables, Emperor Thrones, and an AT-AT Triple Bunk Bed.
3 changes: 3 additions & 0 deletions short.result_centrality.txt
@@ -0,0 +1,3 @@
In honor of the Museum of Narrative Art and its star-studded cast of architects, here's a roundup of articles from Architizer that feature Star Wars-related architecture:

Jeff Bennett's Wars on Kinkade are hilarious paintings that ravage the peaceful landscapes of Thomas Kinkade with the brutal destruction of Star Wars.
113 changes: 107 additions & 6 deletions tldr_test.go
Expand Up @@ -11,10 +11,10 @@ import (
)

var (
err error
raw []byte
text, result, shortResult string
summarizer *Bag
err error
raw []byte
text, result, shortResult, resultCentrality, shortResultCentrality string
summarizer *Bag
)

func init() {
Expand All @@ -33,13 +33,83 @@ func init() {
panic(err)
}
shortResult = string(raw)
summarizer = New()
raw, err = ioutil.ReadFile("./result_centrality.txt")
if err != nil {
panic(err)
}
resultCentrality = string(raw)
raw, err = ioutil.ReadFile("./short.result_centrality.txt")
if err != nil {
panic(err)
}
shortResultCentrality = string(raw)
}

var _ = Describe("tldr", func() {
Describe("Test summarizing", func() {
Describe("Test summarizing using default hamming weighing and pagerank algorithm", func() {
Context("Summarize sample.txt to 3 sentences", func() {
It("Should return a string match with result.txt without error", func() {
summarizer = New()
sums, err := summarizer.Summarize(text, 3)
summarizer.Algorithm = ""
summarizer.Weighing = ""
sum := strings.Join(sums, "\n\n")
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() {
summarizer = New()
summarizer.Algorithm = ""
summarizer.Weighing = ""
sums, err := summarizer.Summarize(text, 10000)
sum := strings.Join(sums, "\n\n")
Expect(err).To(BeNil())
Expect(sum).To(BeAssignableToTypeOf(""))
Expect(sum).NotTo(BeEmpty())
Expect(sum).To(Equal(strings.TrimSpace(string(shortResult))))
})
})
})

Describe("Test summarizing using jaccard weighing and pagerank algorithm", func() {
Context("Summarize sample.txt to 3 sentences", func() {
It("Should return a string match with result.txt without error", func() {
summarizer = New()
summarizer.Weighing = "jaccard"
summarizer.Algorithm = ""
sums, err := summarizer.Summarize(text, 3)
sum := strings.Join(sums, "\n\n")
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() {
summarizer = New()
summarizer.Weighing = "jaccard"
summarizer.Algorithm = ""
sums, err := summarizer.Summarize(text, 10000)
sum := strings.Join(sums, "\n\n")
Expect(err).To(BeNil())
Expect(sum).To(BeAssignableToTypeOf(""))
Expect(sum).NotTo(BeEmpty())
Expect(sum).To(Equal(strings.TrimSpace(string(shortResult))))
})
})
})

Describe("Test summarizing using invalid weighing name and invalid algorithm", func() {
Context("Summarize sample.txt to 3 sentences", func() {
It("Should return a string match with result.txt without error", func() {
summarizer = New()
summarizer.Weighing = "invalid"
summarizer.Algorithm = "invalid"
sums, err := summarizer.Summarize(text, 3)
sum := strings.Join(sums, "\n\n")
Expect(err).To(BeNil())
Expand All @@ -50,6 +120,9 @@ var _ = Describe("tldr", func() {
})
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() {
summarizer = New()
summarizer.Weighing = "invalid"
summarizer.Algorithm = "invalid"
sums, err := summarizer.Summarize(text, 10000)
sum := strings.Join(sums, "\n\n")
Expect(err).To(BeNil())
Expand All @@ -60,4 +133,32 @@ var _ = Describe("tldr", func() {
})
})

Describe("Test summarizing using centrality algorithm", func() {
Context("Summarize sample.txt to 3 sentences", func() {
It("Should return a string match with result_centrality.txt without error", func() {
summarizer = New()
summarizer.Algorithm = "centrality"
summarizer.Weighing = "pagerank"
sums, err := summarizer.Summarize(text, 3)
sum := strings.Join(sums, "\n\n")
Expect(err).To(BeNil())
Expect(sum).To(BeAssignableToTypeOf(""))
Expect(sum).NotTo(BeEmpty())
Expect(sum).To(Equal(strings.TrimSpace(resultCentrality)))
})
})
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() {
summarizer = New()
summarizer.Algorithm = "centrality"
summarizer.Weighing = "pagerank"
sums, err := summarizer.Summarize(text, 10000)
sum := strings.Join(sums, "\n\n")
Expect(err).To(BeNil())
Expect(sum).To(BeAssignableToTypeOf(""))
Expect(sum).NotTo(BeEmpty())
Expect(sum).To(Equal(strings.TrimSpace(string(shortResultCentrality))))
})
})
})
})

0 comments on commit 7e3d16f

Please sign in to comment.