ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Janady13/missionmatch / internal/modules/recruiting/placement_math_test.go

Source identity, revision, and recovered contents.

GitHub sourceSource text recovered

Source identity

FieldRecorded value
Source typeGitHub source
Original recordJanady13/missionmatch / internal/modules/recruiting/placement_math_test.go
DateNot specified in source
RepositoryJanady13/missionmatch
Revision720d47fae476b0d38477ae4401697d372b1ea2bc
Branchfeature/opportunity-to-outcome
Path or archive memberinternal/modules/recruiting/placement_math_test.go
Original SHA-2567be107c107278615384014f0d850dcc84b3180eea948a7228618f174253b7fa2
Git blob SHAdf4e500be2d382fe16e46e3bf393499baebbce90
Reading-copy SHA-2567be107c107278615384014f0d850dcc84b3180eea948a7228618f174253b7fa2

Original source ↗

Recovered source transcript

package recruiting import ( "math/rand" "testing" "time" "github.com/shopspring/decimal" ) func d(s string) *decimal.Decimal { v := decimal.RequireFromString(s); return &v } // TestSpreadIsExactNotFloat. A bill rate is multiplied by hours and by a wrap rate downstream, so a figure // that went through a float64 would not reconcile with an invoice. These are the cases binary floating point // gets wrong. // // THE CASES ARE UNCHANGED AND THE NAME IS NOT. What they always measured was bill minus pay, which is the // SPREAD. The arithmetic was exact and correct the whole time; the word margin on top of it was the defect. func TestSpreadIsExactNotFloat(t *testing.T) { cases := []struct { name, bill, pay, wantSpread, wantPct string }{ {"plain", "150.0000", "100.0000", "50", "33.3333"}, {"tenths that float cannot represent", "0.3000", "0.1000", "0.2", "66.6667"}, {"repeating third", "3.0000", "2.0000", "1", "33.3333"}, {"four decimal rates", "145.7500", "101.2500", "44.5", "30.5317"}, {"equal rates are a zero spread, not an error", "100.0000", "100.0000", "0", "0"}, {"large", "9999.9999", "0.0001", "9999.9998", "100"}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { m := economicsOf("contract", d(c.bill), d(c.pay), nil, nil, nil, nil, nil) if m.SpreadPerHour == nil { t.Fatal("no spread computed") } if !m.SpreadPerHour.Equal(decimal.RequireFromString(c.wantSpread)) { t.Errorf("spread = %s, want %s", m.SpreadPerHour, c.wantSpread) } if m.SpreadPct == nil { t.Fatal("no percentage computed") } if !m.SpreadPct.Equal(decimal.RequireFromString(c.wantPct)) { t.Errorf("pct = %s, want %s", m.SpreadPct, c.wantPct) } }) } } // TestZeroBillRateGivesNoPercentage. A share of nothing is undefined. Returning 0.00 would render as a real // spread of nothing, which is a different and false claim, and dividing would panic. func TestZeroBillRateGivesNoPercentage(t *testing.T) { m := economicsOf("contract", d("0"), d("0"), nil, nil, nil, nil, nil) if m.SpreadPerHour == nil || !m.SpreadPerHour.IsZero() { t.Errorf("spread = %v, want 0", m.SpreadPerHour) } if m.SpreadPct != nil { t.Errorf("pct = %v on a zero bill rate, want absent because the share is undefined", m.SpreadPct) } } // TestSpreadNeedsBothRates. A missing rate is not a zero rate, and treating it as one would report a hundred // percent spread on work whose pay simply has not been entered. func TestSpreadNeedsBothRates(t *testing.T) { for _, c := range []struct{ bill, pay *decimal.Decimal }{ {d("150"), nil}, {nil, d("100")}, {nil, nil}, } { if m := economicsOf("contract", c.bill, c.pay, nil, nil, nil, nil, nil); m.SpreadPerHour != nil { t.Errorf("a spread of %s was computed from bill=%v pay=%v", m.SpreadPerHour, c.bill, c.pay) } } } // TestDirectHireFee. A permanent placement earns a one time fee, never an hourly spread, and the two // shapes must never be blended into one revenue figure. func TestDirectHireFee(t *testing.T) { // An explicit agreed amount wins over the percentage. m := economicsOf("direct_hire", nil, nil, d("150000.00"), d("0.2000"), d("35000.00"), nil, nil) if m.Fee == nil || !m.Fee.Equal(decimal.RequireFromString("35000")) { t.Errorf("fee = %v, want the explicit 35000", m.Fee) } // Otherwise salary times the fraction. 20 percent of 150000 is exactly 30000. m = economicsOf("direct_hire", nil, nil, d("150000.00"), d("0.2000"), nil, nil, nil) if m.Fee == nil || !m.Fee.Equal(decimal.RequireFromString("30000")) { t.Errorf("fee = %v, want 30000", m.Fee) } // A direct hire never reports an hourly spread even if rates were entered by mistake. m = economicsOf("direct_hire", d("150"), d("100"), d("150000"), d("0.2"), nil, nil, nil) if m.SpreadPerHour != nil || m.SpreadPct != nil { t.Error("a direct hire reported an hourly spread, blending two revenue shapes") } // A contract never reports a fee. m = economicsOf("contract", d("150"), d("100"), d("150000"), d("0.2"), d("35000"), nil, nil) if m.Fee != nil { t.Errorf("a contract placement reported a fee of %v", m.Fee) } } // TestSpreadPropertyHoldsForAnyRates. The spread is never negative when bill is at least pay, which the // database enforces, and its percentage never exceeds 100 nor falls below 0. // // NOTE THAT THE MARGIN HAS NO SUCH PROPERTY and must never be given one. Once a wrap is applied the margin // can go negative on rates the database happily accepts, because bill above pay says nothing about bill above // loaded cost. That case is pinned separately in economics_test.go. func TestSpreadPropertyHoldsForAnyRates(t *testing.T) { rng := rand.New(rand.NewSource(20260722)) hundred := decimal.NewFromInt(100) for i := 0; i < 200000; i++ { pay := decimal.NewFromInt(rng.Int63n(2_000_000)).Div(decimal.NewFromInt(10000)) extra := decimal.NewFromInt(rng.Int63n(2_000_000)).Div(decimal.NewFromInt(10000)) bill := pay.Add(extra) m := economicsOf("contract", &bill, &pay, nil, nil, nil, nil, nil) if m.SpreadPerHour == nil { t.Fatalf("no spread for bill=%s pay=%s", bill, pay) } if m.SpreadPerHour.IsNegative() { t.Fatalf("negative spread %s for bill=%s pay=%s", m.SpreadPerHour, bill, pay) } if !m.SpreadPerHour.Equal(bill.Sub(pay)) { t.Fatalf("spread %s is not bill minus pay for %s and %s", m.SpreadPerHour, bill, pay) } if bill.IsZero() { if m.SpreadPct != nil { t.Fatalf("a percentage %s was computed on a zero bill rate", m.SpreadPct) } continue } if m.SpreadPct.IsNegative() || m.SpreadPct.GreaterThan(hundred) { t.Fatalf("pct %s outside [0,100] for bill=%s pay=%s", m.SpreadPct, bill, pay) } } } // TestGuaranteeBoundaryIsInclusive. A 90 day guarantee starting on the 1st covers through day 90. Getting // this off by one either forgives a real breach or claws back a fee that was earned. func TestGuaranteeBoundaryIsInclusive(t *testing.T) { start := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) today := time.Date(2026, 1, 15, 0, 0, 0, 0, time.UTC) g := guaranteeOf(90, start, nil, "active", today) if g.EndsOn != "2026-03-31" { // 1 Jan plus 89 days t.Errorf("a 90 day guarantee from 1 Jan ends on %s, want 2026-03-31", g.EndsOn) } // The last covered day breaches. last := time.Date(2026, 3, 31, 0, 0, 0, 0, time.UTC) if g := guaranteeOf(90, start, &last, "fell_off", today); !g.Breached { t.Error("falling off on the final covered day did not breach") } // The day after does not. after := time.Date(2026, 4, 1, 0, 0, 0, 0, time.UTC) if g := guaranteeOf(90, start, &after, "fell_off", today); g.Breached { t.Error("falling off the day after the guarantee ended was counted as a breach") } // Falling off on day one certainly does. if g := guaranteeOf(90, start, &start, "fell_off", today); !g.Breached { t.Error("falling off on the first day did not breach") } } // TestCompletedAssignmentNeverBreaches. An assignment the client ended on its own terms is not a failure // to deliver, and counting it as one would understate a recruiter's performance for someone else's decision. func TestCompletedAssignmentNeverBreaches(t *testing.T) { start := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) end := time.Date(2026, 1, 10, 0, 0, 0, 0, time.UTC) today := time.Date(2026, 2, 1, 0, 0, 0, 0, time.UTC) if g := guaranteeOf(90, start, &end, "completed", today); g.Breached { t.Error("a completed assignment inside the guarantee window was counted as a breach") } for _, s := range []string{"fell_off", "terminated"} { if g := guaranteeOf(90, start, &end, s, today); !g.Breached { t.Errorf("a %s inside the window did not breach", s) } } } // TestGuaranteeDaysRemainingGoesNegative. A live placement past its guarantee must say so plainly rather // than clamping to zero, which would read as "ends today" forever. func TestGuaranteeDaysRemaining(t *testing.T) { start := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) g := guaranteeOf(30, start, nil, "active", time.Date(2026, 1, 11, 0, 0, 0, 0, time.UTC)) if g.DaysRemaining == nil || *g.DaysRemaining != 19 { // ends 30 Jan, 19 days after 11 Jan t.Errorf("days remaining = %v, want 19", g.DaysRemaining) } g = guaranteeOf(30, start, nil, "active", time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC)) if g.DaysRemaining == nil || *g.DaysRemaining >= 0 { t.Errorf("days remaining = %v past the guarantee, want a negative number", g.DaysRemaining) } // No guarantee at all is not a guarantee of zero days. if g := guaranteeOf(0, start, nil, "active", start); g.EndsOn != "" || g.Breached { t.Errorf("a zero day guarantee produced %+v", g) } } // TestOfferTransitionsMatchTheMigration pins the Go graph against rm_offer_transition in 0055. func TestOfferTransitionsMatchTheMigration(t *testing.T) { legal := map[string][]string{ "extended": {"accepted", "declined", "rescinded", "expired"}, "accepted": {"rescinded"}, } for from := range offerStatuses { for to := range offerStatuses { want := false for _, l := range legal[from] { if l == to { want = true } } if got := offerCanMove(from, to); got != want { t.Errorf("offerCanMove(%q, %q) = %v, want %v", from, to, got, want) } } } // The terminal statuses are terminal. for _, s := range []string{"declined", "rescinded", "expired"} { for to := range offerStatuses { if offerCanMove(s, to) { t.Errorf("%q is terminal but a move to %q was allowed", s, to) } } } // An accepted offer can still be rescinded, because a client pulling a role after acceptance is real. if !offerCanMove("accepted", "rescinded") { t.Error("an accepted offer cannot be rescinded, so a pulled role could not be recorded") } } // TestVocabulariesMatchTheMigrations pins every enum against the CHECK constraints in 0048. func TestPlacementVocabulariesMatchMigrations(t *testing.T) { for name, got := range map[string]map[string]bool{ "offer status": offerStatuses, "placement status": placementStatuses, "interview kind": interviewKinds, "interview outcome": interviewOutcomes, } { if len(got) == 0 { t.Errorf("%s vocabulary is empty", name) } } for _, s := range []string{"extended", "accepted", "declined", "rescinded", "expired"} { if !offerStatuses[s] { t.Errorf("offer status %q is in migration 0048 but missing here", s) } } if len(offerStatuses) != 5 { t.Errorf("offer statuses = %d, migration 0048 permits 5", len(offerStatuses)) } for _, s := range []string{"pending_start", "active", "completed", "terminated", "fell_off"} { if !placementStatuses[s] { t.Errorf("placement status %q is in migration 0048 but missing here", s) } } if len(placementStatuses) != 5 { t.Errorf("placement statuses = %d, migration 0048 permits 5", len(placementStatuses)) } for _, s := range []string{"completed", "terminated", "fell_off"} { if !placementEnded(s) { t.Errorf("%q ends an assignment but is not classified as ended", s) } } for _, s := range []string{"pending_start", "active"} { if placementEnded(s) { t.Errorf("%q is live but is classified as ended", s) } } if len(interviewKinds) != 5 || len(interviewOutcomes) != 6 { t.Errorf("interview vocabularies are %d kinds and %d outcomes, migration 0048 permits 5 and 6", len(interviewKinds), len(interviewOutcomes)) } for _, o := range []string{"passed", "failed", "no_show"} { if !interviewConcluded(o) { t.Errorf("%q requires a completed_at in migration 0048 but is not classified as concluded", o) } } for _, o := range []string{"scheduled", "cancelled", "rescheduled"} { if interviewConcluded(o) { t.Errorf("%q does not require a completed_at but is classified as concluded", o) } } if interviewRoundOK(0) || interviewRoundOK(21) || !interviewRoundOK(1) || !interviewRoundOK(20) { t.Error("interview round bounds do not match the 1 to 20 CHECK in migration 0048") } }

Search equations, builds, manuscript text, and recovered sources.