mirror of
https://github.com/fumiama/jieba.git
synced 2026-06-09 19:20:26 +08:00
updated all tests to use Fatal/Fatalf to fail tests ealier
This commit is contained in:
@@ -260,11 +260,11 @@ func TestExtractTags(t *testing.T) {
|
||||
for index, sentence := range test_contents {
|
||||
result := et.ExtractTags(sentence, 20)
|
||||
if len(result) != len(Tags[index]) {
|
||||
t.Errorf("%s = %v", sentence, result)
|
||||
t.Fatalf("%s = %v", sentence, result)
|
||||
}
|
||||
for i, tag := range result {
|
||||
if tag.Word != Tags[index][i] {
|
||||
t.Errorf("%s != %s", tag, Tags[index][i])
|
||||
t.Fatalf("%s != %s", tag, Tags[index][i])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,7 +276,7 @@ func TestExtratTagsWithWeight(t *testing.T) {
|
||||
for index, tag := range result {
|
||||
if LyciWeight[index].Word != tag.Word ||
|
||||
math.Abs(LyciWeight[index].Weight-tag.Weight) > 1e-6 {
|
||||
t.Errorf("%v != %v", tag, LyciWeight[index])
|
||||
t.Fatalf("%v != %v", tag, LyciWeight[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,7 +288,7 @@ func TestExtractTagsWithStopWordsFile(t *testing.T) {
|
||||
for index, tag := range result {
|
||||
if LyciWeight2[index].Word != tag.Word ||
|
||||
math.Abs(LyciWeight2[index].Weight-tag.Weight) > 1e-6 {
|
||||
t.Errorf("%v != %v", tag, LyciWeight2[index])
|
||||
t.Fatalf("%v != %v", tag, LyciWeight2[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestTextRank(t *testing.T) {
|
||||
results := tr.TextRank(sentence, 10)
|
||||
for index, tw := range results {
|
||||
if tw.Word != tagRanks[index].Word || math.Abs(tw.Weight-tagRanks[index].Weight) > 1e-6 {
|
||||
t.Errorf("%v != %v", tw, tagRanks[index])
|
||||
t.Fatalf("%v != %v", tw, tagRanks[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ func TestViterbi(t *testing.T) {
|
||||
states := []byte{'B', 'M', 'E', 'S'}
|
||||
prob, path := viterbi([]rune(obs), states)
|
||||
if math.Abs(prob+39.68824128493802) > 1e-10 {
|
||||
t.Error(prob)
|
||||
t.Fatal(prob)
|
||||
}
|
||||
for index, state := range []byte{'B', 'E', 'S', 'B', 'M', 'E'} {
|
||||
if path[index] != state {
|
||||
t.Error(path)
|
||||
t.Fatal(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,16 +31,16 @@ func TestCutHan(t *testing.T) {
|
||||
obs := "我们是程序员"
|
||||
result := chanToArray(cutHan(obs))
|
||||
if len(result) != 3 {
|
||||
t.Error(result)
|
||||
t.Fatal(result)
|
||||
}
|
||||
if result[0] != "我们" {
|
||||
t.Error(result[0])
|
||||
t.Fatal(result[0])
|
||||
}
|
||||
if result[1] != "是" {
|
||||
t.Error(result[1])
|
||||
t.Fatal(result[1])
|
||||
}
|
||||
if result[2] != "程序员" {
|
||||
t.Error(result[2])
|
||||
t.Fatal(result[2])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,24 +48,24 @@ func TestCut(t *testing.T) {
|
||||
sentence := "我们是程序员"
|
||||
result := chanToArray(Cut(sentence))
|
||||
if len(result) != 3 {
|
||||
t.Error(len(result))
|
||||
t.Fatal(len(result))
|
||||
}
|
||||
if result[0] != "我们" {
|
||||
t.Error(result[0])
|
||||
t.Fatal(result[0])
|
||||
}
|
||||
if result[1] != "是" {
|
||||
t.Error(result[1])
|
||||
t.Fatal(result[1])
|
||||
}
|
||||
if result[2] != "程序员" {
|
||||
t.Error(result[2])
|
||||
t.Fatal(result[2])
|
||||
}
|
||||
result2 := chanToArray(Cut("I'm a programmer!"))
|
||||
if len(result2) != 8 {
|
||||
t.Error(result2)
|
||||
t.Fatal(result2)
|
||||
}
|
||||
result3 := chanToArray(Cut("程序员average年龄28.6岁。"))
|
||||
if len(result3) != 6 {
|
||||
t.Error(result3)
|
||||
t.Fatal(result3)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -630,7 +630,7 @@ func TestCutDAG(t *testing.T) {
|
||||
|
||||
result := chanToArray(j.cutDAG("BP神经网络如何训练才能在分类时增加区分度?"))
|
||||
if len(result) != 11 {
|
||||
t.Error(result)
|
||||
t.Fatal(result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -639,7 +639,7 @@ func TestCutDAGNoHmm(t *testing.T) {
|
||||
|
||||
result := chanToArray(j.cutDAGNoHMM("BP神经网络如何训练才能在分类时增加区分度?"))
|
||||
if len(result) != 11 {
|
||||
t.Error(result)
|
||||
t.Fatal(result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -647,12 +647,12 @@ func TestRegexpSplit(t *testing.T) {
|
||||
result := chanToArray(RegexpSplit(regexp.MustCompile(`\p{Han}+`),
|
||||
"BP神经网络如何训练才能在分类时增加区分度?"))
|
||||
if len(result) != 3 {
|
||||
t.Error(result)
|
||||
t.Fatal(result)
|
||||
}
|
||||
result = chanToArray(RegexpSplit(regexp.MustCompile(`([\p{Han}#]+)`),
|
||||
",BP神经网络如何训练才能在分类时#增加区分度?"))
|
||||
if len(result) != 3 {
|
||||
t.Error(result)
|
||||
t.Fatal(result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,12 +663,12 @@ func TestDefaultCut(t *testing.T) {
|
||||
for index, content := range test_contents {
|
||||
result = chanToArray(j.Cut(content, true))
|
||||
if len(result) != len(defaultCutResult[index]) {
|
||||
t.Errorf("default cut for %s length should be %d not %d\n",
|
||||
t.Fatalf("default cut for %s length should be %d not %d\n",
|
||||
content, len(defaultCutResult[index]), len(result))
|
||||
}
|
||||
for i, r := range result {
|
||||
if r != defaultCutResult[index][i] {
|
||||
t.Error(r)
|
||||
t.Fatal(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -681,12 +681,12 @@ func TestCutAll(t *testing.T) {
|
||||
for index, content := range test_contents {
|
||||
result = chanToArray(j.CutAll(content))
|
||||
if len(result) != len(cutAllResult[index]) {
|
||||
t.Errorf("cut all for %s length should be %d not %d\n",
|
||||
t.Fatalf("cut all for %s length should be %d not %d\n",
|
||||
content, len(cutAllResult[index]), len(result))
|
||||
}
|
||||
for i, c := range result {
|
||||
if c != cutAllResult[index][i] {
|
||||
t.Error(c)
|
||||
t.Fatal(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -699,12 +699,12 @@ func TestDefaultCutNoHMM(t *testing.T) {
|
||||
for index, content := range test_contents {
|
||||
result = chanToArray(j.Cut(content, false))
|
||||
if len(result) != len(defaultCutNoHMMResult[index]) {
|
||||
t.Errorf("default cut no hmm for %s length should be %d not %d\n",
|
||||
t.Fatalf("default cut no hmm for %s length should be %d not %d\n",
|
||||
content, len(defaultCutNoHMMResult[index]), len(result))
|
||||
}
|
||||
for i, c := range result {
|
||||
if c != defaultCutNoHMMResult[index][i] {
|
||||
t.Error(c)
|
||||
t.Fatal(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -717,24 +717,24 @@ func TestCutForSearch(t *testing.T) {
|
||||
for index, content := range test_contents {
|
||||
result = chanToArray(j.CutForSearch(content, true))
|
||||
if len(result) != len(cutForSearchResult[index]) {
|
||||
t.Errorf("cut for search for %s length should be %d not %d\n",
|
||||
t.Fatalf("cut for search for %s length should be %d not %d\n",
|
||||
content, len(cutForSearchResult[index]), len(result))
|
||||
}
|
||||
for i, c := range result {
|
||||
if c != cutForSearchResult[index][i] {
|
||||
t.Error(c)
|
||||
t.Fatal(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
for index, content := range test_contents {
|
||||
result = chanToArray(j.CutForSearch(content, false))
|
||||
if len(result) != len(cutForSearchNoHMMResult[index]) {
|
||||
t.Errorf("cut for search no hmm for %s length should be %d not %d\n",
|
||||
t.Fatalf("cut for search no hmm for %s length should be %d not %d\n",
|
||||
content, len(cutForSearchNoHMMResult[index]), len(result))
|
||||
}
|
||||
for i, c := range result {
|
||||
if c != cutForSearchNoHMMResult[index][i] {
|
||||
t.Error(c)
|
||||
t.Fatal(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -746,12 +746,12 @@ func TestSetdictionary(t *testing.T) {
|
||||
for index, content := range test_contents {
|
||||
result = chanToArray(j.Cut(content, true))
|
||||
if len(result) != len(userDictCutResult[index]) {
|
||||
t.Errorf("default cut with user dictionary for %s length should be %d not %d\n",
|
||||
t.Fatalf("default cut with user dictionary for %s length should be %d not %d\n",
|
||||
content, len(userDictCutResult[index]), len(result))
|
||||
}
|
||||
for i, c := range result {
|
||||
if c != userDictCutResult[index][i] {
|
||||
t.Error(c)
|
||||
t.Fatal(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -766,11 +766,11 @@ func TestLoadUserDict(t *testing.T) {
|
||||
|
||||
words := chanToArray(j.Cut(sentence, true))
|
||||
if len(words) != len(result) {
|
||||
t.Error(len(words))
|
||||
t.Fatal(len(words))
|
||||
}
|
||||
for index, word := range words {
|
||||
if word != result[index] {
|
||||
t.Error(word)
|
||||
t.Fatal(word)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -778,11 +778,11 @@ func TestLoadUserDict(t *testing.T) {
|
||||
result = []string{"easy_install", " ", "is", " ", "great"}
|
||||
words = chanToArray(j.Cut(sentence, true))
|
||||
if len(words) != len(result) {
|
||||
t.Error(len(words))
|
||||
t.Fatal(len(words))
|
||||
}
|
||||
for index, word := range words {
|
||||
if word != result[index] {
|
||||
t.Error(word)
|
||||
t.Fatal(word)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -790,12 +790,12 @@ func TestLoadUserDict(t *testing.T) {
|
||||
result = []string{"python", " ", "的", "正则表达式", "是", "好用", "的"}
|
||||
words = chanToArray(j.Cut(sentence, true))
|
||||
if len(words) != len(result) {
|
||||
t.Error(words)
|
||||
t.Error(result)
|
||||
t.Fatal(words)
|
||||
t.Fatal(result)
|
||||
}
|
||||
for index, word := range words {
|
||||
if word != result[index] {
|
||||
t.Error(word)
|
||||
t.Fatal(word)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,20 +283,20 @@ func TestCut(t *testing.T) {
|
||||
for index, content := range test_contents {
|
||||
result := chanToArray(p.Cut(content, true))
|
||||
if len(defaultCutResult[index]) != len(result) {
|
||||
t.Error(content)
|
||||
t.Fatal(content)
|
||||
}
|
||||
for i, _ := range result {
|
||||
if result[i] != defaultCutResult[index][i] {
|
||||
t.Errorf("expect %s, got %s", defaultCutResult[index][i], result[i])
|
||||
t.Fatalf("expect %s, got %s", defaultCutResult[index][i], result[i])
|
||||
}
|
||||
}
|
||||
result = chanToArray(p.Cut(content, false))
|
||||
if len(noHMMCutResult[index]) != len(result) {
|
||||
t.Error(content)
|
||||
t.Fatal(content)
|
||||
}
|
||||
for i, _ := range result {
|
||||
if result[i] != noHMMCutResult[index][i] {
|
||||
t.Error(content)
|
||||
t.Fatal(content)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,11 +317,11 @@ func TestBug132(t *testing.T) {
|
||||
}
|
||||
result := chanToArray(p.Cut(sentence, true))
|
||||
if len(cutResult) != len(result) {
|
||||
t.Error(result)
|
||||
t.Fatal(result)
|
||||
}
|
||||
for i, _ := range result {
|
||||
if result[i] != cutResult[i] {
|
||||
t.Error(result[i])
|
||||
t.Fatal(result[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -349,11 +349,11 @@ func TestBug137(t *testing.T) {
|
||||
}
|
||||
result := chanToArray(p.Cut(sentence, true))
|
||||
if len(cutResult) != len(result) {
|
||||
t.Error(result)
|
||||
t.Fatal(result)
|
||||
}
|
||||
for i, _ := range result {
|
||||
if result[i] != cutResult[i] {
|
||||
t.Error(result[i])
|
||||
t.Fatal(result[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -404,11 +404,11 @@ func TestUserDict(t *testing.T) {
|
||||
|
||||
result := chanToArray(p.Cut(sentence, true))
|
||||
if len(cutResult) != len(result) {
|
||||
t.Error(result)
|
||||
t.Fatal(result)
|
||||
}
|
||||
for i, _ := range result {
|
||||
if result[i] != cutResult[i] {
|
||||
t.Error(result[i])
|
||||
t.Fatal(result[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +32,11 @@ func TestViterbi(t *testing.T) {
|
||||
ss := "李小福是创新办主任也是云计算方面的专家;"
|
||||
route := viterbi([]rune(ss))
|
||||
if len(route) != len(route1) {
|
||||
t.Error(len(route))
|
||||
t.Fatal(len(route))
|
||||
}
|
||||
for index, _ := range route {
|
||||
if route[index] != route1[index] {
|
||||
t.Error(route[index])
|
||||
t.Fatal(route[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22509,7 +22509,7 @@ func TestJiebaTokenizerSearchModeWithoutHMM(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
actual := tokenizer.Tokenize(test.input)
|
||||
if !reflect.DeepEqual(actual, test.output) {
|
||||
t.Errorf("Expected %v, got %v for %s", test.output, actual, string(test.input))
|
||||
t.Fatalf("Expected %v, got %v for %s", test.output, actual, string(test.input))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user