-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchain_test.go
99 lines (85 loc) · 2.15 KB
/
chain_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
package xrich
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
var logger *zap.Logger
func init() {
logger, _ = zap.NewDevelopment()
}
//testGeneratePolicy is mock
type testGeneratePolicy struct {
}
func (r testGeneratePolicy) init(c *MarkovChain) {
}
func (r testGeneratePolicy) findFirstPrefix(c *MarkovChain) Prefix {
return *c.keys[0]
}
func (r testGeneratePolicy) findNextPrefix(c *MarkovChain) Prefix {
return *c.keys[0]
}
func (r testGeneratePolicy) findSuffix(sx []Suffix) Suffix {
return sx[0]
}
func (r testGeneratePolicy) findPhrase(ss []string) string {
return ss[0]
}
func TestGenerate1(t *testing.T) {
ss := []string{"a b c"}
c := NewMarkovChain(logger)
c.SetGeneratePolicy(testGeneratePolicy{})
c.Build(ss)
s := c.GenerateSentence(3)
assert.Equal(t, "a b c", s)
}
func TestGenerate2(t *testing.T) {
ss := []string{"a b c b", "b c d"}
c := NewMarkovChain(logger)
c.SetGeneratePolicy(testGeneratePolicy{})
c.Build(ss)
s := c.GenerateSentence(6)
assert.Equal(t, "a b c b . a", s)
}
func TestAnswer1(t *testing.T) {
ss := []string{"a b c b", "b c d"}
c := NewMarkovChain(logger)
c.SetGeneratePolicy(testGeneratePolicy{})
c.Build(ss)
s := c.GenerateAnswer("a", 6)
assert.Equal(t, "a b c b", s)
}
func TestAnswer2(t *testing.T) {
ss := []string{"a b c b", "b c d"}
c := NewMarkovChain(logger)
c.SetGeneratePolicy(testGeneratePolicy{})
c.Build(ss)
s := c.GenerateAnswer("b", 6)
assert.Equal(t, "b c b", s)
}
func TestAnswer3(t *testing.T) {
ss := []string{"\u2318a, b: c- b.", "b c d"}
c := NewMarkovChain(logger)
c.SetGeneratePolicy(testGeneratePolicy{})
c.Build(ss)
fmt.Println(c.Dump())
s := c.GenerateAnswer("b", 6)
assert.Equal(t, "b c - b", s)
}
func TestAnswer4(t *testing.T) {
ss := []string{"a, . b c b . .", "b c d"}
c := NewMarkovChain(logger)
c.SetGeneratePolicy(testGeneratePolicy{})
c.Build(ss)
s := c.GenerateAnswer("a", 10)
assert.Equal(t, "a ,", s)
}
func TestAnswer5(t *testing.T) {
ss := []string{"a, . b c b . .", "b c d"}
c := NewMarkovChain(logger)
c.SetGeneratePolicy(testGeneratePolicy{})
c.Build(ss)
s := c.GenerateAnswer("b,c", 10)
assert.Equal(t, "b c b", s)
}