about summary refs log tree commit diff
path: root/tools/seqstat/sequence_test.go
blob: 12990864ff835d9df070060d4961bfc81f8bf8d5 (plain) (blame)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main

import (
	"testing"
)

func TestHistogram(t *testing.T) {
	cases := []struct {
		in        []float64
		histogram []rune
	}{
		{[]float64{1, 2}, []rune{'▁', '█'}},
		{[]float64{1, 10, 4}, []rune{'▁', '█', '▃'}},
		{[]float64{1, 5, 22, 13, 53}, []rune{'▁', '▁', '▃', '▂', '█'}},
	}

	for _, c := range cases {
		seq := newSequence(c.in)
		if string(seq.histogram()) != string(c.histogram) {
			t.Errorf("Not matching: got %q, want %q", string(seq.histogram()), string(c.histogram))
		}
	}
}

func TestStats(t *testing.T) {
	cases := []struct {
		in   []float64
		min  float64
		max  float64
		p999 float64
	}{
		{[]float64{1, 10, 52, 12}, 1, 52, 52},
	}

	for _, c := range cases {
		seq := newSequence(c.in)
		if seq.min != c.min {
			t.Errorf("Not matching: got min %f want %f", seq.min, c.min)
		}
		if seq.max != c.max {
			if seq.max != c.max {
				t.Errorf("Not matching: got max %f want %f", seq.max, c.max)
			}
			if seq.p999() != c.p999 {
				t.Errorf("Not matching: got p999 %f want %f", seq.p999(), c.p999)
			}
		}
	}
}