fix
This commit is contained in:
1 parent
7537a41955
commit
ff6c2df618
14 files changed
+767
-349
No files matched your search
@@ -37,3 +37,90 @@ Napiši ime v slovenščini
|
||||
t.Fatal("cleanup not idempotent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDedupeA1RealRepeatingTemplate(t *testing.T) {
|
||||
headingA := `<H2>{Napiši Novo ime izdelka brez barve in izpostavi en benefit}</H2>`
|
||||
headingB := `<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>`
|
||||
paragraphA := `<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>`
|
||||
paragraphB := `<p>{Napiši odstavek, ki je dolg 100 besed in VKLJUČI tudi Novo ime izdelka.}</p>`
|
||||
original := headingA + "\n" + paragraphA + "\n" + headingB + "\n" + paragraphB + "\n" +
|
||||
headingA + "\n" + paragraphA + "\n" + headingB + "\n" + paragraphB + "\n" +
|
||||
headingB + "\n" + paragraphA + `<b>{Tehnične specifikacije}</b><ul><li>{Napiši 3-10 tehničnih specifikacij v alinejah}</li></ul>`
|
||||
cleaned, removed := DedupeA1DescriptionBlocks(original)
|
||||
if removed != 2 {
|
||||
t.Fatalf("expected 2 duplicate pairs, got %d", removed)
|
||||
}
|
||||
if strings.Count(cleaned, "<H2>") != 3 {
|
||||
t.Fatalf("expected 3 distinct pairs: %s", cleaned)
|
||||
}
|
||||
if !strings.Contains(cleaned, "Tehnične specifikacije") {
|
||||
t.Fatal("lost specs")
|
||||
}
|
||||
twice, removedAgain := DedupeA1DescriptionBlocks(cleaned)
|
||||
if removedAgain != 0 || twice != cleaned {
|
||||
t.Fatal("A1 cleanup must be idempotent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDedupeStructuredA1Descriptions(t *testing.T) {
|
||||
raw := `{"sections":[{"type":"h2","instructions":"A"},{"type":"p","instructions":"X"},{"type":"h2","instructions":"B"},{"type":"p","instructions":"Y"},{"type":"h2","instructions":"A"},{"type":"p","instructions":"X"},{"type":"ul","instructions":"Specifications"}],"metaDescription":"140 znakov"}`
|
||||
cleaned, removed, err := DedupeA1DescriptionTemplate(raw)
|
||||
if err != nil || removed != 1 {
|
||||
t.Fatalf("removed=%d err=%v", removed, err)
|
||||
}
|
||||
if strings.Count(cleaned, `"type":"h2"`) != 2 || !strings.Contains(cleaned, `140 znakov`) || !strings.Contains(cleaned, `Specifications`) {
|
||||
t.Fatalf("invalid result: %s", cleaned)
|
||||
}
|
||||
again, n, err := DedupeA1DescriptionTemplate(cleaned)
|
||||
if n != 0 || err != nil || again != cleaned {
|
||||
t.Fatal("structured cleanup not idempotent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeA1RepeatedBenefitsKeepsFiveDistinctSections(t *testing.T) {
|
||||
source := `<H2>{Napiši Novo ime izdelka brez barve in izpostavi en benefit}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>
|
||||
<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed in VKLJUČI tudi Novo ime izdelka.}</p>
|
||||
<H2>{Napiši Novo ime izdelka brez barve in izpostavi en benefit}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>
|
||||
<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed in VKLJUČI tudi Novo ime izdelka.}</p>
|
||||
<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p><b>{Tehnične specifikacije}</b><ul><li>{Napiši 3-10 tehničnih specifikacij v alinejah}</li></ul>`
|
||||
result, rewritten := NormalizeA1RepeatedBenefits(source)
|
||||
if rewritten != 3 {
|
||||
t.Fatalf("rewritten=%d want 3", rewritten)
|
||||
}
|
||||
if strings.Count(result, "<H2>") != 5 || strings.Count(result, "<p>") != 5 {
|
||||
t.Fatalf("lost section: %s", result)
|
||||
}
|
||||
if !strings.Contains(result, "3. drugačno") || !strings.Contains(result, "4. drugačno") || !strings.Contains(result, "5. drugačno") {
|
||||
t.Fatalf("not distinct: %s", result)
|
||||
}
|
||||
if strings.Count(result, "VKLJUČI") != 1 || strings.Count(result, "vključi naravno natanko enkrat") != 1 {
|
||||
t.Fatalf("failed inclusion preservation: %s", result)
|
||||
}
|
||||
if !strings.Contains(result, "Tehnične specifikacije") {
|
||||
t.Fatal("lost technical specifications")
|
||||
}
|
||||
again, n := NormalizeA1RepeatedBenefits(result)
|
||||
if n != 0 || again != result {
|
||||
t.Fatalf("not idempotent: %d %s", n, again)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeA1StructuredKeepsSections(t *testing.T) {
|
||||
source := `{"sections":[{"type":"h2","instructions":"Benefit A"},{"type":"p","instructions":"NE vsebuje Novo ime izdelka"},{"type":"h2","instructions":"Benefit B"},{"type":"p","instructions":"VKLJUČI Novo ime izdelka"},{"type":"h2","instructions":"Benefit A"},{"type":"p","instructions":"NE vsebuje Novo ime izdelka"}],"metaDescription":"140 znakov"}`
|
||||
result, changed, err := NormalizeA1DescriptionTemplate(source)
|
||||
if err != nil || changed != 1 {
|
||||
t.Fatalf("changed=%d err=%v", changed, err)
|
||||
}
|
||||
if strings.Count(result, `"type":"h2"`) != 3 || !strings.Contains(result, "3. drugačno") || !strings.Contains(result, "140 znakov") {
|
||||
t.Fatalf("invalid: %s", result)
|
||||
}
|
||||
again, n, err := NormalizeA1DescriptionTemplate(result)
|
||||
if n != 0 || err != nil || again != result {
|
||||
t.Fatal("not idempotent")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user