package events

import (
	"testing"
	"time"
)

func TestStat_String(t *testing.T) {
	var stat Stat

	goodStr := `{"events_processed":0,"events_aggregated":0,"average_iteration":{"value":"0s"}}`

	if stat.String() != goodStr {
		t.Errorf("Can't serialize stat. Expect %v, got %v", goodStr, stat.String())
	}
}

func TestStat_Update(t *testing.T) {
	var s1, s2 Stat

	s1.EventsProcessed = 10
	s1.EventsAggregated = 10
	s1.AverageIterationTime.Add(time.Second)

	s2.EventsProcessed = 10
	s2.EventsAggregated = 10
	s2.AverageIterationTime.Add(time.Second * 3)

	s1.Update(s2)

	goodStr := `{"events_processed":20,"events_aggregated":20,"average_iteration":{"value":"400ms"}}`

	if s1.String() != goodStr {
		t.Errorf("Can't serialize stat. Expect %v, got %v", goodStr, s1.String())
	}
}
