32 lines
1.5 KiB
Go
32 lines
1.5 KiB
Go
package pipeline
|
||
|
||
import "testing"
|
||
|
||
// TestSegmentLoopRuns pins the pack-13 point-10 degenerate-loop guard: a run of ≥3 identical consecutive
|
||
// (whitespace-normalized) segments is a loop; distinct prose is not; empty exports break a run and never
|
||
// count (a pending/flagged unit exports "").
|
||
func TestSegmentLoopRuns(t *testing.T) {
|
||
cases := []struct {
|
||
name string
|
||
segs []string
|
||
wantRuns int
|
||
}{
|
||
{"healthy prose", []string{"Абзац один.", "Абзац два.", "Абзац три.", "Абзац четыре."}, 0},
|
||
{"loop of 3", []string{"уникальный", "ПОВТОР", "ПОВТОР", "ПОВТОР", "конец"}, 1},
|
||
{"loop of 2 below threshold", []string{"a", "ПОВТОР", "ПОВТОР", "b"}, 0},
|
||
{"whitespace-insensitive loop", []string{"один два", "один два", "один\tдва", "один два"}, 1},
|
||
{"empty breaks the run", []string{"ПОВТОР", "ПОВТОР", "", "ПОВТОР", "ПОВТОР"}, 0},
|
||
{"empties never loop", []string{"", "", "", "", ""}, 0},
|
||
{"two separate loops", []string{"A", "A", "A", "x", "B", "B", "B"}, 2},
|
||
}
|
||
for _, c := range cases {
|
||
if got := len(segmentLoopRuns(c.segs, segmentLoopMinRun)); got != c.wantRuns {
|
||
t.Errorf("%s: segmentLoopRuns = %d runs, want %d", c.name, got, c.wantRuns)
|
||
}
|
||
}
|
||
// The run carries the correct start + count.
|
||
runs := segmentLoopRuns([]string{"a", "R", "R", "R", "R"}, 3)
|
||
if len(runs) != 1 || runs[0].Start != 1 || runs[0].Count != 4 {
|
||
t.Errorf("run metadata wrong: %+v", runs)
|
||
}
|
||
}
|