[#88] min aggregator bug fixed, tests added #164
3 changed files with 57 additions and 6 deletions
|
@ -24,6 +24,7 @@ type (
|
||||||
|
|
||||||
minAgg struct {
|
minAgg struct {
|
||||||
min float64
|
min float64
|
||||||
|
minFound bool
|
||||||
}
|
}
|
||||||
|
|
||||||
meanIQRAgg struct {
|
meanIQRAgg struct {
|
||||||
|
@ -102,7 +103,13 @@ func (a *meanAgg) Compute() float64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *minAgg) Add(n float64) {
|
func (a *minAgg) Add(n float64) {
|
||||||
if a.min == 0 || n < a.min {
|
if !a.minFound {
|
||||||
|
a.min = n
|
||||||
|
a.minFound = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if n < a.min {
|
||||||
a.min = n
|
a.min = n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
44
netmap/aggregator_test.go
Normal file
44
netmap/aggregator_test.go
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package netmap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMinAgg(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
vals []float64
|
||||||
|
res float64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
vals: []float64{1, 2, 3, 0, 10},
|
||||||
|
res: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vals: []float64{10, 0, 10, 0},
|
||||||
|
res: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vals: []float64{0, 1, 2, 3, 10},
|
||||||
|
res: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vals: []float64{0, 0, 0, 0},
|
||||||
|
res: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vals: []float64{10, 10, 10, 10},
|
||||||
|
res: 10,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
a := newMinAgg()
|
||||||
|
for _, val := range test.vals {
|
||||||
|
a.Add(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Equal(t, test.res, a.Compute())
|
||||||
|
}
|
||||||
|
}
|
|
@ -146,19 +146,19 @@
|
||||||
"select 3 nodes in 3 distinct countries, same placement": {
|
"select 3 nodes in 3 distinct countries, same placement": {
|
||||||
"policy": {"replicas":[{"count":1,"selector":"Main"}],"containerBackupFactor":1,"selectors":[{"name":"Main","count":3,"clause":"DISTINCT","attribute":"Country","filter":"*"}],"filters":[]},
|
"policy": {"replicas":[{"count":1,"selector":"Main"}],"containerBackupFactor":1,"selectors":[{"name":"Main","count":3,"clause":"DISTINCT","attribute":"Country","filter":"*"}],"filters":[]},
|
||||||
"pivot": "Y29udGFpbmVySUQ=",
|
"pivot": "Y29udGFpbmVySUQ=",
|
||||||
"result": [[4, 0, 7]],
|
"result": [[0, 2, 3]],
|
||||||
"placement": {
|
"placement": {
|
||||||
"pivot": "b2JqZWN0SUQ=",
|
"pivot": "b2JqZWN0SUQ=",
|
||||||
"result": [[4, 0, 7]]
|
"result": [[0, 2, 3]]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"select 6 nodes in 3 distinct countries, different placement": {
|
"select 6 nodes in 3 distinct countries, different placement": {
|
||||||
"policy": {"replicas":[{"count":1,"selector":"Main"}],"containerBackupFactor":2,"selectors":[{"name":"Main","count":3,"clause":"DISTINCT","attribute":"Country","filter":"*"}],"filters":[]},
|
"policy": {"replicas":[{"count":1,"selector":"Main"}],"containerBackupFactor":2,"selectors":[{"name":"Main","count":3,"clause":"DISTINCT","attribute":"Country","filter":"*"}],"filters":[]},
|
||||||
"pivot": "Y29udGFpbmVySUQ=",
|
"pivot": "Y29udGFpbmVySUQ=",
|
||||||
"result": [[4, 3, 0, 1, 7, 2]],
|
"result": [[0, 1, 2, 6, 3, 4]],
|
||||||
"placement": {
|
"placement": {
|
||||||
"pivot": "b2JqZWN0SUQ=",
|
"pivot": "b2JqZWN0SUQ=",
|
||||||
"result": [[4, 3, 0, 7, 2, 1]]
|
"result": [[0, 1, 2, 6, 3, 4]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue