textmachine/backend/internal/membank/termgaps_test.go

46 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package membank
import (
"strings"
"testing"
"textmachine/backend/internal/store"
)
// TestTermWindowGapsSeesTheHoleTheLoaderCannot pins backlog row 490: the loader refuses two rows that
// OVERLAP and says nothing about two that leave a chapter between them.
func TestTermWindowGapsSeesTheHoleTheLoaderCannot(t *testing.T) {
rows := []store.GlossaryEntry{
// THE HOLE: chapter 4 belongs to neither window.
{Src: "古月", Dst: "Гуюэ", SinceCh: 1, UntilCh: 3, Status: "approved"},
{Src: "古月", Dst: "клан Гу Юэ", SinceCh: 5, UntilCh: 0, Status: "approved"},
// CONTIGUOUS: a handover, not a hole — the commonest legitimate shape and the one a noisy check
// would report on every spoiler boundary in the book.
{Src: "方源", Dst: "Фан Юань", SinceCh: 1, UntilCh: 10, Status: "approved"},
{Src: "方源", Dst: "Демон", SinceCh: 11, UntilCh: 0, Status: "approved"},
// ONE ROW, open-ended: nothing to compare.
{Src: "元石", Dst: "юаньши", SinceCh: 0, UntilCh: 0, Status: "draft"},
// TWO SENSES of one surface: two laws by design (the A3 disambiguator is part of the uniqueness
// key), so their windows must NOT be measured against each other.
{Src: "青茅", Sense: "гора", Dst: "Цинмао", SinceCh: 1, UntilCh: 3, Status: "approved"},
{Src: "青茅", Sense: "трава", Dst: "синяя осока", SinceCh: 40, UntilCh: 0, Status: "approved"},
}
got := TermWindowGaps(rows)
if len(got) != 1 {
t.Fatalf("reported %d gap(s), want exactly the one real hole: %v", len(got), got)
}
for _, want := range []string{`"古月"`, "chapters 44", "window ends at 3", "next starts at 5"} {
if !strings.Contains(got[0], want) {
t.Errorf("the message must name the chapters the owner has to look at; %q is missing from:\n %s", want, got[0])
}
}
// The control that makes the «exactly one» readable: this function can see MORE than one, so the count
// above is a measurement of the fixture rather than a ceiling of the function.
wider := append([]store.GlossaryEntry(nil), rows...)
wider = append(wider,
store.GlossaryEntry{Src: "蛊师", Dst: "гу-мастер", SinceCh: 1, UntilCh: 2, Status: "approved"},
store.GlossaryEntry{Src: "蛊师", Dst: "мастер Гу", SinceCh: 9, UntilCh: 0, Status: "approved"})
if n := len(TermWindowGaps(wider)); n != 2 {
t.Fatalf("control: a second genuine hole produced %d report(s), want 2 — the function reports at most one and the assertion above measured that, not the data", n)
}
}