From 519f4800b39dbab792f53ad0e879f99e46f3f4fd Mon Sep 17 00:00:00 2001 From: adragusin Date: Mon, 2 Dec 2019 14:15:45 +0200 Subject: [PATCH] Updated tests in engine --- engine/action_plan_test.go | 12 +++++ engine/rateinterval.go | 21 ++++++++- engine/rateinterval_test.go | 93 +++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) diff --git a/engine/action_plan_test.go b/engine/action_plan_test.go index abb451685..1c0b847da 100644 --- a/engine/action_plan_test.go +++ b/engine/action_plan_test.go @@ -111,6 +111,18 @@ func TestActionPlanClone(t *testing.T) { t.Errorf("\nExpecting: %+v,\n received: %+v", at1, at1Cloned) } } + +func TestActionTimingClone(t *testing.T) { + at := &ActionTiming{ + Uuid: "Uuid_test", + ActionsID: "ActionsID_test", + Weight: 0.7, + } + if cloned := at.Clone(); !reflect.DeepEqual(at, cloned) { + t.Errorf("\nExpecting: %+v,\n received: %+v", at, cloned) + } +} + func TestActionTimindSetActions(t *testing.T) { actionTiming := new(ActionTiming) diff --git a/engine/rateinterval.go b/engine/rateinterval.go index b9bc3f8de..822e1a934 100644 --- a/engine/rateinterval.go +++ b/engine/rateinterval.go @@ -466,7 +466,26 @@ func (rit *RIRate) Clone() (cln *RIRate) { RoundingDecimals: rit.RoundingDecimals, MaxCost: rit.MaxCost, MaxCostStrategy: rit.MaxCostStrategy, - Rates: rit.Rates, + } + if rit.Rates != nil { + cln.Rates = make([]*Rate, len(rit.Rates)) + for i, rate := range rit.Rates { + cln.Rates[i] = rate.Clone() + } } return cln } + +// Clone clones Rates +func (r *Rate) Clone() (cln *Rate) { + if r == nil { + return + } + cln = &Rate{ + GroupIntervalStart: r.GroupIntervalStart, + Value: r.Value, + RateIncrement: r.RateIncrement, + RateUnit: r.RateUnit, + } + return +} diff --git a/engine/rateinterval_test.go b/engine/rateinterval_test.go index 7aa8def3f..cc53eda56 100644 --- a/engine/rateinterval_test.go +++ b/engine/rateinterval_test.go @@ -18,6 +18,7 @@ along with this program. If not, see package engine import ( + "reflect" "testing" "time" @@ -445,6 +446,98 @@ func TestRateGroupsEquals(t *testing.T) { } } +func TestRateIntervalClone(t *testing.T) { + var i, cln RateInterval + if cloned := i.Clone(); !reflect.DeepEqual(cln, *cloned) { + t.Errorf("Expecting: %+v, received: %+v", cln, *cloned) + } + i = RateInterval{ + Weight: 0.7, + } + cln = RateInterval{ + Weight: 0.7, + } + if cloned := i.Clone(); !reflect.DeepEqual(cln, *cloned) { + t.Errorf("Expecting: %+v, received: %+v", cln, *cloned) + } +} + +func TestRITimingClone(t *testing.T) { + var rit, cln RITiming + if cloned := rit.Clone(); !reflect.DeepEqual(cln, *cloned) { + t.Errorf("Expecting: %+v, received: %+v", cln, *cloned) + } + rit = RITiming{ + Years: utils.Years{2019}, + Months: utils.Months{4}, + MonthDays: utils.MonthDays{18}, + WeekDays: utils.WeekDays{5}, + StartTime: "StartTime_test", + EndTime: "EndTime_test", + } + cln = RITiming{ + Years: utils.Years{2019}, + Months: utils.Months{4}, + MonthDays: utils.MonthDays{18}, + WeekDays: utils.WeekDays{5}, + StartTime: "StartTime_test", + EndTime: "EndTime_test", + } + cloned := rit.Clone() + if !reflect.DeepEqual(cln, *cloned) { + t.Errorf("Expecting: %+v, received: %+v", cln, *cloned) + } + rit.Years = utils.Years{2020} + if cloned.Years[0] != cln.Years[0] { + t.Errorf("Expecting: 2019, received: %+v", cloned.Years) + } +} + +func TestRIRateClone(t *testing.T) { + var rit, cln RIRate + if cloned := rit.Clone(); !reflect.DeepEqual(cln, *cloned) { + t.Errorf("\nExpecting: %+v,\n received: %+v", cln, *cloned) + } + rit = RIRate{ + ConnectFee: 0.7, + RoundingMethod: "RoundingMethod_test", + RoundingDecimals: 7, + MaxCost: 0.7, + MaxCostStrategy: "MaxCostStrategy_test", + Rates: RateGroups{ + &Rate{ + GroupIntervalStart: time.Duration(10), + Value: 0.7, + RateIncrement: time.Duration(10), + RateUnit: time.Duration(10), + }, + }, + } + cln = RIRate{ + ConnectFee: 0.7, + RoundingMethod: "RoundingMethod_test", + RoundingDecimals: 7, + MaxCost: 0.7, + MaxCostStrategy: "MaxCostStrategy_test", + Rates: RateGroups{ + &Rate{ + GroupIntervalStart: time.Duration(10), + Value: 0.7, + RateIncrement: time.Duration(10), + RateUnit: time.Duration(10), + }, + }, + } + cloned := rit.Clone() + if !reflect.DeepEqual(cln, *cloned) { + t.Errorf("Expecting: %+v, received: %+v", cln, *cloned) + } + rit.Rates[0].GroupIntervalStart = time.Duration(7) + if cloned.Rates[0].GroupIntervalStart != time.Duration(10) { + t.Errorf("\nExpecting: 10,\n received: %+v", cloned.Rates[0].GroupIntervalStart) + } +} + /*********************************Benchmarks**************************************/ func BenchmarkRateIntervalContainsDate(b *testing.B) {