Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

42 Zeilen
1023 B

  1. package location
  2. import (
  3. "testing"
  4. "github.com/AFASystems/presence/internal/pkg/common/utils"
  5. "github.com/AFASystems/presence/internal/pkg/model"
  6. )
  7. // Test location algorithm scoring formula: seenW + (rssiW * (1.0 - (rssi / -100.0)))
  8. func TestLocationScoringFormula(t *testing.T) {
  9. seenW := 1.5
  10. rssiW := 0.75
  11. tests := []struct {
  12. rssi int64
  13. wantMin float64
  14. wantMax float64
  15. }{
  16. {-50, 1.85, 1.9}, // 1.5 + 0.75*0.5 = 1.875
  17. {-100, 1.45, 1.55}, // 1.5 + 0.75*0 = 1.5
  18. {-80, 1.6, 1.7}, // 1.5 + 0.75*0.2 = 1.65
  19. }
  20. for _, tt := range tests {
  21. score := seenW + (rssiW * (1.0 - (float64(tt.rssi) / -100.0)))
  22. if score < tt.wantMin || score > tt.wantMax {
  23. t.Errorf("RSSI %d: score %f outside expected [%f, %f]", tt.rssi, score, tt.wantMin, tt.wantMax)
  24. }
  25. }
  26. }
  27. func TestCalculateDistance_ForLocation(t *testing.T) {
  28. adv := model.BeaconAdvertisement{
  29. RSSI: -65,
  30. TXPower: "C5",
  31. }
  32. d := utils.CalculateDistance(adv)
  33. if d < 0 {
  34. t.Errorf("Distance should be non-negative, got %f", d)
  35. }
  36. }