97 lines
3.1 KiB
Go
97 lines
3.1 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func freshMod(margins [4]float64) phyModView {
|
|
return phyModView{fresh: true, link: true, margins: margins}
|
|
}
|
|
|
|
func TestPhyDisplayWorstMarginAndFault(t *testing.T) {
|
|
cable := cableInfo{
|
|
ecd: ecdResult{verdicts: [4]int{pairOK, pairOpen, pairOK, pairOK}, metres: [4]int{45, 12, 41, 46}},
|
|
maps: [2]byte{pairIdentityMap, pairIdentityMap},
|
|
}
|
|
a := freshMod([4]float64{5, 5, 2, 0.5})
|
|
b := freshMod([4]float64{4, 5, 5, 5})
|
|
d := phyDisplayFrom(cable, false, a, b)
|
|
|
|
if !d.haveSNR || d.worstMargin != 0.5 {
|
|
t.Errorf("worstMargin = %v (have %v), want 0.5", d.worstMargin, d.haveSNR)
|
|
}
|
|
if d.metres != "44" || d.metresClass != clsBad {
|
|
t.Errorf("metres = %q class %d, want the healthy mean 44 painted bad", d.metres, d.metresClass)
|
|
}
|
|
}
|
|
|
|
func TestCableSummary(t *testing.T) {
|
|
healthy := ecdResult{verdicts: [4]int{pairOK, pairOK, pairOK, pairOK}, metres: [4]int{50, 48, 47, 51}}
|
|
for _, c := range []struct {
|
|
name string
|
|
cable cableInfo
|
|
measuring bool
|
|
want string
|
|
class int
|
|
}{
|
|
{"clean", cableInfo{ecd: healthy, maps: [2]byte{pairIdentityMap, pairIdentityMap}}, false, "49", clsGood},
|
|
{"far-end swap", cableInfo{ecd: healthy, maps: [2]byte{pairIdentityMap, 0xE1}}, false, "49", clsWarn},
|
|
{"no diag yet", cableInfo{}, false, "-", clsNone},
|
|
{"measuring", cableInfo{ecd: healthy, maps: [2]byte{pairIdentityMap, pairIdentityMap}}, true, "...", clsNone},
|
|
} {
|
|
s, cl := cableSummary(c.cable, c.measuring)
|
|
if s != c.want || cl != c.class {
|
|
t.Errorf("%s = %q class %d, want %q class %d", c.name, s, cl, c.want, c.class)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPhyDisplayStaleGoesDim(t *testing.T) {
|
|
cable := cableInfo{
|
|
ecd: ecdResult{verdicts: [4]int{pairOK, pairOK, pairOK, pairOK}, metres: [4]int{45, 45, 41, 46}},
|
|
maps: [2]byte{pairIdentityMap, pairIdentityMap},
|
|
}
|
|
d := phyDisplayFrom(cable, 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 {
|
|
t.Errorf("metres = %q class %d, want the diag verdict kept", d.metres, d.metresClass)
|
|
}
|
|
}
|
|
|
|
func TestCableMetresString(t *testing.T) {
|
|
c := cableInfo{ecd: ecdResult{
|
|
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 := (cableInfo{}).metresString(); got != "-" {
|
|
t.Errorf("no diag = %q, want -", got)
|
|
}
|
|
}
|
|
|
|
func TestSNRClass(t *testing.T) {
|
|
for _, c := range []struct {
|
|
margin float64
|
|
want int
|
|
}{
|
|
{5, clsGood}, {3, clsGood}, {2, clsWarn}, {1, clsWarn}, {0.5, clsBad}, {-2, clsBad},
|
|
} {
|
|
if got := snrClass(c.margin); got != c.want {
|
|
t.Errorf("snrClass(%v) = %d, want %d", c.margin, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestVerdictString(t *testing.T) {
|
|
ok := ecdResult{verdicts: [4]int{1, 1, 1, 1}, metres: [4]int{45, 45, 41, 46}}
|
|
if got := verdictString(ok); got != "all pairs ok, 45/45/41/46 m" {
|
|
t.Errorf("healthy = %q", got)
|
|
}
|
|
bad := ecdResult{verdicts: [4]int{1, 2, 4, 1}, metres: [4]int{45, 12, 30, 46}}
|
|
if got := verdictString(bad); got != "B OPEN at 12m, C XTALK at 30m" {
|
|
t.Errorf("faulted = %q", got)
|
|
}
|
|
}
|