1package jev23import (4 "testing"56 "src.rest/cat/012/internal/sheet"7)89// Every call must get its own key, and equal calls the same one, map10// order notwithstanding.11func TestKeysAreDistinct(t *testing.T) {12 calls := []sheet.RemoteCall{13 {Kind: "noul", State: "The box was crushed", Instructions: "Is this a complaint?"},14 {Kind: "noul", State: "The box was crushed", Instructions: "Is this a complaint?", Criteria: [2]string{"yes", ""}},15 {Kind: "noul", State: "The box was crushed", Instructions: "Is this a complaint?", Criteria: [2]string{"", "yes"}},16 {Kind: "noul", State: "The box was crushed ", Instructions: "Is this a complaint?"},17 {Kind: "noul", State: "The box", Instructions: " was crushedIs this a complaint?"},18 {Kind: "noul", State: 12.0, Instructions: "q"},19 {Kind: "noul", State: "12", Instructions: "q"},20 {Kind: "noul", State: true, Instructions: "q"},21 {Kind: "noul", State: "", Instructions: "q"},22 {Kind: "noul", State: nil, Instructions: "q"},23 {Kind: "noul", State: [][]any{{"a", 1.0}, {"b", 2.0}}, Instructions: "q"},24 {Kind: "noul", State: [][]any{{"a", 1.0, "b", 2.0}}, Instructions: "q"},25 {Kind: "choice", State: "x", Instructions: "q", Criteria: map[string]string{"neg": "bad", "pos": "good"}},26 {Kind: "choice", State: "x", Instructions: "q", Criteria: map[string]string{"neg": "good", "pos": "bad"}},27 {Kind: "score", State: "x", Instructions: "q", Criteria: []string{"low", "mid", "high"}},28 {Kind: "score", State: "x", Instructions: "q", Criteria: []string{"low", "midhigh"}},29 {Kind: "score", State: "x", Instructions: "q", Criteria: []int{1, 2}}, // JSON fallback30 }31 seen := map[string]int{}32 for i, c := range calls {33 k := Key(c)34 if j, dup := seen[k]; dup {35 t.Errorf("calls %d and %d share key %q", j, i, k)36 }37 seen[k] = i38 }39 m := map[string]string{}40 for _, l := range []string{"a", "b", "c", "d", "e", "f"} {41 m[l] = l + "!"42 }43 c := sheet.RemoteCall{Kind: "choice", State: "x", Instructions: "q", Criteria: m}44 want := Key(c)45 for range 20 {46 if got := Key(c); got != want {47 t.Fatal("map order changed the key")48 }49 }50}5152func BenchmarkKey(b *testing.B) {53 c := sheet.RemoteCall{Kind: "choice", State: "The box was crushed", Instructions: "Sentiment",54 Criteria: map[string]string{"negative": "negative", "positive": "positive"}}55 for b.Loop() {56 Key(c)57 }58}