package main import ( "testing" "time" ) func TestIncidentsGroupsByGap(t *testing.T) { got := incidents([]time.Duration{ 5 * time.Second, 1 * time.Second, 1500 * time.Millisecond, }, time.Second) if len(got) != 2 { t.Fatalf("incidents = %+v, want 2", got) } if got[0].Errors != 2 || got[0].DurationS != 0.5 || got[1].Errors != 1 || got[1].DurationS != 0 { t.Errorf("incidents = %+v", got) } } func TestPercentiles(t *testing.T) { d := make([]time.Duration, 100) for i := range d { d[i] = time.Duration(100-i) * time.Millisecond } got := percentiles(d) if got.Count != 100 || got.P50 != 51 || got.P95 != 96 || got.P99 != 100 { t.Errorf("percentiles = %+v", got) } }