File: histogram_test.go

package info (click to toggle)
dnss 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 368 kB
  • sloc: sh: 237; makefile: 6
file content (29 lines) | stat: -rw-r--r-- 605 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package nettrace

import (
	"testing"
	"time"
)

func TestHistogramBasic(t *testing.T) {
	h := histogram{}
	h.Add(1, 1*time.Millisecond)

	snap := h.Snapshot()
	if snap.Count != 1 ||
		snap.Min != 1*time.Millisecond ||
		snap.Max != 1*time.Millisecond ||
		snap.Avg != 1*time.Millisecond {
		t.Errorf("expected snapshot with only 1 sample, got %v", snap)
	}
}

func TestHistogramEmpty(t *testing.T) {
	h := histogram{}
	snap := h.Snapshot()

	if len(snap.Counts) != nBuckets || snap.Count != 0 ||
		snap.Avg != 0 || snap.Min != 0 || snap.Max != 0 {
		t.Errorf("expected zero snapshot, got %v", snap)
	}
}