Stats ASR returning -1.0 in case of not available, more tests

This commit is contained in:
DanB
2017-07-28 19:36:27 +02:00
parent 204f42798c
commit 0dac63f40f
2 changed files with 21 additions and 4 deletions

View File

@@ -46,7 +46,7 @@ func (asr *ASR) GetStringValue(fmtOpts string) (valStr string) {
func (asr *ASR) GetValue() (v interface{}) {
if asr.Count == 0 {
return engine.STATS_NA
return float64(engine.STATS_NA)
}
return utils.Round((asr.Answered / asr.Count * 100),
config.CgrConfig().RoundingDecimals, utils.ROUNDING_MIDDLE)

View File

@@ -30,9 +30,9 @@ func TestASRGetStringValue(t *testing.T) {
if strVal := asr.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
t.Errorf("wrong asr value: %s", strVal)
}
asr.AddEvent(
engine.StatsEvent{
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)})
ev := engine.StatsEvent{
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}
asr.AddEvent(ev)
if strVal := asr.GetStringValue(""); strVal != "100%" {
t.Errorf("wrong asr value: %s", strVal)
}
@@ -45,6 +45,15 @@ func TestASRGetStringValue(t *testing.T) {
if strVal := asr.GetStringValue(""); strVal != "50%" {
t.Errorf("wrong asr value: %s", strVal)
}
asr.RemEvent(ev)
if strVal := asr.GetStringValue(""); strVal != "0%" {
t.Errorf("wrong asr value: %s", strVal)
}
asr.RemEvent(engine.StatsEvent{})
if strVal := asr.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
t.Errorf("wrong asr value: %s", strVal)
}
}
func TestASRGetValue(t *testing.T) {
@@ -65,4 +74,12 @@ func TestASRGetValue(t *testing.T) {
if v := asr.GetValue(); v != 50.0 {
t.Errorf("wrong asr value: %f", v)
}
asr.RemEvent(ev)
if v := asr.GetValue(); v != 0.0 {
t.Errorf("wrong asr value: %f", v)
}
asr.RemEvent(engine.StatsEvent{})
if v := asr.GetValue(); v != -1.0 {
t.Errorf("wrong asr value: %f", v)
}
}