-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmimic_test.go
112 lines (96 loc) · 2.36 KB
/
mimic_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
100
101
102
103
104
105
106
107
108
109
110
111
112
package mimic
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTrainSingleValid(t *testing.T) {
testSet := []string{"hello there"}
markov := NewMarkovChain(2)
markov.Train(testSet)
expectedMap := map[string]map[string]struct{}{
" ": map[string]struct{}{
"hello": struct{}{},
},
" hello": map[string]struct{}{
"there": struct{}{},
},
"hello there": map[string]struct{}{
"": struct{}{},
},
}
assert.Equal(t, markov.chain, expectedMap)
}
func TestTrainTwoValid(t *testing.T) {
testSet := []string{"hello there", "hello there jon"}
markov := NewMarkovChain(2)
markov.Train(testSet)
expectedMap := map[string]map[string]struct{}{
" ": map[string]struct{}{
"hello": struct{}{},
},
" hello": map[string]struct{}{
"there": struct{}{},
},
"hello there": map[string]struct{}{
"": struct{}{},
"jon": struct{}{},
},
"there jon": map[string]struct{}{
"": struct{}{},
},
}
assert.Equal(t, markov.chain, expectedMap)
}
func TestTrainThreeValid(t *testing.T) {
testSet := []string{"hello there", "hello there jon", "Run there jon quickly!", "ignore"}
markov := NewMarkovChain(2)
markov.Train(testSet)
expectedMap := map[string]map[string]struct{}{
" ": map[string]struct{}{
"hello": struct{}{},
"run": struct{}{},
},
" run": map[string]struct{}{
"there": struct{}{},
},
" hello": map[string]struct{}{
"there": struct{}{},
},
"run there": map[string]struct{}{
"jon": struct{}{},
},
"hello there": map[string]struct{}{
"": struct{}{},
"jon": struct{}{},
},
"there jon": map[string]struct{}{
"quickly!": struct{}{},
"": struct{}{},
},
"jon quickly!": map[string]struct{}{
"": struct{}{},
},
}
assert.Equal(t, markov.chain, expectedMap)
}
func TestGenerate(t *testing.T) {
markov := NewMarkovChain(2)
testSet := []string{"Hello there jon"}
markov.Train(testSet)
assert.Equal(t, "hello there jon", markov.Generate())
}
var nextSuffixTests = []struct {
prefix string
suffix string
expectedPrefix string
}{
{" ", "nonempty", " nonempty"},
{" prefix", "suffix", "prefix suffix"},
{"ignored prefix", "suffix", "prefix suffix"},
}
func TestNextSuffix(t *testing.T) {
for _, testCase := range nextSuffixTests {
newPrefix := nextPrefix(testCase.prefix, testCase.suffix)
assert.Equal(t, testCase.expectedPrefix, newPrefix)
}
}