From 7e737fd3cd675c5d38159932bef74d0b319b25a9 Mon Sep 17 00:00:00 2001 From: Yoshida Hiroshi Date: Fri, 20 Dec 2024 12:26:57 +0900 Subject: [PATCH] =?UTF-8?q?IsPartial=20=E5=80=A4=E3=81=94=E3=81=A8?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- amazon_transcribe_handler_test.go | 520 ++++++++++++++++++++---------- 1 file changed, 357 insertions(+), 163 deletions(-) diff --git a/amazon_transcribe_handler_test.go b/amazon_transcribe_handler_test.go index 41bd263..a88e44f 100644 --- a/amazon_transcribe_handler_test.go +++ b/amazon_transcribe_handler_test.go @@ -200,194 +200,388 @@ func TestBuildMessage(t *testing.T) { }) t.Run("minimumConfidence", func(t *testing.T) { - testCases := []struct { - Name string - Config Config - Input Input - Expect Expect - }{ - { - Name: "minimumConfidenceScore is 0", - Config: Config{ - MinimumConfidenceScore: 0, - }, - Input: Input{ - Alt: transcribestreamingservice.Alternative{ - Items: []*transcribestreamingservice.Item{ - { - Confidence: aws.Float64(0), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("test"), - }, - { - Confidence: aws.Float64(0), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("data"), + t.Run("IsPartial == false", func(t *testing.T) { + testCases := []struct { + Name string + Config Config + Input Input + Expect Expect + }{ + { + Name: "minimumConfidenceScore is 0", + Config: Config{ + MinimumConfidenceScore: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("test"), + }, + { + Confidence: aws.Float64(0), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("data"), + }, }, }, + IsPartial: false, + }, + Expect: Expect{ + Message: "testdata", + Ok: true, }, - IsPartial: false, - }, - Expect: Expect{ - Message: "testdata", - Ok: true, - }, - }, - { - Name: "confidence > minimumConfidenceScore ", - Config: Config{ - MinimumConfidenceScore: 0.1, - MinimumTranscribedTime: 0, }, - Input: Input{ - Alt: transcribestreamingservice.Alternative{ - Items: []*transcribestreamingservice.Item{ - { - Confidence: aws.Float64(0.11), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("test"), - }, - { - Confidence: aws.Float64(0), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("data"), - }, - { - Confidence: aws.Float64(0.11), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("1"), + { + Name: "confidence > minimumConfidenceScore ", + Config: Config{ + MinimumConfidenceScore: 0.1, + MinimumTranscribedTime: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0.11), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("test"), + }, + { + Confidence: aws.Float64(0), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("data"), + }, + { + Confidence: aws.Float64(0.11), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("1"), + }, }, }, + IsPartial: false, + }, + Expect: Expect{ + Message: "test1", + Ok: true, }, - IsPartial: false, - }, - Expect: Expect{ - Message: "test1", - Ok: true, - }, - }, - { - Name: "confidence == minimumConfidenceScore ", - Config: Config{ - MinimumConfidenceScore: 0.1, - MinimumTranscribedTime: 0, }, - Input: Input{ - Alt: transcribestreamingservice.Alternative{ - Items: []*transcribestreamingservice.Item{ - { - Confidence: aws.Float64(0.1), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("test"), - }, - { - Confidence: aws.Float64(0.1), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("data"), - }, - { - Confidence: aws.Float64(0.1), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("1"), + { + Name: "confidence == minimumConfidenceScore ", + Config: Config{ + MinimumConfidenceScore: 0.1, + MinimumTranscribedTime: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0.1), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("test"), + }, + { + Confidence: aws.Float64(0.1), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("data"), + }, + { + Confidence: aws.Float64(0.1), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("1"), + }, }, }, + IsPartial: false, + }, + Expect: Expect{ + Message: "testdata1", + Ok: true, }, - IsPartial: false, - }, - Expect: Expect{ - Message: "testdata1", - Ok: true, - }, - }, - { - Name: "confidence < minimumConfidenceScore ", - Config: Config{ - MinimumConfidenceScore: 0.1, - MinimumTranscribedTime: 0, }, - Input: Input{ - Alt: transcribestreamingservice.Alternative{ - Items: []*transcribestreamingservice.Item{ - { - Confidence: aws.Float64(0), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("test"), - }, - { - Confidence: aws.Float64(0.09), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("data"), - }, - { - Confidence: aws.Float64(0.09), - StartTime: aws.Float64(0), - EndTime: aws.Float64(0), - Content: aws.String("1"), + { + Name: "confidence < minimumConfidenceScore ", + Config: Config{ + MinimumConfidenceScore: 0.1, + MinimumTranscribedTime: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("test"), + }, + { + Confidence: aws.Float64(0.09), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("data"), + }, + { + Confidence: aws.Float64(0.09), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("1"), + }, }, }, + IsPartial: false, + }, + Expect: Expect{ + Message: "", + Ok: false, }, - IsPartial: false, }, - Expect: Expect{ - Message: "", - Ok: false, + { + Name: "punctuation", + Config: Config{ + MinimumConfidenceScore: 0.1, + MinimumTranscribedTime: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0.2), + StartTime: aws.Float64(1.0), + EndTime: aws.Float64(1.02), + Content: aws.String("テスト"), + }, + { + // 句読点は Confidence は nil + Confidence: nil, + StartTime: aws.Float64(1.02), + EndTime: aws.Float64(1.02), + Content: aws.String("、"), + }, + { + Confidence: aws.Float64(0.2), + StartTime: aws.Float64(1.02), + EndTime: aws.Float64(1.04), + Content: aws.String("データ"), + }, + }, + }, + IsPartial: false, + }, + Expect: Expect{ + Message: "テスト、データ", + Ok: true, + }, }, - }, - { - Name: "punctuation", - Config: Config{ - MinimumConfidenceScore: 0.1, - MinimumTranscribedTime: 0, + } + + for _, tc := range testCases { + t.Run(tc.Name, func(t *testing.T) { + actual, ok := buildMessage(tc.Config, tc.Input.Alt, tc.Input.IsPartial) + assert.Equal(t, tc.Expect.Ok, ok) + assert.Equal(t, tc.Expect.Message, actual) + }) + } + }) + + t.Run("IsPartial == true", func(t *testing.T) { + testCases := []struct { + Name string + Config Config + Input Input + Expect Expect + }{ + { + Name: "minimumConfidenceScore is 0", + Config: Config{ + MinimumConfidenceScore: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("test"), + }, + { + Confidence: aws.Float64(0), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("data"), + }, + }, + }, + IsPartial: true, + }, + Expect: Expect{ + Message: "testdata", + Ok: true, + }, }, - Input: Input{ - Alt: transcribestreamingservice.Alternative{ - Items: []*transcribestreamingservice.Item{ - { - Confidence: aws.Float64(0.2), - StartTime: aws.Float64(1.0), - EndTime: aws.Float64(1.02), - Content: aws.String("テスト"), + { + Name: "confidence > minimumConfidenceScore ", + Config: Config{ + MinimumConfidenceScore: 0.1, + MinimumTranscribedTime: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0.11), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("test"), + }, + { + Confidence: aws.Float64(0), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("data"), + }, + { + Confidence: aws.Float64(0.11), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("1"), + }, }, - { - // 句読点は Confidence は nil - Confidence: nil, - StartTime: aws.Float64(1.02), - EndTime: aws.Float64(1.02), - Content: aws.String("、"), + }, + IsPartial: true, + }, + Expect: Expect{ + Message: "testdata1", + Ok: true, + }, + }, + { + Name: "confidence == minimumConfidenceScore ", + Config: Config{ + MinimumConfidenceScore: 0.1, + MinimumTranscribedTime: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0.1), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("test"), + }, + { + Confidence: aws.Float64(0.1), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("data"), + }, + { + Confidence: aws.Float64(0.1), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("1"), + }, }, - { - Confidence: aws.Float64(0.2), - StartTime: aws.Float64(1.02), - EndTime: aws.Float64(1.04), - Content: aws.String("データ"), + }, + IsPartial: true, + }, + Expect: Expect{ + Message: "testdata1", + Ok: true, + }, + }, + { + Name: "confidence < minimumConfidenceScore ", + Config: Config{ + MinimumConfidenceScore: 0.1, + MinimumTranscribedTime: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("test"), + }, + { + Confidence: aws.Float64(0.09), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("data"), + }, + { + Confidence: aws.Float64(0.09), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Content: aws.String("1"), + }, }, }, + IsPartial: true, + }, + Expect: Expect{ + Message: "testdata1", + Ok: true, }, - IsPartial: false, }, - Expect: Expect{ - Message: "テスト、データ", - Ok: true, + { + Name: "punctuation", + Config: Config{ + MinimumConfidenceScore: 0.1, + MinimumTranscribedTime: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Items: []*transcribestreamingservice.Item{ + { + Confidence: aws.Float64(0.2), + StartTime: aws.Float64(1.0), + EndTime: aws.Float64(1.02), + Content: aws.String("テスト"), + }, + { + // 句読点は Confidence は nil + Confidence: nil, + StartTime: aws.Float64(1.02), + EndTime: aws.Float64(1.02), + Content: aws.String("、"), + }, + { + Confidence: aws.Float64(0.2), + StartTime: aws.Float64(1.02), + EndTime: aws.Float64(1.04), + Content: aws.String("データ"), + }, + }, + }, + IsPartial: true, + }, + Expect: Expect{ + Message: "テスト、データ", + Ok: true, + }, }, - }, - } + } - for _, tc := range testCases { - t.Run(tc.Name, func(t *testing.T) { - actual, ok := buildMessage(tc.Config, tc.Input.Alt, tc.Input.IsPartial) - assert.Equal(t, tc.Expect.Ok, ok) - assert.Equal(t, tc.Expect.Message, actual) - }) - } + for _, tc := range testCases { + t.Run(tc.Name, func(t *testing.T) { + actual, ok := buildMessage(tc.Config, tc.Input.Alt, tc.Input.IsPartial) + assert.Equal(t, tc.Expect.Ok, ok) + assert.Equal(t, tc.Expect.Message, actual) + }) + } + }) }) }