forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metric_test.go
97 lines (84 loc) · 2.64 KB
/
metric_test.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
package main
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCalculate(t *testing.T) {
assert := assert.New(t)
var m = metrics{
Name: "name",
Description: "desc",
Type: "type",
CheckType: "json",
CheckVar: "Results",
MinVal: 1.9,
MaxVal: 2.1,
Gap: 0,
stats: statistics{
Results: []float64{1.0, 2.0, 3.0},
Iterations: 3,
Mean: 0.0,
Min: 0.0,
Max: 0.0,
Range: 0.0,
RangeSpread: 0.0,
SD: 0.0,
CoV: 0.0}}
m.calculate()
// Constants here calculated from info coded in struct above
// We do a little funky math on Gap to round it to within 0.1% - as the actual
// gap math gave us 10.000000000000009 ...
roundedGap := math.Round(m.Gap/0.001) * 0.001
assert.Equal(10.0, roundedGap, "Should be equal")
assert.Equal(2.0, m.stats.Mean, "Should be equal")
assert.Equal(1.0, m.stats.Min, "Should be equal")
assert.Equal(3.0, m.stats.Max, "Should be equal")
assert.Equal(2.0, m.stats.Range, "Should be equal")
assert.Equal(200.0, m.stats.RangeSpread, "Should be equal")
assert.Equal(0.816496580927726, m.stats.SD, "Should be equal")
assert.Equal(40.8248290463863, m.stats.CoV, "Should be equal")
}
// Test that only setting a % range works
func TestCalculate2(t *testing.T) {
assert := assert.New(t)
var m = metrics{
Name: "name",
Description: "desc",
Type: "type",
CheckType: "json",
CheckVar: "Results",
//MinVal: 1.9,
//MaxVal: 2.1,
MinPercent: 20,
MaxPercent: 25,
MidVal: 2.0,
Gap: 0,
stats: statistics{
Results: []float64{1.0, 2.0, 3.0},
Iterations: 3,
Mean: 0.0,
Min: 0.0,
Max: 0.0,
Range: 0.0,
RangeSpread: 0.0,
SD: 0.0,
CoV: 0.0}}
m.calculate()
// Constants here calculated from info coded in struct above
// We do a little funky math on Gap to round it to within 0.1% - as the actual
// gap math gave us 10.000000000000009 ...
roundedGap := math.Round(m.Gap/0.001) * 0.001
// This is not a nice (20+25), as the 'midval' will skew it.
assert.Equal(43.902, roundedGap, "Should be equal")
assert.Equal(2.0, m.stats.Mean, "Should be equal")
assert.Equal(1.0, m.stats.Min, "Should be equal")
assert.Equal(3.0, m.stats.Max, "Should be equal")
assert.Equal(2.0, m.stats.Range, "Should be equal")
assert.Equal(200.0, m.stats.RangeSpread, "Should be equal")
assert.Equal(0.816496580927726, m.stats.SD, "Should be equal")
assert.Equal(40.8248290463863, m.stats.CoV, "Should be equal")
}