text:=`The giant brown dog! He jumped over the candlestick into a popsicle! What a disaster! But maybe a good disaster? He spent $1.50 on it. All the while he was chanting "U.S.A." like a madman.`
s:=sentencesFromText(text)
ifassert.Len(t,s,6){
assert.Equal(t,"What a disaster!",s[2])
assert.Equal(t,`All the while he was chanting "U.S.A." like a madman.`,s[5])
}
}
funcTestSentenceExtractionMultiline(t*testing.T){
text:=`Sentenceone.
Sentencetwo,onanewline.
Sentencethree,afterablankline!`
s:=sentencesFromText(text)
assert.Len(t,s,3)
assert.Equal(t,"Sentence two, on a new line.",s[1])
assert.Equal(t,`Sentence three, after a blank line!`,s[2])
}
funcTestSentenceNoPunctuation(t*testing.T){
text:=`this is just some words`
s:=sentencesFromText(text)
assert.Len(t,s,1)
assert.Equal(t,"this is just some words",s[0])
}
funcTestSentenceRepeatedPunctuation(t*testing.T){
text:=`this is just some words!! With a lot of emphasis!`
s:=sentencesFromText(text)
t.Skip("this case does not yet work?")
ifassert.Len(t,s,2){
assert.Equal(t,"this is just some words!!",s[0])
assert.Equal(t,"With a lot of emphasis!",s[1])
}
}
funcTestWordsInSentence(t*testing.T){
text:=`the quick brown dog`
words:=wordsInSentence(text)
assert.Len(t,words,4)
text=`the quick brown dog.`
words=wordsInSentence(text)
assert.Len(t,words,4)
text=`it cost $4.50, or more`
words=wordsInSentence(text)
assert.Len(t,words,5)
text="the quick gay dude ran to the new pink car in the state of mind to win"
words=wordsInSentence(text)
assert.Len(t,words,17)
assert.Equal(t,"the",words[0])
assert.Equal(t,"quick",words[1])
assert.Equal(t,"to",words[15])
assert.Equal(t,"win",words[16])
text="the quick gay dude ran to the new pink car in the state of mind to win!"
words=wordsInSentence(text)
assert.Len(t,words,17)
assert.Equal(t,"the",words[0])
assert.Equal(t,"quick",words[1])
assert.Equal(t,"to",words[15])
assert.Equal(t,"win",words[16])
text=""
words=wordsInSentence(text)
assert.Len(t,words,0)
}
funcTestHaikuFromSentence(t*testing.T){
// 1 2 3 4 5| 6 7 8 9 10 11 12| 13 14 15 16 17
h,err:=haikuFromSentence("the quick fast dude ran to the new red car in the state of mind to win")
ifassert.NoError(t,err){
assert.Equal(t,`thequickfastduderan
tothenewredcarinthe
stateofmindtowin`,
h.String())
assert.Equal(t,"to the new red car in the",h.Lines()[1])
}
_,err=haikuFromSentence("did u talk also about the breakup part? like why it happened and if that reason is still a thing?")
assert.ErrorContains(t,err,"not a haiku - too many words")
h,err=haikuFromSentence("by grabthar's hammer, what a savings you can make - almost criminal")
ifassert.NoError(t,err){
assert.Equal(t,`bygrabthar'shammer,
whatasavingsyoucanmake
-almostcriminal`,
h.String())
}
h,err=haikuFromSentence("")
assert.ErrorContains(t,err,"sentence has 0 words")