package iace import "testing" // TestComputePLr_Canonical8 pins the 8 leaves of the EN ISO 13849-1 // Annex A risk graph: S1/S2 x F1/F2 x P1/P2 -> a..e. func TestComputePLr_Canonical8(t *testing.T) { cases := []struct { s, f, p int want string }{ {1, 1, 1, "a"}, {1, 1, 2, "b"}, {1, 2, 1, "b"}, {1, 2, 2, "c"}, {2, 1, 1, "c"}, {2, 1, 2, "d"}, {2, 2, 1, "d"}, {2, 2, 2, "e"}, // worst case: severe + frequent + hardly avoidable } for _, c := range cases { got := ComputePLr(c.s, c.f, c.p) if got != c.want { t.Errorf("ComputePLr(S%d F%d P%d) = %q, want %q", c.s, c.f, c.p, got, c.want) } } } // TestSeverityExposureMapping ensures the 1-5 internal fields map to the // correct binary S/F parameter at the documented threshold (3). func TestSeverityExposureMapping(t *testing.T) { for sev, wantS := range map[int]int{1: 1, 2: 1, 3: 2, 4: 2, 5: 2} { if got := SeverityToS(sev); got != wantS { t.Errorf("SeverityToS(%d) = %d, want %d", sev, got, wantS) } } for exp, wantF := range map[int]int{1: 1, 2: 1, 3: 2, 4: 2, 5: 2} { if got := ExposureToF(exp); got != wantF { t.Errorf("ExposureToF(%d) = %d, want %d", exp, got, wantF) } } }