Formated and added more tests

This commit is contained in:
edwardro22
2017-07-04 23:09:28 +03:00
parent a32181722d
commit cafe5a5263
5 changed files with 74 additions and 23 deletions

View File

@@ -24,7 +24,6 @@ import (
"testing"
"github.com/cgrates/cgrates/utils"
)
var dfCgrJsonCfg *CgrJsonCfg

View File

@@ -437,8 +437,8 @@ func TestCgrCfgJSONDefaultsCacheCFG(t *testing.T) {
Timings: &CacheParamConfig{Limit: 10000,
TTL: time.Duration(0 * time.Second), Precache: false},
}
if !reflect.DeepEqual(eCacheCfg, cgrCfg.CacheConfig) {
t.Errorf("received: %+v, expecting: %+v", eCacheCfg, cgrCfg.CacheConfig)
if !reflect.DeepEqual(eCacheCfg, cgrCfg.CacheConfig) {
t.Errorf("received: %+v, expecting: %+v", eCacheCfg, cgrCfg.CacheConfig)
}
}

View File

@@ -263,7 +263,7 @@ type CacheJsonCfg struct {
Reverse_aliases *CacheParamJsonCfg
Derived_chargers *CacheParamJsonCfg
Resource_limits *CacheParamJsonCfg
Timings *CacheParamJsonCfg
Timings *CacheParamJsonCfg
}
// Represents one connection instance towards FreeSWITCH

View File

@@ -193,31 +193,31 @@ func TestDateseriesWeekDaysEquals(t *testing.T) {
wds2 := WeekDays{time.Monday, time.Saturday, time.Sunday}
wds3 := WeekDays{time.Monday}
if wds1.Equals(wds2) != true {
t.Errorf("Expected: true, got: %v",!true)
}else if wds1.Equals(wds3) !=false {
t.Errorf("Expected: false, got: %v",!false)
t.Errorf("Expected: true, got: %v", !true)
} else if wds1.Equals(wds3) != false {
t.Errorf("Expected: false, got: %v", !false)
}
}
func TestDateseriesMonthsEquals(t *testing.T) {
func TestDateseriesMonthsEquals(t *testing.T) {
m1 := Months{5, 6, 7, 8}
m2 := Months{5, 6, 7, 8}
m3 := Months{}
if m1.Equals(m2) !=true {
t.Errorf("Expected: true, got: %v",!true)
}else if m1.Equals(m3) !=false {
t.Errorf("Expected: false, got: %v",!false)
if m1.Equals(m2) != true {
t.Errorf("Expected: true, got: %v", !true)
} else if m1.Equals(m3) != false {
t.Errorf("Expected: false, got: %v", !false)
}
}
func TestDateseriesMonthDayssEquals(t *testing.T) {
func TestDateseriesMonthDaysEquals(t *testing.T) {
md1 := MonthDays{24, 25, 26}
md2 := MonthDays{24, 25, 26}
md3 := MonthDays{}
if md1.Equals(md2) !=true {
t.Errorf("Expected: true, got: %v",!true)
}else if md1.Equals(md3) !=false {
t.Errorf("Expected: false, got: %v",!false)
if md1.Equals(md2) != true {
t.Errorf("Expected: true, got: %v", !true)
} else if md1.Equals(md3) != false {
t.Errorf("Expected: false, got: %v", !false)
}
}
@@ -225,9 +225,61 @@ func TestDateseriesYearsEquals(t *testing.T) {
ys1 := Years{2013, 2014, 2015}
ys2 := Years{2013, 2014, 2015}
ys3 := Years{}
if ys1.Equals(ys2) !=true {
t.Errorf("Expected: true, got: %v",!true)
}else if ys1.Equals(ys3) !=false {
t.Errorf("Expected: false, got: %v",!false)
if ys1.Equals(ys2) != true {
t.Errorf("Expected: true, got: %v", !true)
} else if ys1.Equals(ys3) != false {
t.Errorf("Expected: false, got: %v", !false)
}
}
func TestDateseriesWeekDaysParse(t *testing.T) {
wds1 := WeekDays{}
in := "1,2,3"
wds2 := WeekDays{time.Monday, time.Tuesday, time.Wednesday}
if reflect.DeepEqual(wds2, wds1) != false {
t.Errorf("Expected: %+v, received: %+v", WeekDays{}, wds1)
}
wds1.Parse(in, ",")
if !reflect.DeepEqual(wds2, wds1) {
t.Errorf("Expected: %+v, received: %+v", wds2, wds1)
}
}
func TestDateseriesMonthsParse(t *testing.T) {
m1 := Months{}
m2 := Months{5, 6, 7, 8}
in := "5,6,7,8"
if reflect.DeepEqual(m2, m1) != false {
t.Errorf("Expected: %+v, received: %+v", Months{}, m1)
}
m1.Parse(in, ",")
if !reflect.DeepEqual(m2, m1) {
t.Errorf("Expected: %+v, received: %+v", m2, m1)
}
}
func TestDateseriesMonthDaysParse(t *testing.T) {
md1 := MonthDays{}
md2 := MonthDays{24, 25, 26}
in := "24,25,26"
if reflect.DeepEqual(md2, md1) != false {
t.Errorf("Expected: %+v, received: %+v", MonthDays{}, md1)
}
md1.Parse(in, ",")
if !reflect.DeepEqual(md2, md1) {
t.Errorf("Expected: %+v, received: %+v", md2, md1)
}
}
func TestDateseriesYearsParse(t *testing.T) {
ys1 := Years{}
ys2 := Years{2013, 2014, 2015}
in := "2013,2014,2015"
if reflect.DeepEqual(ys2, ys1) != false {
t.Errorf("Expected: %+v, received: %+v", Years{}, ys1)
}
ys1.Parse(in, ",")
if !reflect.DeepEqual(ys2, ys1) {
t.Errorf("Expected: %+v, received: %+v", ys2, ys1)
}
}

View File

@@ -107,10 +107,10 @@ func incrementalFormula(params map[string]interface{}) float64 {
return units / 24
}
if interval == "month" {
return units / ( DaysInMonth(now.Year(), now.Month()) * 24 )
return units / (DaysInMonth(now.Year(), now.Month()) * 24)
}
if interval == "year" {
return units / ( DaysInYear(now.Year()) * 24 )
return units / (DaysInYear(now.Year()) * 24)
}
}
if increment == "minute" {