-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_correct_test.go
79 lines (61 loc) · 2.53 KB
/
batch_correct_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
package gospel
// Word list from:
// https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines
import (
"testing"
"github.com/stretchr/testify/assert"
"strconv"
)
const BENCHMARK_CORRECT_PERCENT = 0.55
func TestBatchCorrections_Ab(t *testing.T){
c := ForEnglish()
misspellings := []ExpectedCorrection{
ExpectedCorrection{wrong: "abandonned", right: "abandoned"},
ExpectedCorrection{wrong: "aberation", right: "aberration"},
ExpectedCorrection{wrong: "abilityes", right: "abilities"},
ExpectedCorrection{wrong: "abilties", right: "abilities"},
ExpectedCorrection{wrong: "abilty", right: "ability"},
ExpectedCorrection{wrong: "abondon", right: "abandon"},
ExpectedCorrection{wrong: "abbout", right: "about"}}
assertCorrectBenchmark(t, batchCorrectPercent(&c, misspellings))
}
func TestBatchCorrections_Em(t *testing.T){
c := ForEnglish()
misspellings := []ExpectedCorrection{
ExpectedCorrection{wrong: "embarass", right: "embarrass"},
ExpectedCorrection{wrong: "embarassed", right: "embarrassed"},
ExpectedCorrection{wrong: "emblamatic", right: "emblematic"},
ExpectedCorrection{wrong: "eminate", right: "emanate"},
ExpectedCorrection{wrong: "emision", right: "emission"},
ExpectedCorrection{wrong: "emited", right: "emitted"},
ExpectedCorrection{wrong: "emmediately", right: "immediately"}}
assertCorrectBenchmark(t, batchCorrectPercent(&c, misspellings))
}
func TestBatchCorrections_Hi(t *testing.T){
c := ForEnglish()
misspellings := []ExpectedCorrection{
ExpectedCorrection{wrong:"hieght", right: "height"},
ExpectedCorrection{wrong:"hierachical", right: "hierarchical"},
ExpectedCorrection{wrong:"hieroglph", right: "hieroglyph"},
ExpectedCorrection{wrong:"higer", right: "higher"},
ExpectedCorrection{wrong:"higway", right: "highway"},
ExpectedCorrection{wrong:"himselv", right: "himself"},
ExpectedCorrection{wrong:"hitsingles", right: "hit singles"}}
assertCorrectBenchmark(t, batchCorrectPercent(&c, misspellings))
}
func batchCorrectPercent(c *Corrector, misspellings []ExpectedCorrection) float64 {
rights := 0.0
for _, ms := range misspellings {
corrected := c.Correct(ms.wrong)
if corrected == ms.right {
rights++
}
}
return float64(rights)/float64(len(misspellings))
}
func assertCorrectBenchmark(t *testing.T, pct float64) {
assert.True(t, pct > BENCHMARK_CORRECT_PERCENT, "Correct percent was: " + strconv.FormatFloat(pct, 'f', -1, 64))
}
type ExpectedCorrection struct {
wrong, right string
}