router/semantic: tests for contrastive safety transforms (slice 12)
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
package semantic
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNegationTransform(t *testing.T) {
|
||||
pairs := negationTransform("ru-act-002", "выключи свет в спальне", RouteAction)
|
||||
if len(pairs) == 0 {
|
||||
t.Fatal("negationTransform returned no pairs")
|
||||
}
|
||||
for _, p := range pairs {
|
||||
if p.Route != RouteUncertain {
|
||||
t.Errorf("negation of %q: got route %q, want uncertain", p.BaseText, p.Route)
|
||||
}
|
||||
if p.Transform != "negation" {
|
||||
t.Errorf("transform name = %q, want negation", p.Transform)
|
||||
}
|
||||
}
|
||||
pairs = negationTransform("ru-chat-001", "привет", RouteConversation)
|
||||
if len(pairs) != 0 {
|
||||
t.Error("negationTransform produced pairs for non-action route")
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuestionTransform(t *testing.T) {
|
||||
pairs := questionTransform("ru-act-002", "выключи свет в спальне", RouteAction)
|
||||
if len(pairs) == 0 {
|
||||
t.Fatal("questionTransform returned no pairs")
|
||||
}
|
||||
for _, p := range pairs {
|
||||
if p.Route != RouteKnowledge {
|
||||
t.Errorf("question of %q: got route %q, want knowledge", p.BaseText, p.Route)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReportedSpeechTransform(t *testing.T) {
|
||||
pairs := reportedSpeechTransform("ru-act-002", "выключи свет в спальне", RouteAction)
|
||||
if len(pairs) == 0 {
|
||||
t.Fatal("reportedSpeechTransform returned no pairs")
|
||||
}
|
||||
for _, p := range pairs {
|
||||
if p.Route != RouteUncertain {
|
||||
t.Errorf("reported speech of %q: got route %q, want uncertain", p.BaseText, p.Route)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuotationTransform(t *testing.T) {
|
||||
pairs := quotationTransform("ru-act-002", "выключи свет в спальне", RouteAction)
|
||||
if len(pairs) == 0 {
|
||||
t.Fatal("quotationTransform returned no pairs")
|
||||
}
|
||||
for _, p := range pairs {
|
||||
if p.Route != RouteUncertain {
|
||||
t.Errorf("quotation of %q: got route %q, want uncertain", p.BaseText, p.Route)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHypotheticalTransform(t *testing.T) {
|
||||
pairs := hypotheticalTransform("ru-act-002", "выключи свет в спальне", RouteAction)
|
||||
if len(pairs) == 0 {
|
||||
t.Fatal("hypotheticalTransform returned no pairs")
|
||||
}
|
||||
for _, p := range pairs {
|
||||
if p.Route != RouteUncertain {
|
||||
t.Errorf("hypothetical of %q: got route %q, want uncertain", p.BaseText, p.Route)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCapabilityQuestionTransform(t *testing.T) {
|
||||
pairs := capabilityQuestionTransform("ru-act-002", "выключи свет в спальне", RouteAction)
|
||||
if len(pairs) == 0 {
|
||||
t.Fatal("capabilityQuestionTransform returned no pairs")
|
||||
}
|
||||
for _, p := range pairs {
|
||||
if p.Route != RouteKnowledge {
|
||||
t.Errorf("capability question of %q: got route %q, want knowledge", p.BaseText, p.Route)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateContrastivePairs(t *testing.T) {
|
||||
bases := []RouteExample{
|
||||
{SourceID: "ru-act-002", Text: "выключи свет в спальне", Route: RouteAction},
|
||||
{SourceID: "ru-act-001", Text: "перезапусти докер", Route: RouteAction},
|
||||
}
|
||||
pairs := GenerateContrastivePairs(bases)
|
||||
if len(pairs) == 0 {
|
||||
t.Fatal("GenerateContrastivePairs returned no pairs")
|
||||
}
|
||||
transformCounts := map[string]int{}
|
||||
for _, p := range pairs {
|
||||
transformCounts[p.Transform]++
|
||||
}
|
||||
for _, tr := range StandardTransforms {
|
||||
if c := transformCounts[tr.Name]; c == 0 {
|
||||
t.Errorf("no pairs for transform %q", tr.Name)
|
||||
}
|
||||
}
|
||||
t.Logf("generated %d contrastive pairs from %d bases", len(pairs), len(bases))
|
||||
}
|
||||
Reference in New Issue
Block a user