package location import ( "testing" "github.com/AFASystems/presence/internal/pkg/common/utils" "github.com/AFASystems/presence/internal/pkg/model" ) // Test location algorithm scoring formula: seenW + (rssiW * (1.0 - (rssi / -100.0))) func TestLocationScoringFormula(t *testing.T) { seenW := 1.5 rssiW := 0.75 tests := []struct { rssi int64 wantMin float64 wantMax float64 }{ {-50, 1.85, 1.9}, // 1.5 + 0.75*0.5 = 1.875 {-100, 1.45, 1.55}, // 1.5 + 0.75*0 = 1.5 {-80, 1.6, 1.7}, // 1.5 + 0.75*0.2 = 1.65 } for _, tt := range tests { score := seenW + (rssiW * (1.0 - (float64(tt.rssi) / -100.0))) if score < tt.wantMin || score > tt.wantMax { t.Errorf("RSSI %d: score %f outside expected [%f, %f]", tt.rssi, score, tt.wantMin, tt.wantMax) } } } func TestCalculateDistance_ForLocation(t *testing.T) { adv := model.BeaconAdvertisement{ RSSI: -65, TXPower: "C5", } d := utils.CalculateDistance(adv) if d < 0 { t.Errorf("Distance should be non-negative, got %f", d) } }