Updated tests in engine

This commit is contained in:
adragusin
2019-12-02 14:15:45 +02:00
parent 27f07da9de
commit 519f4800b3
3 changed files with 125 additions and 1 deletions

View File

@@ -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)

View File

@@ -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
}

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
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) {