Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/matching/engine/weights_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/matching/engine/weights_test.go |
| Original SHA-256 | 14a820394a2379eeb3d44902d986bb54ba3e5ecd30b3599e70a39c6ec0b25126 |
| Git blob SHA | d503b401a2ecbce8409979041149135595e035d4 |
| Reading-copy SHA-256 | 14a820394a2379eeb3d44902d986bb54ba3e5ecd30b3599e70a39c6ec0b25126 |
Every recorded occurrence
These 2 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/modules/matching/engine/weights_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/modules/matching/engine/weights_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
Recovered source transcript
Download complete source text ↓122 lines · 4.1 KB
package engine
import (
"context"
"reflect"
"testing"
"github.com/shopspring/decimal"
)
// TestDefaultWeightsIdentity proves the weighted entry point with the default weights reproduces
// ScoreCandidate exactly, so the AIOE wiring cannot drift the historical scores.
func TestDefaultWeightsIdentity(t *testing.T) {
cands := []Candidate{
{
ID: "c1",
Clearance: Clearance{Level: ClearanceTSSCI, Status: StatusActive},
Skills: []CandidateSkill{
{SkillID: "s1", Name: "Signals Intelligence"},
{SkillID: "s2", Name: "Network Analysis"},
},
Certifications: []string{"Security+"},
CustomerExperience: []string{"NSA"},
YearsExperience: 7,
Location: "Fort Meade, MD",
Available: true,
},
{ID: "c2", Clearance: Clearance{Level: ClearanceSecret, Status: StatusExpired}},
{ID: "c3", YearsExperience: 2, Relocatable: true},
}
reqs := []Requirement{
{
ID: "r1",
RequiredLevel: ClearanceTSSCI,
RequiredSkills: []RequiredSkill{
{SkillID: "s1", Name: "Signals Intelligence", Mandatory: true},
{SkillID: "s9", Name: "Targeting"},
},
RequiredCerts: []string{"Security+", "CISSP"},
CustomerAgency: "NSA",
RequiredYears: 5,
WorkLocation: "Fort Meade, MD",
},
{ID: "r2"},
}
for _, c := range cands {
for _, r := range reqs {
a := ScoreCandidate(context.Background(), c, r, nil)
b := ScoreCandidateWithWeights(context.Background(), c, r, nil, DefaultWeights())
if !reflect.DeepEqual(a, b) {
t.Fatalf("weighted default diverges for c=%s r=%s:\n a=%+v\n b=%+v", c.ID, r.ID, a, b)
}
}
}
}
// TestCustomWeightsChangeOnlyTheWeighting proves an alternate profile changes weights and totals but
// never the raw dimension scores, so the adaptive layer can only rebalance, never rescore.
func TestCustomWeightsChangeOnlyTheWeighting(t *testing.T) {
c := Candidate{
ID: "c1",
Clearance: Clearance{Level: ClearanceTopSecret, Status: StatusActive},
Skills: []CandidateSkill{{SkillID: "s1", Name: "RMF"}},
Available: true,
}
r := Requirement{
ID: "r1",
RequiredLevel: ClearanceSecret,
RequiredSkills: []RequiredSkill{{SkillID: "s1", Name: "RMF"}, {SkillID: "s2", Name: "ATO"}},
RequiredYears: 4,
}
alt := Weights{
Clearance: decimal.RequireFromString("0.30"),
Skills: decimal.RequireFromString("0.30"),
Certifications: decimal.RequireFromString("0.10"),
CustomerExperience: decimal.RequireFromString("0.10"),
Experience: decimal.RequireFromString("0.10"),
Location: decimal.RequireFromString("0.10"),
}
if err := alt.Validate(); err != nil {
t.Fatalf("alt weights should validate: %v", err)
}
a := ScoreCandidate(context.Background(), c, r, nil)
b := ScoreCandidateWithWeights(context.Background(), c, r, nil, alt)
for name, pair := range map[string][2]decimal.Decimal{
"clearance": {a.Clearance, b.Clearance},
"skills": {a.Skills, b.Skills},
"certs": {a.Certifications, b.Certifications},
"customer": {a.CustomerExperience, b.CustomerExperience},
"experience": {a.Experience, b.Experience},
"location": {a.Location, b.Location},
} {
if !pair[0].Equal(pair[1]) {
t.Fatalf("raw %s score changed under alternate weights: %s vs %s", name, pair[0], pair[1])
}
}
if a.Total.Equal(b.Total) {
t.Fatalf("alternate weights should change the total for this fixture (both %s)", a.Total)
}
if b.Trace[0].Weight.String() != "0.3" && b.Trace[0].Weight.String() != "0.30" {
t.Fatalf("trace should carry the injected weight, got %s", b.Trace[0].Weight)
}
}
func TestWeightsValidate(t *testing.T) {
ok := DefaultWeights()
if err := ok.Validate(); err != nil {
t.Fatalf("default weights must validate: %v", err)
}
bad := DefaultWeights()
bad.Skills = decimal.RequireFromString("0.30")
if err := bad.Validate(); err == nil {
t.Fatal("weights not summing to one must fail validation")
}
zeroed := DefaultWeights()
zeroed.Location = decimal.Zero
zeroed.Experience = decimal.RequireFromString("0.20")
if err := zeroed.Validate(); err == nil {
t.Fatal("a zero weight must fail validation")
}
}