-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfidence_test.go
More file actions
71 lines (65 loc) · 1.68 KB
/
confidence_test.go
File metadata and controls
71 lines (65 loc) · 1.68 KB
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
package model
import (
"encoding/json"
"strings"
"testing"
)
func TestConfidenceScores(t *testing.T) {
cases := map[Confidence]float64{
ConfidenceLexical: 0.6,
ConfidenceSyntactic: 0.8,
ConfidenceResolved: 0.95,
}
for c, want := range cases {
if got := c.Score(); got != want {
t.Errorf("%v.Score() = %v, want %v", c, got, want)
}
}
}
func TestConfidenceOrdering(t *testing.T) {
if !(ConfidenceLexical < ConfidenceSyntactic) {
t.Error("LEXICAL should be < SYNTACTIC")
}
if !(ConfidenceSyntactic < ConfidenceResolved) {
t.Error("SYNTACTIC should be < RESOLVED")
}
}
func TestConfidenceString(t *testing.T) {
if ConfidenceLexical.String() != "LEXICAL" {
t.Errorf("LEXICAL string = %q", ConfidenceLexical.String())
}
if ConfidenceResolved.String() != "RESOLVED" {
t.Errorf("RESOLVED string = %q", ConfidenceResolved.String())
}
}
func TestConfidenceParseCaseInsensitive(t *testing.T) {
for _, in := range []string{"lexical", "LEXICAL", "Lexical", " lexical "} {
c, err := ParseConfidence(strings.TrimSpace(in))
if err != nil {
t.Errorf("ParseConfidence(%q) error = %v", in, err)
continue
}
if c != ConfidenceLexical {
t.Errorf("ParseConfidence(%q) = %v, want LEXICAL", in, c)
}
}
if _, err := ParseConfidence("nope"); err == nil {
t.Error("ParseConfidence(\"nope\") err = nil, want non-nil")
}
}
func TestConfidenceJSON(t *testing.T) {
b, err := json.Marshal(ConfidenceResolved)
if err != nil {
t.Fatal(err)
}
if string(b) != `"RESOLVED"` {
t.Fatalf("Marshal = %s", b)
}
var c Confidence
if err := json.Unmarshal([]byte(`"SYNTACTIC"`), &c); err != nil {
t.Fatal(err)
}
if c != ConfidenceSyntactic {
t.Fatal("Unmarshal mismatch")
}
}