Skip to content

Commit

Permalink
Add unit test for Generate. Trim leading and trailing whitespace from…
Browse files Browse the repository at this point in the history
… generated sentences.
  • Loading branch information
colinfike committed Feb 8, 2020
1 parent 111f11b commit d3d2dff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mimic.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (m *MarkovChain) Generate() string {
sentence = sentence + delim + suffix
prefix = nextPrefix(prefix, suffix)
}
return sentence
return strings.TrimSpace(sentence)
}

func nextPrefix(prefix, suffix string) string {
Expand Down
8 changes: 8 additions & 0 deletions mimic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ func TestTrainThreeValid(t *testing.T) {
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
Expand Down

0 comments on commit d3d2dff

Please sign in to comment.