mirror of
https://github.com/fumiama/jieba.git
synced 2026-06-05 00:32:51 +08:00
added more tests for dictionary.go
This commit is contained in:
@@ -33,13 +33,33 @@ func TestLoadUserDictionary(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFrequency(t *testing.T) {
|
||||||
|
d.LoadUserDictionary("../userdict.txt")
|
||||||
|
if f, _ := d.Frequency("八一双鹿"); f != 3.0 {
|
||||||
|
t.Fatalf("Wrong frequency for word \"八一双鹿\", expect 3.0, got %f", f)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestTotal(t *testing.T) {
|
func TestTotal(t *testing.T) {
|
||||||
d.LoadDictionary("../userdict.txt")
|
d.LoadDictionary("../userdict.txt")
|
||||||
|
|
||||||
if d.Total() != 319.0 {
|
if d.Total() != 319.0 {
|
||||||
t.Fatalf("Wrong total for userdict.txt, expect 319.0, got %f", d.Total())
|
t.Fatalf("Wrong total for userdict.txt, expect 319.0, got %f", d.Total())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLogTotal(t *testing.T) {
|
||||||
|
d.LoadDictionary("../userdict.txt")
|
||||||
if d.LogTotal() != math.Log(319.0) {
|
if d.LogTotal() != math.Log(319.0) {
|
||||||
t.Fatalf("Wrong total for userdict.txt, expect %f, got %f", math.Log(319.0), d.LogTotal())
|
t.Fatalf("Wrong total for userdict.txt, expect %f, got %f", math.Log(319.0), d.LogTotal())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAddToken(t *testing.T) {
|
||||||
|
d.LoadDictionary("../userdict.txt")
|
||||||
|
token := Token{text: "超敏C反应蛋白", frequency: 100.0, pos: "nz"}
|
||||||
|
d.AddToken(token)
|
||||||
|
if f, _ := d.Frequency("超敏C反应蛋白"); f != 100.0 {
|
||||||
|
t.Fatalf("Failed to add Token \"超敏C反应蛋白\", except frequency 100.0, got %f", f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user