Cover the loss window, rate window, error taxonomy and formatters with tests

This commit is contained in:
flamingcow
2026-08-04 15:46:12 -07:00
parent 63196eb691
commit 8db5c29882
5 changed files with 315 additions and 1 deletions
+25
View File
@@ -0,0 +1,25 @@
package main
import "testing"
func stamped(min, floor int64) view {
return view{cable: cableView{min: min, floor: floor, ok: true}}
}
// Averaged across directions, since one direction alone carries a phy asymmetry
// that swamps the cable.
func TestCableMetresAveragesDirections(t *testing.T) {
m, ok := cableMetres([]view{stamped(1000, 900), stamped(1100, 900)}, 5)
if !ok || m != 30 {
t.Errorf("cableMetres = %v, %v; want 30, true", m, ok)
}
}
func TestCableMetresNeedsEveryDirection(t *testing.T) {
if _, ok := cableMetres(nil, 5); ok {
t.Error("no views should not yield a length")
}
if _, ok := cableMetres([]view{stamped(1000, 900), {}}, 5); ok {
t.Error("a direction with no stamp yet should not yield a length")
}
}