mediocre-go-lib/mcmp/series_test.go
2019-06-15 17:52:55 -06:00

46 lines
1022 B
Go

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,
massert.Length(SeriesElements(c, key), 0),
massert.Length(SeriesValues(c, key), 0),
)
// test after a single value has been added
AddSeriesValue(c, key, 1)
massert.Require(t,
massert.Equal([]SeriesElement{{Value: 1}}, SeriesElements(c, key)),
massert.Equal([]interface{}{1}, SeriesValues(c, key)),
)
// test after a child has been added
childA := c.Child("a")
massert.Require(t,
massert.Equal(
[]SeriesElement{{Value: 1}, {Child: childA}},
SeriesElements(c, key),
),
massert.Equal([]interface{}{1}, SeriesValues(c, key)),
)
// test after another value has been added
AddSeriesValue(c, key, 2)
massert.Require(t,
massert.Equal(
[]SeriesElement{{Value: 1}, {Child: childA}, {Value: 2}},
SeriesElements(c, key),
),
massert.Equal([]interface{}{1, 2}, SeriesValues(c, key)),
)
}