From 6ea9fea76ed74819c73a5d638ed2c57a8ff901d1 Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 15 May 2017 17:15:56 +0200 Subject: [PATCH] Equals on EventCost and dateseries --- engine/eventcost.go | 63 ++++++++++++++++++++++++++++++++++++++++++--- utils/dateseries.go | 52 +++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/engine/eventcost.go b/engine/eventcost.go index e70e42cd9..a3e0f55ae 100644 --- a/engine/eventcost.go +++ b/engine/eventcost.go @@ -46,6 +46,23 @@ type ChargingInterval struct { CompressFactor int } +func (cIl *ChargingInterval) Equals(oCIl *ChargingInterval) (equals bool) { + if equals = ((cIl.StartTime == nil && oCIl.StartTime == nil) || + (cIl.StartTime != nil && oCIl.StartTime != nil && cIl.StartTime.Equal(*oCIl.StartTime))) && + cIl.IntervalDetailsUUID == oCIl.IntervalDetailsUUID && + cIl.RatingUUID == oCIl.RatingUUID && + len(cIl.Increments) == len(oCIl.Increments); !equals { + return + } + for i := range cIl.Increments { + if !cIl.Increments[i].Equals(oCIl.Increments[i]) { + equals = false + break + } + } + return +} + // ChargingIncrement represents one unit charged inside an interval type ChargingIncrement struct { Usage time.Duration @@ -54,6 +71,12 @@ type ChargingIncrement struct { CompressFactor int } +func (cIt *ChargingIncrement) Equals(oCIt *ChargingIncrement) bool { + return cIt.Usage == oCIt.Usage && + cIt.Cost == oCIt.Cost && + cIt.BalanceChargeUUID == oCIt.BalanceChargeUUID +} + // BalanceCharge represents one unit charged to a balance type BalanceCharge struct { AccountID string // keep reference for shared balances @@ -63,23 +86,45 @@ type BalanceCharge struct { ExtraChargeUUID string // used in cases when paying *voice with *monetary } +func (bc *BalanceCharge) Equals(oBC *BalanceCharge) bool { + return bc.AccountID == oBC.AccountID && + bc.BalanceUUID == oBC.BalanceUUID && + bc.RatingUUID == oBC.RatingUUID && + bc.Units == oBC.Units && + bc.ExtraChargeUUID == oBC.ExtraChargeUUID +} + type ChrgIntervDetail struct { Subject string // matched subject DestinationPrefix string // matched destination prefix DestinationID string // matched destinationID RatingPlanID string // matched ratingPlanID +} +func (cid *ChrgIntervDetail) Equals(oCID *ChrgIntervDetail) bool { + return cid.Subject == oCID.Subject && + cid.DestinationPrefix == oCID.DestinationPrefix && + cid.DestinationID == oCID.DestinationID && + cid.RatingPlanID == oCID.RatingPlanID } // ChargedTiming represents one timing attached to a charge type ChargedTiming struct { - Years *utils.Years - Months *utils.Months - MonthDays *utils.MonthDays - WeekDays *utils.WeekDays + Years utils.Years + Months utils.Months + MonthDays utils.MonthDays + WeekDays utils.WeekDays StartTime string } +func (ct *ChargedTiming) Equals(oCT *ChargedTiming) bool { + return ct.Years.Equals(oCT.Years) && + ct.Months.Equals(oCT.Months) && + ct.MonthDays.Equals(oCT.MonthDays) && + ct.WeekDays.Equals(oCT.WeekDays) && + ct.StartTime == oCT.StartTime +} + // RatingUnit represents one unit out of RatingPlan matching for an event type RatingUnit struct { ConnectFee float64 @@ -90,3 +135,13 @@ type RatingUnit struct { TimingUUID string // This RatingUnit is bounded to specific timing profile RatesUUID string } + +func (ru *RatingUnit) Equals(oRU *RatingUnit) bool { + return ru.ConnectFee == oRU.ConnectFee && + ru.RoudingMethod == oRU.RoudingMethod && + ru.RoundingDecimals == oRU.RoundingDecimals && + ru.MaxCost == oRU.MaxCost && + ru.MaxCostStrategy == oRU.MaxCostStrategy && + ru.TimingUUID == oRU.TimingUUID && + ru.RatesUUID == oRU.RatesUUID +} diff --git a/utils/dateseries.go b/utils/dateseries.go index c73b0f8fe..09623ffa0 100644 --- a/utils/dateseries.go +++ b/utils/dateseries.go @@ -87,6 +87,19 @@ func (ys Years) Serialize(sep string) string { return yStr } +// Equals implies that Years are already sorted +func (ys Years) Equals(oYS Years) bool { + if len(ys) != len(oYS) { + return false + } + for i := range ys { + if ys[i] != oYS[i] { + return false + } + } + return true +} + // Defines months series type Months []time.Month @@ -154,6 +167,19 @@ func (m Months) IsComplete() bool { return reflect.DeepEqual(m, allMonths) } +// Equals implies that Months are already sorted +func (m Months) Equals(oM Months) bool { + if len(m) != len(oM) { + return false + } + for i := range m { + if m[i] != oM[i] { + return false + } + } + return true +} + // Defines month days series type MonthDays []int @@ -216,6 +242,19 @@ func (md MonthDays) Serialize(sep string) string { return mdsStr } +// Equals implies that MonthDays are already sorted +func (md MonthDays) Equals(oMD MonthDays) bool { + if len(md) != len(oMD) { + return false + } + for i := range md { + if md[i] != oMD[i] { + return false + } + } + return true +} + // Defines week days series type WeekDays []time.Weekday @@ -277,6 +316,19 @@ func (wd WeekDays) Serialize(sep string) string { return wdStr } +// Equals implies that WeekDays are already sorted +func (wd WeekDays) Equals(oWD WeekDays) bool { + if len(wd) != len(oWD) { + return false + } + for i := range wd { + if wd[i] != oWD[i] { + return false + } + } + return true +} + func DaysInMonth(year int, month time.Month) float64 { return float64(time.Date(year, month, 1, 0, 0, 0, 0, time.UTC).AddDate(0, 1, -1).Day()) }