Mask measure blips end to end and show a running median cable length

This commit is contained in:
flamingcow
2026-08-30 19:58:40 -07:00
parent 2cdeccc84d
commit 1bde1f4227
4 changed files with 108 additions and 64 deletions
+32 -23
View File
@@ -14,7 +14,7 @@ func TestPhyDisplayWorstMarginAndFault(t *testing.T) {
}
a := freshMod([4]float64{5, 5, 2, 0.5})
b := freshMod([4]float64{4, 5, 5, 5})
d := phyDisplayFrom(cable, cableRange{}, false, a, b)
d := phyDisplayFrom(cable, cableLengths{}, false, a, b)
if !d.haveSNR || d.worstMargin != 0.5 {
t.Errorf("worstMargin = %v (have %v), want 0.5", d.worstMargin, d.haveSNR)
@@ -27,15 +27,15 @@ func TestPhyDisplayWorstMarginAndFault(t *testing.T) {
func TestPhyDisplaySNREndOwnsMargin(t *testing.T) {
wiitek := freshMod([4]float64{9.2, 7.2, 7.0, 8.7})
fs := phyModView{fresh: true, link: true}
d := phyDisplayFrom(cableInfo{}, cableRange{}, false, wiitek, fs)
d := phyDisplayFrom(cableInfo{}, cableLengths{}, false, wiitek, fs)
if !d.haveSNR || d.worstMargin != 7.0 {
t.Errorf("worstMargin = %v (have %v), want the SNR end's 7.0", d.worstMargin, d.haveSNR)
}
d = phyDisplayFrom(cableInfo{}, cableRange{}, false, fs, wiitek)
d = phyDisplayFrom(cableInfo{}, cableLengths{}, false, fs, wiitek)
if !d.haveSNR || d.worstMargin != 7.0 {
t.Errorf("swapped ends: worstMargin = %v, want 7.0", d.worstMargin)
}
d = phyDisplayFrom(cableInfo{}, cableRange{}, false, fs, fs)
d = phyDisplayFrom(cableInfo{}, cableLengths{}, false, fs, fs)
if d.haveSNR {
t.Error("a pair with no SNR end should withhold snr")
}
@@ -50,9 +50,9 @@ func TestCableSummary(t *testing.T) {
want string
class int
}{
{"clean", cableInfo{ecd: healthy, maps: [2]byte{pairIdentityMap, pairIdentityMap}, haveMaps: [2]bool{true, true}}, false, "49", clsGood},
{"clean", cableInfo{ecd: healthy, maps: [2]byte{pairIdentityMap, pairIdentityMap}, haveMaps: [2]bool{true, true}}, false, "48", clsGood},
{"far-end swap", cableInfo{ecd: healthy, maps: [2]byte{pairIdentityMap, 0xE1}, haveMaps: [2]bool{true, true}}, false, "xover", clsWarn},
{"one-end map only", cableInfo{ecd: healthy, maps: [2]byte{pairIdentityMap, 0}, haveMaps: [2]bool{true, false}}, false, "49", clsGood},
{"one-end map only", cableInfo{ecd: healthy, maps: [2]byte{pairIdentityMap, 0}, haveMaps: [2]bool{true, false}}, false, "48", clsGood},
{"fault", cableInfo{ecd: ecdResult{verdicts: [4]int{pairOK, pairShort, pairXtalk, pairOK}, metres: [4]int{50, 12, 30, 51}}}, false, "SHORT", clsBad},
{"fault beats swap", cableInfo{ecd: ecdResult{verdicts: [4]int{pairOpen, pairOK, pairOK, pairOK}}, maps: [2]byte{pairIdentityMap, 0xE1}, haveMaps: [2]bool{true, true}}, false, "OPEN", clsBad},
{"no diag yet", cableInfo{}, false, "-", clsNone},
@@ -71,11 +71,11 @@ func TestPhyDisplayStaleGoesDim(t *testing.T) {
maps: [2]byte{pairIdentityMap, pairIdentityMap},
haveMaps: [2]bool{true, true},
}
d := phyDisplayFrom(cable, cableRange{}, false, freshMod([4]float64{5, 5, 5, 5}), phyModView{})
d := phyDisplayFrom(cable, cableLengths{}, false, freshMod([4]float64{5, 5, 5, 5}), phyModView{})
if d.haveSNR {
t.Error("one silent module should withhold snr")
}
if d.metres != "44" || d.metresClass != clsGood {
if d.metres != "45" || d.metresClass != clsGood {
t.Errorf("metres = %q class %d, want the diag verdict kept", d.metres, d.metresClass)
}
}
@@ -85,26 +85,26 @@ func TestCableMetresString(t *testing.T) {
verdicts: [4]int{pairOK, pairOpen, pairOK, pairOK},
metres: [4]int{45, 3, 41, 46},
}}
if got := c.metresString(); got != "44" {
t.Errorf("metres = %q, want 44", got)
if got := c.metresString(); got != "45" {
t.Errorf("metres = %q, want the healthy pairs' median 45", got)
}
if got := (cableInfo{}).metresString(); got != "-" {
t.Errorf("no diag = %q, want -", got)
}
}
func TestCableRange(t *testing.T) {
var r cableRange
func TestCableLengths(t *testing.T) {
var l cableLengths
for _, m := range []int{42, 40, 44, 41} {
r.add(m)
l.add(m)
}
if r.String() != "40-44" {
t.Errorf("range = %q, want 40-44", r.String())
if m, ok := l.median(); !ok || m != 41 {
t.Errorf("median = %d (%v), want the lower middle 41", m, ok)
}
one := cableRange{}
one := cableLengths{}
one.add(42)
if one.String() != "42" {
t.Errorf("single measure = %q, want 42", one.String())
if m, ok := one.median(); !ok || m != 42 {
t.Errorf("single measure = %d (%v), want 42", m, ok)
}
cable := cableInfo{
@@ -112,14 +112,23 @@ func TestCableRange(t *testing.T) {
maps: [2]byte{pairIdentityMap, pairIdentityMap},
haveMaps: [2]bool{true, true},
}
d := phyDisplayFrom(cable, r, false, freshMod([4]float64{5, 5, 5, 5}), freshMod([4]float64{5, 5, 5, 5}))
if d.metres != "40-44" || d.metresClass != clsGood {
t.Errorf("metres = %q class %d, want the range shown good", d.metres, d.metresClass)
d := phyDisplayFrom(cable, l, false, freshMod([4]float64{5, 5, 5, 5}), freshMod([4]float64{5, 5, 5, 5}))
if d.metres != "41" || d.metresClass != clsGood {
t.Errorf("metres = %q class %d, want the running median shown good", d.metres, d.metresClass)
}
faulted := cableInfo{ecd: ecdResult{verdicts: [4]int{pairOK, pairOpen, pairOK, pairOK}}}
d = phyDisplayFrom(faulted, r, false, freshMod([4]float64{5, 5, 5, 5}), freshMod([4]float64{5, 5, 5, 5}))
d = phyDisplayFrom(faulted, l, false, freshMod([4]float64{5, 5, 5, 5}), freshMod([4]float64{5, 5, 5, 5}))
if d.metres != "OPEN" {
t.Errorf("fault shows %q, want the verdict to beat the range", d.metres)
t.Errorf("fault shows %q, want the verdict to beat the median", d.metres)
}
d = phyDisplayFrom(cable, l, true, freshMod([4]float64{5, 5, 5, 5}), freshMod([4]float64{5, 5, 5, 5}))
if d.metres != "41" || d.metresClass != clsGood {
t.Errorf("measuring shows %q class %d, want the median held", d.metres, d.metresClass)
}
d = phyDisplayFrom(cableInfo{}, l, false, freshMod([4]float64{5, 5, 5, 5}), freshMod([4]float64{5, 5, 5, 5}))
if d.metres != "41" || d.metresClass != clsGood {
t.Errorf("no data shows %q class %d, want the median held", d.metres, d.metresClass)
}
}