File: aggregation_test.go

package info (click to toggle)
golang-github-facebookgo-stats 0.0~git20151006.0.1b76add-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 108 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 943 bytes parent folder | download | duplicates (3)
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
package stats_test

import (
	"testing"

	"github.com/facebookgo/ensure"
	"github.com/facebookgo/stats"
)

func TestAverage(t *testing.T) {
	t.Parallel()
	ensure.DeepEqual(t, stats.Average([]float64{}), 0.0)
	ensure.DeepEqual(t, stats.Average([]float64{1}), 1.0)
	ensure.DeepEqual(t, stats.Average([]float64{1, 2}), 1.5)
	ensure.DeepEqual(t, stats.Average([]float64{1, 2, 3}), 2.0)
}

func TestSum(t *testing.T) {
	t.Parallel()
	ensure.DeepEqual(t, stats.Sum([]float64{}), 0.0)
	ensure.DeepEqual(t, stats.Sum([]float64{1}), 1.0)
	ensure.DeepEqual(t, stats.Sum([]float64{1, 2}), 3.0)
	ensure.DeepEqual(t, stats.Sum([]float64{1, 2, 3}), 6.0)
}

func TestPercentiles(t *testing.T) {
	t.Parallel()
	percentiles := map[string]float64{
		"p50": 0.5,
		"p90": 0.9,
	}
	input := []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	expected := map[string]float64{
		"p50": 5,
		"p90": 9,
	}
	ensure.DeepEqual(t, stats.Percentiles(input, percentiles), expected)
}