-
Notifications
You must be signed in to change notification settings - Fork 4
/
reader_test.go
135 lines (109 loc) · 4.18 KB
/
reader_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package textstats
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/suite"
)
type AnalyseSuite struct {
suite.Suite
}
type badReader struct{}
func (b *badReader) Read(buf []byte) (int, error) {
return 0, errors.New("fake error")
}
func (s *AnalyseSuite) TestBadReader() {
_, err := Analyse(&badReader{})
s.Error(err)
}
func (s *AnalyseSuite) TestAverageLettersPerWord() {
res, _ := Analyse(strings.NewReader(qbf))
s.Equal(3.888888888888889, res.AverageLettersPerWord())
}
func (s *AnalyseSuite) TestAverageSyllablesPerWord() {
res, _ := Analyse(strings.NewReader(qbf))
s.Equal(1.2222222222222223, res.AverageSyllablesPerWord())
}
func (s *AnalyseSuite) TestAverageWordsPerSentence() {
res, _ := Analyse(strings.NewReader(qbf))
s.Equal(9.0, res.AverageWordsPerSentence())
res, _ = Analyse(strings.NewReader(lorem))
s.Equal(17.25, res.AverageWordsPerSentence())
}
func (s *AnalyseSuite) TestWordsWithAtLeastNSyllables() {
res, _ := Analyse(strings.NewReader(hw))
s.Equal(6, res.WordsWithAtLeastNSyllables(0, true))
s.Equal(6, res.WordsWithAtLeastNSyllables(1, true))
s.Equal(3, res.WordsWithAtLeastNSyllables(2, true))
s.Equal(2, res.WordsWithAtLeastNSyllables(3, true))
s.Equal(1, res.WordsWithAtLeastNSyllables(4, true))
s.Equal(0, res.WordsWithAtLeastNSyllables(5, true))
s.Equal(4, res.WordsWithAtLeastNSyllables(0, false))
s.Equal(4, res.WordsWithAtLeastNSyllables(1, false))
s.Equal(2, res.WordsWithAtLeastNSyllables(2, false))
s.Equal(2, res.WordsWithAtLeastNSyllables(3, false))
s.Equal(1, res.WordsWithAtLeastNSyllables(4, false))
s.Equal(0, res.WordsWithAtLeastNSyllables(5, false))
}
func (s *AnalyseSuite) TestPercentageWordsWithAtLeastNSyllables() {
res, _ := Analyse(strings.NewReader(hw))
s.Equal(100.0, res.PercentageWordsWithAtLeastNSyllables(0, true))
s.Equal(100.0, res.PercentageWordsWithAtLeastNSyllables(1, true))
s.Equal(50.0, res.PercentageWordsWithAtLeastNSyllables(2, true))
s.Equal(33.33333333333333, res.PercentageWordsWithAtLeastNSyllables(3, true))
s.Equal(16.666666666666664, res.PercentageWordsWithAtLeastNSyllables(4, true))
s.Equal(0.0, res.PercentageWordsWithAtLeastNSyllables(5, true))
s.Equal(66.66666666666666, res.PercentageWordsWithAtLeastNSyllables(0, false))
s.Equal(66.66666666666666, res.PercentageWordsWithAtLeastNSyllables(1, false))
s.Equal(33.33333333333333, res.PercentageWordsWithAtLeastNSyllables(3, false))
s.Equal(33.33333333333333, res.PercentageWordsWithAtLeastNSyllables(2, false))
s.Equal(16.666666666666664, res.PercentageWordsWithAtLeastNSyllables(4, false))
s.Equal(0.0, res.PercentageWordsWithAtLeastNSyllables(5, false))
}
func (s *AnalyseSuite) TestWordCount() {
res, _ := Analyse(strings.NewReader(qbf))
s.Equal(9, res.Words)
}
func (s *AnalyseSuite) TestLetterCount() {
res, _ := Analyse(strings.NewReader(qbf))
s.Equal(35, res.Letters)
}
func (s *AnalyseSuite) TestSentenceCount() {
res, _ := Analyse(strings.NewReader(lorem))
s.Equal(4, res.Sentences)
}
func (s *AnalyseSuite) TestSyllableCount() {
res, _ := Analyse(strings.NewReader(qbf))
s.Equal(11, res.Syllables)
}
func (s *AnalyseSuite) TestFleschKincaidReadingEase() {
res, _ := Analyse(strings.NewReader(lorem))
s.Equal(7.865380434782622, res.FleschKincaidReadingEase())
}
func (s *AnalyseSuite) TestFleschKincaidGradeLevel() {
res, _ := Analyse(strings.NewReader(lorem))
s.Equal(16.447644927536235, res.FleschKincaidGradeLevel())
}
func (s *AnalyseSuite) TestGunningFogScore() {
res, _ := Analyse(strings.NewReader(lorem))
s.Equal(19.073913043478264, res.GunningFogScore())
}
func (s *AnalyseSuite) TestColemanLiauIndex() {
res, _ := Analyse(strings.NewReader(lorem))
s.Equal(15.681304347826085, res.ColemanLiauIndex())
}
func (s *AnalyseSuite) TestSMOGIndex() {
res, _ := Analyse(strings.NewReader(lorem))
s.Equal(13.524018386038225, res.SMOGIndex())
}
func (s *AnalyseSuite) TestAutomatedReadabilityIndex() {
res, _ := Analyse(strings.NewReader(lorem))
s.Equal(12.383260869565213, res.AutomatedReadabilityIndex())
}
func (s *AnalyseSuite) TestDaleChallReadabilityScore() {
res, _ := Analyse(strings.NewReader(qbf))
s.Equal(5.837344444444444, res.DaleChallReadabilityScore())
}
func TestAnalyseMethods(t *testing.T) {
suite.Run(t, new(AnalyseSuite))
}