fix(assessment): require the leak to agree with a statement before its landmark
This commit is contained in:
1 parent
754c745fba
commit
3de226b16c
3 files changed
+95
-6
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode"
|
||||
@@ -262,6 +263,43 @@ func TestAlignmentIsLongestForTheVariantThatWasLeakedAndShorterForOtherVariants(
|
||||
}
|
||||
}
|
||||
|
||||
// dependencyOrderStatement is a family whose first interchangeable phrase comes
|
||||
// after the size of the task, so the piece before it differs between variants and
|
||||
// the closing sentence is the only text that every variant shares.
|
||||
func dependencyOrderStatement(jobs int, dependencies string) string {
|
||||
return fmt.Sprintf("A worker runs %[1]d jobs numbered from 1 to %[1]d, one at a time. A dependency A->B means job A must finish before job B starts. "+
|
||||
"The dependencies are: %[2]s. The dependencies contain no cycle, so at least one valid order exists. "+
|
||||
"Among all execution orders that respect every dependency, choose the one that is smallest when compared number by number from the first position. "+
|
||||
"Write that order as job numbers separated by single spaces.", jobs, dependencies)
|
||||
}
|
||||
|
||||
func TestAlignmentDoesNotTakeASharedClosingSentenceForACopyOfAnotherVariant(t *testing.T) {
|
||||
leaked, other := dependencyOrderStatement(9, "7->2 9->4 2->9 6->2"), dependencyOrderStatement(5, "3->4 2->5 2->4 2->1 1->4")
|
||||
leak := "Posted in the group chat: " + VisibleAssessmentText(testWatermark(t, 1).Mark(leaked)) + " please help"
|
||||
|
||||
// The closing sentence is long enough to be a landmark and occurs in both
|
||||
// variants, but the leak differs from the other variant before it.
|
||||
if got := AssessmentLeakAlignment(other, leak); got.Follows() || got.Runes != 0 {
|
||||
t.Fatalf("another variant aligned %+v, want nothing: the text before the shared closing sentence differs", got)
|
||||
}
|
||||
if got := AssessmentLeakAlignment(leaked, leak); !got.Complete || !got.Follows() {
|
||||
t.Fatalf("the leaked variant aligned %+v, want it followed to its end", got)
|
||||
}
|
||||
// A leak that starts inside the statement, at the closing sentence, still
|
||||
// follows it: the part that the leak holds is a copy.
|
||||
visible := VisibleAssessmentText(testWatermark(t, 1).Mark(leaked))
|
||||
closing := strings.Index(visible, " execution orders")
|
||||
if closing < 0 {
|
||||
t.Fatal("the leaked statement has no closing sentence")
|
||||
}
|
||||
tail := visible[strings.LastIndex(visible[:closing], ". ")+len(". "):]
|
||||
for name, statement := range map[string]string{"leaked": leaked, "other": other} {
|
||||
if got := AssessmentLeakAlignment(statement, tail); !got.Complete || !got.Follows() {
|
||||
t.Fatalf("%s variant aligned %+v for a leak of the closing sentence only, want a copy of that part", name, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplittingATextAtItsPhrasesLeavesPiecesThatEveryCopyShares(t *testing.T) {
|
||||
statement := rateLimitVariant(t).Statement
|
||||
// Whatever phrases an attempt picked, the pieces between them are the same.
|
||||
|
||||
Reference in new issue
Block a user