61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package services
|
|
|
|
import "testing"
|
|
|
|
func TestMockPronunciationReturnsWordScores(t *testing.T) {
|
|
result := mockPronunciation("Hello, my name is Anna.")
|
|
|
|
if result.Provider != "mock" {
|
|
t.Fatalf("expected mock provider, got %s", result.Provider)
|
|
}
|
|
if len(result.WordScores) != 5 {
|
|
t.Fatalf("expected 5 word scores, got %d", len(result.WordScores))
|
|
}
|
|
if result.OverallScore <= 0 {
|
|
t.Fatalf("expected positive score, got %f", result.OverallScore)
|
|
}
|
|
}
|
|
|
|
func TestParseAzurePronunciationTopLevelScores(t *testing.T) {
|
|
body := []byte(`{
|
|
"RecognitionStatus": "Success",
|
|
"DisplayText": "Can I have a coffee please?",
|
|
"NBest": [{
|
|
"Display": "Can I have a coffee please?",
|
|
"AccuracyScore": 94.0,
|
|
"FluencyScore": 99.0,
|
|
"CompletenessScore": 100.0,
|
|
"PronScore": 96.2,
|
|
"Words": [{
|
|
"Word": "can",
|
|
"AccuracyScore": 94.0,
|
|
"ErrorType": "None",
|
|
"Phonemes": [{"Phoneme": "k"}, {"Phoneme": "ae"}, {"Phoneme": "n"}]
|
|
}]
|
|
}]
|
|
}`)
|
|
|
|
result, err := parseAzurePronunciation(body)
|
|
if err != nil {
|
|
t.Fatalf("parse azure pronunciation: %v", err)
|
|
}
|
|
if result.Provider != "azure" {
|
|
t.Fatalf("expected azure provider, got %s", result.Provider)
|
|
}
|
|
if result.OverallScore != 96.2 {
|
|
t.Fatalf("expected overall score 96.2, got %f", result.OverallScore)
|
|
}
|
|
if result.AccuracyScore != 94 {
|
|
t.Fatalf("expected accuracy score 94, got %f", result.AccuracyScore)
|
|
}
|
|
if len(result.WordScores) != 1 {
|
|
t.Fatalf("expected one word score, got %d", len(result.WordScores))
|
|
}
|
|
if result.WordScores[0].Accuracy != 94 {
|
|
t.Fatalf("expected word accuracy 94, got %f", result.WordScores[0].Accuracy)
|
|
}
|
|
if result.WordScores[0].Highlight != "good" {
|
|
t.Fatalf("expected good highlight, got %s", result.WordScores[0].Highlight)
|
|
}
|
|
}
|