2026-11-26 02:53:03 +00:00
package locationoccurrences
import (
"reflect"
"strings"
"testing"
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
)
func TestCollapseDuplicatesPreservesIndependentEvidenceAndOriginalIndices ( t * testing . T ) {
doc := & source . SourceDocument { ID : "session" , Units : [ ] source . SourceUnit { { ID : 10 } , { ID : 20 } } }
ref := func ( id int ) source . SourceRef {
return source . SourceRef { SourceID : doc . ID , StartUnitID : id , EndUnitID : id }
}
a := dnd . LocationOccurrence { LocationID : "place" , Name : "Inn" , Kind : dnd . LocationOccurrenceKindMentioned , SourceRefs : [ ] source . SourceRef { ref ( 10 ) } }
b := dnd . LocationOccurrence { LocationID : "place" , Name : "Inn" , Kind : dnd . LocationOccurrenceKindMentioned , SourceRefs : [ ] source . SourceRef { ref ( 20 ) } }
invalid := dnd . LocationOccurrence { LocationID : "place" , Name : "Inn" , Kind : dnd . LocationOccurrenceKindMentioned , SourceRefs : [ ] source . SourceRef { ref ( 999 ) } }
2026-11-26 02:56:43 +00:00
records := [ ] normalizedRecord { { occurrence : a , inputIndex : 10 } , { occurrence : b , inputIndex : 20 } , { occurrence : invalid , inputIndex : 30 } , { occurrence : b , inputIndex : 40 } , { occurrence : invalid , inputIndex : 50 } , { occurrence : a , inputIndex : 60 } }
2026-11-26 02:53:03 +00:00
output , findings := collapseDuplicates ( records , source . NewDocumentIndex ( doc ) )
if want := [ ] dnd . LocationOccurrence { a , b , invalid , invalid } ; ! reflect . DeepEqual ( output , want ) {
t . Fatalf ( "output = %#v, want %#v" , output , want )
}
if len ( findings ) != 2 || ! strings . Contains ( findings [ 0 ] . Message , "retained input index 10" ) || ! strings . Contains ( findings [ 0 ] . Message , "removed input index 60" ) || ! strings . Contains ( findings [ 1 ] . Message , "retained input index 20" ) || ! strings . Contains ( findings [ 1 ] . Message , "removed input index 40" ) {
t . Fatalf ( "findings = %#v" , findings )
}
2026-11-26 02:56:43 +00:00
_ , reversed := collapseDuplicates ( [ ] normalizedRecord { { occurrence : b , inputIndex : 20 } , { occurrence : a , inputIndex : 10 } , { occurrence : a , inputIndex : 60 } , { occurrence : b , inputIndex : 40 } } , source . NewDocumentIndex ( doc ) )
2026-11-26 02:53:03 +00:00
if len ( reversed ) != 2 || ! strings . Contains ( reversed [ 0 ] . Message , "retained input index 20" ) || ! strings . Contains ( reversed [ 1 ] . Message , "retained input index 10" ) {
t . Fatalf ( "permuted findings = %#v" , reversed )
}
output [ 0 ] . SourceRefs [ 0 ] . StartUnitID = 20
if records [ 0 ] . occurrence . SourceRefs [ 0 ] . StartUnitID != 10 {
t . Fatal ( "output aliases input evidence" )
}
}