updates on the order bulk fix

This commit is contained in:
2026-10-06 17:29:07 +05:30
parent efad4d3d12
commit 7ff9dad288
12 changed files with 1029 additions and 48 deletions

View File

@@ -0,0 +1,48 @@
package assignment
import (
"math"
"testing"
"github.com/redis/go-redis/v9"
)
func TestAcceptTimeout(t *testing.T) {
cases := map[string]int{
"": defaultAcceptTimeoutMinutes,
"0": 0, // off
"5": 5,
"-1": defaultAcceptTimeoutMinutes,
"soon": defaultAcceptTimeoutMinutes, // a typo must not switch it off
}
for env, want := range cases {
t.Setenv("ASSIGNMENT_ACCEPT_TIMEOUT_MINUTES", env)
if got := acceptTimeout(); got != want {
t.Errorf("ASSIGNMENT_ACCEPT_TIMEOUT_MINUTES=%q: %d, want %d", env, got, want)
}
}
}
func TestWithoutRiders(t *testing.T) {
nearby := []redis.GeoLocation{{Name: "1"}, {Name: "2"}, {Name: "3"}, {Name: "x"}}
got := withoutRiders(nearby, map[int]bool{2: true})
if len(got) != 3 || got[0].Name != "1" || got[1].Name != "3" || got[2].Name != "x" {
t.Fatalf("got %v", got)
}
if len(nearby) != 4 || nearby[1].Name != "2" {
t.Fatal("the input slice must not be modified")
}
if got := withoutRiders(nearby, nil); len(got) != 4 {
t.Fatal("nothing to skip, nothing removed")
}
}
func TestDistanceKm(t *testing.T) {
// RS Puram to Gandhipuram, Coimbatore: about 2.2 km.
if d := distanceKm(11.0090, 76.9500, 11.0182714, 76.9677744); math.Abs(d-2.17) > 0.2 {
t.Fatalf("distance = %.2f km", d)
}
if d := distanceKm(11, 77, 11, 77); d != 0 {
t.Fatalf("same point = %v", d)
}
}