From cafe5a5263beb769b5b297d1c5d10fd6fe637909 Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Tue, 4 Jul 2017 23:09:28 +0300 Subject: [PATCH] Formated and added more tests --- config/config_json_test.go | 1 - config/config_test.go | 4 +- config/libconfig_json.go | 2 +- utils/dateseries_test.go | 86 ++++++++++++++++++++++++++++++-------- utils/value_formula.go | 4 +- 5 files changed, 74 insertions(+), 23 deletions(-) diff --git a/config/config_json_test.go b/config/config_json_test.go index 7abb76c22..c28e361c9 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -24,7 +24,6 @@ import ( "testing" "github.com/cgrates/cgrates/utils" - ) var dfCgrJsonCfg *CgrJsonCfg diff --git a/config/config_test.go b/config/config_test.go index 5c0ef18d7..a787750ee 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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) } } diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 837b44b57..3b21cdb17 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -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 diff --git a/utils/dateseries_test.go b/utils/dateseries_test.go index ab04390c2..225897124 100644 --- a/utils/dateseries_test.go +++ b/utils/dateseries_test.go @@ -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) } } diff --git a/utils/value_formula.go b/utils/value_formula.go index a1a2e38f3..06caa9ffe 100644 --- a/utils/value_formula.go +++ b/utils/value_formula.go @@ -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" {