test(agent): the orientation matrix iterated maps, so its 36 cells shuffled
Caught on the sibling mort PR (gadfly/sonnet) and the same mistake was
here: map iteration is randomised, so the matrix printed its cells in a
different order every run and two failing runs could not be diffed. The
"which placements are bare" lookup was a second map keyed by name, which
also let a placement and its expectation drift apart by a typo.
Both are now one slice of {name, bare, build}, so the expectation sits
on the row it belongs to and the order is fixed.
This commit is contained in:
+36
-34
@@ -161,50 +161,52 @@ func TestPointsAbove(t *testing.T) {
|
||||
//
|
||||
// The rule under test is a single line: bare IFF there is no content.
|
||||
func TestBareAbovePointerOrientations(t *testing.T) {
|
||||
// Each pointer form, written so it reads naturally both as a whole
|
||||
// Slices, not maps: map iteration is randomised, so the 36 cells would
|
||||
// print in a different order every run and two failing runs could not be
|
||||
// diffed against each other.
|
||||
//
|
||||
// Each pointer form is written so it reads naturally both as a whole
|
||||
// sentence and as a trailing clause.
|
||||
pointers := map[string]struct{ sentence, clause string }{
|
||||
"demonstrative": {"That's the chain above.", "as shown above"},
|
||||
"imperative": {"See the note above.", "per the note above"},
|
||||
"copular": {"The breakdown is above.", "which is above"},
|
||||
type pointerForm struct{ name, sentence, clause string }
|
||||
pointers := []pointerForm{
|
||||
{"demonstrative", "That's the chain above.", "as shown above"},
|
||||
{"imperative", "See the note above.", "per the note above"},
|
||||
{"copular", "The breakdown is above.", "which is above"},
|
||||
}
|
||||
// Where the answer can sit relative to the pointer. "" = nowhere: the
|
||||
// pointer is alone, which is the only bare case.
|
||||
const answer = "Ship Tuesday"
|
||||
placements := map[string]func(p struct{ sentence, clause string }) string{
|
||||
"alone": func(p struct{ sentence, clause string }) string { return p.sentence },
|
||||
"alone as a clause": func(p struct{ sentence, clause string }) string { return p.clause },
|
||||
"before, same sentence": func(p struct{ sentence, clause string }) string { return answer + ", " + p.clause + "." },
|
||||
"before, own sentence": func(p struct{ sentence, clause string }) string { return answer + ". " + p.sentence },
|
||||
"before, own line": func(p struct{ sentence, clause string }) string { return answer + "\n" + p.sentence },
|
||||
"before, list item": func(p struct{ sentence, clause string }) string { return "- " + answer + "\n- " + p.sentence },
|
||||
"after, same sentence": func(p struct{ sentence, clause string }) string { return p.clause + ", " + answer + "." },
|
||||
"after, own sentence": func(p struct{ sentence, clause string }) string { return p.sentence + " " + answer + "." },
|
||||
"after, own line": func(p struct{ sentence, clause string }) string { return p.sentence + "\n" + answer + "." },
|
||||
"after a filler opener": func(p struct{ sentence, clause string }) string { return "OK. " + answer + ", " + p.clause + "." },
|
||||
"filler then pointer": func(p struct{ sentence, clause string }) string { return "OK. " + p.sentence },
|
||||
"done-dash then pointer": func(p struct{ sentence, clause string }) string {
|
||||
return "Done — " + p.clause + "."
|
||||
},
|
||||
}
|
||||
// The only terminals with no answer in them.
|
||||
bare := map[string]bool{
|
||||
"alone": true,
|
||||
"alone as a clause": true,
|
||||
"filler then pointer": true,
|
||||
"done-dash then pointer": true,
|
||||
// bare records whether the built terminal contains NO answer — the only
|
||||
// case the rule may treat as disposable.
|
||||
placements := []struct {
|
||||
name string
|
||||
bare bool
|
||||
build func(p pointerForm) string
|
||||
}{
|
||||
{"alone", true, func(p pointerForm) string { return p.sentence }},
|
||||
{"alone as a clause", true, func(p pointerForm) string { return p.clause }},
|
||||
{"filler then pointer", true, func(p pointerForm) string { return "OK. " + p.sentence }},
|
||||
{"done-dash then pointer", true, func(p pointerForm) string { return "Done — " + p.clause + "." }},
|
||||
|
||||
{"before, same sentence", false, func(p pointerForm) string { return answer + ", " + p.clause + "." }},
|
||||
{"before, own sentence", false, func(p pointerForm) string { return answer + ". " + p.sentence }},
|
||||
{"before, own line", false, func(p pointerForm) string { return answer + "\n" + p.sentence }},
|
||||
{"before, list item", false, func(p pointerForm) string { return "- " + answer + "\n- " + p.sentence }},
|
||||
{"after, same sentence", false, func(p pointerForm) string { return p.clause + ", " + answer + "." }},
|
||||
{"after, own sentence", false, func(p pointerForm) string { return p.sentence + " " + answer + "." }},
|
||||
{"after, own line", false, func(p pointerForm) string { return p.sentence + "\n" + answer + "." }},
|
||||
{"after a filler opener", false, func(p pointerForm) string { return "OK. " + answer + ", " + p.clause + "." }},
|
||||
}
|
||||
|
||||
for pname, p := range pointers {
|
||||
for placement, build := range placements {
|
||||
t.Run(pname+"/"+placement, func(t *testing.T) {
|
||||
in := build(p)
|
||||
for _, p := range pointers {
|
||||
for _, pl := range placements {
|
||||
t.Run(p.name+"/"+pl.name, func(t *testing.T) {
|
||||
in := pl.build(p)
|
||||
if !pointsAbove(in) {
|
||||
t.Fatalf("setup is not a pointer at all, so the case proves nothing: %q", in)
|
||||
}
|
||||
want := bare[placement]
|
||||
if got := bareAbovePointer(in); got != want {
|
||||
t.Errorf("bareAbovePointer(%q) = %v, want %v", in, got, want)
|
||||
if got := bareAbovePointer(in); got != pl.bare {
|
||||
t.Errorf("bareAbovePointer(%q) = %v, want %v", in, got, pl.bare)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user