From 0dac63f40fef0a1e60fda1383a473f84d23dab31 Mon Sep 17 00:00:00 2001 From: DanB Date: Fri, 28 Jul 2017 19:36:27 +0200 Subject: [PATCH] Stats ASR returning -1.0 in case of not available, more tests --- stats/asr.go | 2 +- stats/asr_test.go | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/stats/asr.go b/stats/asr.go index 0b8aa47eb..224c2609e 100644 --- a/stats/asr.go +++ b/stats/asr.go @@ -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) diff --git a/stats/asr_test.go b/stats/asr_test.go index 4c6742274..c0e1cb136 100644 --- a/stats/asr_test.go +++ b/stats/asr_test.go @@ -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) + } }