- remove the events/outages module, ArcGIS adapter, portal config and event statuses - add a configurable city dictionary/parser and make City part of StreetKey - seed: read city/city_name, namespace IDs by city, keep structures distinct - fix reliability: schema v2 with fail-closed load, deterministic ordering, input limits, config validation, atomic DB publish, LLM response caps - add read-only shadow mode comparing the old ES path with addrkit - breaking: registry.db must be re-seeded; config has no portal section
73 lines
2.6 KiB
Go
73 lines
2.6 KiB
Go
package match
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.totmin.ru/en2zmax/addrkit/internal/domain/address"
|
|
)
|
|
|
|
// TestCompatibleVariant encodes the safety contract for LLM rewrites: only a
|
|
// spelling fix of the same street, with the same ordinal and house unit, may be
|
|
// considered.
|
|
func TestCompatibleVariant(t *testing.T) {
|
|
orig := address.Parse("2-я Сухарная улица 95")
|
|
tests := []struct {
|
|
name string
|
|
variant string
|
|
want bool
|
|
}{
|
|
{"spelling fix (transposition)", "2-я Сухраная улица 95", true},
|
|
{"reordered words", "Сухарная 2-я улица 95", true},
|
|
{"ordinal dropped", "Сухарная улица 95", false},
|
|
{"different street", "Королева улица 95", false},
|
|
{"house changed", "2-я Сухарная улица 96", false},
|
|
{"building added", "2-я Сухарная улица 95 к1", false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := compatibleVariant(orig, address.Parse(tt.variant))
|
|
if got != tt.want {
|
|
t.Errorf("compatibleVariant(%q) = %v, want %v", tt.variant, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestCompatibleVariantProtectsApartment ensures "кв 5" is not folded into a
|
|
// corpus "к5" by the model.
|
|
func TestCompatibleVariantProtectsApartment(t *testing.T) {
|
|
orig := address.Parse("ул. Елоховская, д. 43 кв. 5")
|
|
if compatibleVariant(orig, address.Parse("ул. Елоховская 43 к5")) {
|
|
t.Fatal("apartment must not be rewritten as a corpus")
|
|
}
|
|
}
|
|
|
|
// TestCompatibleVariantProtectsCityAndStructure makes sure a rewrite cannot
|
|
// move the address to another city or another building.
|
|
func TestCompatibleVariantProtectsCityAndStructure(t *testing.T) {
|
|
parser := address.NewParser(address.NewDictionary([]address.City{
|
|
{Name: "Новосибирск", Aliases: []string{"нск"}},
|
|
{Name: "Бердск"},
|
|
}), "")
|
|
orig := parser.Parse("нск, Сухарная улица 95 стр. 1")
|
|
|
|
if !compatibleVariant(orig, parser.Parse("Новосибирск, Сухраная улица 95 стр. 1")) {
|
|
t.Error("same-city spelling fix must be accepted")
|
|
}
|
|
if compatibleVariant(orig, parser.Parse("Бердск, Сухарная улица 95 стр. 1")) {
|
|
t.Error("city change must be rejected")
|
|
}
|
|
if compatibleVariant(orig, parser.Parse("нск, Сухарная улица 95 стр. 2")) {
|
|
t.Error("structure change must be rejected")
|
|
}
|
|
}
|
|
|
|
func TestDamerau(t *testing.T) {
|
|
if got := damerau("гоглоя", "гоголя"); got != 1 {
|
|
t.Errorf("transposition distance = %d, want 1", got)
|
|
}
|
|
if got := damerau("сееврный", "северная"); got < 2 {
|
|
t.Errorf("expected a larger distance for a different word, got %d", got)
|
|
}
|
|
}
|