2019-06-15 18:36:10 +00:00
|
|
|
package mcmp
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "testing"
|
|
|
|
|
|
|
|
"github.com/mediocregopher/mediocre-go-lib/mtest/massert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSeries(t *T) {
|
|
|
|
key := "foo"
|
|
|
|
|
|
|
|
// test empty state
|
|
|
|
c := new(Component)
|
|
|
|
massert.Require(t,
|
2019-06-15 23:52:55 +00:00
|
|
|
massert.Length(SeriesElements(c, key), 0),
|
|
|
|
massert.Length(SeriesValues(c, key), 0),
|
2019-06-15 18:36:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// test after a single value has been added
|
|
|
|
AddSeriesValue(c, key, 1)
|
|
|
|
massert.Require(t,
|
2019-06-15 23:52:55 +00:00
|
|
|
massert.Equal([]SeriesElement{{Value: 1}}, SeriesElements(c, key)),
|
|
|
|
massert.Equal([]interface{}{1}, SeriesValues(c, key)),
|
2019-06-15 18:36:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// test after a child has been added
|
|
|
|
childA := c.Child("a")
|
|
|
|
massert.Require(t,
|
|
|
|
massert.Equal(
|
|
|
|
[]SeriesElement{{Value: 1}, {Child: childA}},
|
2019-06-15 23:52:55 +00:00
|
|
|
SeriesElements(c, key),
|
2019-06-15 18:36:10 +00:00
|
|
|
),
|
2019-06-15 23:52:55 +00:00
|
|
|
massert.Equal([]interface{}{1}, SeriesValues(c, key)),
|
2019-06-15 18:36:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// test after another value has been added
|
|
|
|
AddSeriesValue(c, key, 2)
|
|
|
|
massert.Require(t,
|
|
|
|
massert.Equal(
|
|
|
|
[]SeriesElement{{Value: 1}, {Child: childA}, {Value: 2}},
|
2019-06-15 23:52:55 +00:00
|
|
|
SeriesElements(c, key),
|
2019-06-15 18:36:10 +00:00
|
|
|
),
|
2019-06-15 23:52:55 +00:00
|
|
|
massert.Equal([]interface{}{1, 2}, SeriesValues(c, key)),
|
2019-06-15 18:36:10 +00:00
|
|
|
)
|
|
|
|
}
|