package controllers import "testing" func TestIsHyperlocal(t *testing.T) { cases := []struct { name string pickup string delivery string want bool }{ { name: "same coimbatore postal area routes hyperlocal", pickup: "641012", // Gandhipuram delivery: "641004", // Peelamedu want: true, }, { name: "identical pincode routes hyperlocal", pickup: "641012", delivery: "641012", want: true, }, { name: "coimbatore to chennai is not hyperlocal", pickup: "641012", delivery: "600001", want: false, }, { name: "adjacent prefixes are not hyperlocal", pickup: "641012", delivery: "642012", want: false, }, { // Bad data must fall back to the hub route rather than sending a // cross-city parcel out for local delivery. name: "short pickup pincode is not hyperlocal", pickup: "64", delivery: "641012", want: false, }, { name: "short delivery pincode is not hyperlocal", pickup: "641012", delivery: "64", want: false, }, { name: "empty pincodes are not hyperlocal", pickup: "", delivery: "", want: false, }, { name: "exactly three digits is enough to match", pickup: "641", delivery: "641999", want: true, }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { if got := isHyperlocal(tc.pickup, tc.delivery); got != tc.want { t.Errorf("isHyperlocal(%q, %q) = %v, want %v", tc.pickup, tc.delivery, got, tc.want) } }) } } func TestCalculateVolumetricWeight(t *testing.T) { cases := []struct { name string l, w, h float64 want float64 }{ {name: "zero dimensions weigh nothing", l: 0, w: 0, h: 0, want: 0}, {name: "standard divisor of 5000", l: 50, w: 40, h: 30, want: 12}, {name: "one centimetre cube", l: 1, w: 1, h: 1, want: 1.0 / 5000.0}, {name: "large parcel", l: 100, w: 100, h: 100, want: 200}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { got := calculateVolumetricWeight(tc.l, tc.w, tc.h) if got != tc.want { t.Errorf("calculateVolumetricWeight(%v, %v, %v) = %v, want %v", tc.l, tc.w, tc.h, got, tc.want) } }) } }