mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Stats ASR returning -1.0 in case of not available, more tests
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user