feat(html): canonicalize compare variant keys
This commit is contained in:
parent
e95c059412
commit
dd68c6d0d7
2 changed files with 22 additions and 1 deletions
|
|
@ -141,7 +141,12 @@ func CompareVariants(r *Responsive, ctx *Context) map[string]float64 {
|
|||
scores := make(map[string]float64)
|
||||
for i := range len(imprints) {
|
||||
for j := i + 1; j < len(imprints); j++ {
|
||||
key := imprints[i].name + ":" + imprints[j].name
|
||||
left := imprints[i].name
|
||||
right := imprints[j].name
|
||||
if right < left {
|
||||
left, right = right, left
|
||||
}
|
||||
key := left + ":" + right
|
||||
scores[key] = imprints[i].imp.Similar(imprints[j].imp)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,3 +172,19 @@ func TestCompareVariants_SameContent_Good(t *testing.T) {
|
|||
t.Errorf("same content in different variants should score >= 0.8, got %f", sim)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareVariants_KeyOrderDeterministic_Good(t *testing.T) {
|
||||
svc, _ := i18n.New()
|
||||
i18n.SetDefault(svc)
|
||||
ctx := NewContext()
|
||||
|
||||
r := NewResponsive().
|
||||
Variant("beta", NewLayout("C").C(El("p", Text("Building project")))).
|
||||
Variant("alpha", NewLayout("C").C(El("p", Text("Building project"))))
|
||||
|
||||
scores := CompareVariants(r, ctx)
|
||||
|
||||
if _, ok := scores["alpha:beta"]; !ok {
|
||||
t.Fatalf("CompareVariants should use deterministic key ordering, got keys: %v", scores)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue