package staffing import ( "testing" "github.com/shopspring/decimal" ) func dec(s string) decimal.Decimal { return decimal.RequireFromString(s) } func TestPriorityMultiplier(t *testing.T) { ref := decimal.NewFromInt(5_000_000) minM := decimal.NewFromInt(1) maxM := decimal.NewFromInt(3) cases := []struct { name string value decimal.Decimal want string }{ {"zero value is minimum", decimal.Zero, "1"}, {"negative value clamps to minimum", decimal.NewFromInt(-100), "1"}, {"reference value is midpoint", decimal.NewFromInt(5_000_000), "2"}, {"double reference hits the cap", decimal.NewFromInt(10_000_000), "3"}, {"far above reference stays capped", decimal.NewFromInt(50_000_000), "3"}, {"half reference is 1.5", decimal.NewFromInt(2_500_000), "1.5"}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { got := PriorityMultiplier(c.value, ref, minM, maxM) if !got.Equal(dec(c.want)) { t.Fatalf("PriorityMultiplier(%s) = %s, want %s", c.value, got, c.want) } }) } } func TestPriorityMultiplierNonPositiveReferenceDisablesWeighting(t *testing.T) { got := PriorityMultiplier(decimal.NewFromInt(9_000_000), decimal.Zero, decimal.NewFromInt(1), decimal.NewFromInt(3)) if !got.Equal(decimal.NewFromInt(1)) { t.Fatalf("a non positive reference must return the minimum multiplier, got %s", got) } } func TestScaledValueKnown(t *testing.T) { // total 90, multiplier 2, scale 1e6 -> 180,000,000 got := ScaledValue(decimal.NewFromInt(90), decimal.NewFromInt(2), 1_000_000) if got != 180_000_000 { t.Fatalf("ScaledValue = %d, want 180000000", got) } } func TestScaledValueDeterministicRounding(t *testing.T) { // 0.0000005 * 1 * 1e6 = 0.5, shopspring rounds half away from zero -> 1. got := ScaledValue(dec("0.0000005"), decimal.NewFromInt(1), 1_000_000) if got != 1 { t.Fatalf("half away from zero rounding expected 1, got %d", got) } // Stability: the same input always yields the same integer. a := ScaledValue(dec("87.6543"), dec("1.7"), 1_000_000) b := ScaledValue(dec("87.6543"), dec("1.7"), 1_000_000) if a != b { t.Fatalf("ScaledValue is not deterministic: %d vs %d", a, b) } } func TestScaledValueZeroFitIsZero(t *testing.T) { if got := ScaledValue(decimal.Zero, decimal.NewFromInt(3), 1_000_000); got != 0 { t.Fatalf("zero fit must be zero value, got %d", got) } }