mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 14:19:54 +05:00
Populate other fields for RateCost and add an example of test for CorrectCost
This commit is contained in:
committed by
Dan Christian Bogos
parent
def6b2091e
commit
318145d7c5
@@ -203,11 +203,11 @@ func (rPc *RateProfileCost) CorrectCost(rndDec *int, rndMtd string) {
|
||||
}
|
||||
|
||||
}
|
||||
if rPc.Cost < rPc.MinCost {
|
||||
if rPc.MinCost != 0 && rPc.Cost < rPc.MinCost {
|
||||
rPc.Cost = rPc.MinCost
|
||||
rPc.Altered = append(rPc.Altered, utils.MinCost)
|
||||
}
|
||||
if rPc.Cost > rPc.MaxCost {
|
||||
if rPc.MaxCost != 0 && rPc.Cost > rPc.MaxCost {
|
||||
rPc.Cost = rPc.MaxCost
|
||||
rPc.Altered = append(rPc.Altered, utils.MaxCost)
|
||||
}
|
||||
|
||||
@@ -656,3 +656,21 @@ func TestCostForIntervalsWIthFixedFee(t *testing.T) {
|
||||
t.Errorf("eDcml: %f, received: %+v", eDcml, cost)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRateProfileCostCorrectCost(t *testing.T) {
|
||||
rPrfCost := &RateProfileCost{
|
||||
ID: "Test1",
|
||||
Cost: 0.234,
|
||||
}
|
||||
rPrfCost.CorrectCost(utils.IntPointer(2), utils.ROUNDING_UP)
|
||||
if rPrfCost.Cost != 0.24 {
|
||||
t.Errorf("Expected: %+v, received: %+v", 0.24, rPrfCost.Cost)
|
||||
}
|
||||
if rPrfCost.RoundingDecimals != 2 {
|
||||
t.Errorf("Expected: %+v, received: %+v", 2, rPrfCost.Cost)
|
||||
}
|
||||
if !reflect.DeepEqual(rPrfCost.Altered, []string{utils.RoundingDecimals}) {
|
||||
t.Errorf("Expected: %+v, received: %+v", []string{utils.RoundingDecimals}, rPrfCost.Altered)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -162,7 +162,13 @@ func (rS *RateS) rateProfileCostForEvent(rtPfl *engine.RateProfile, args *utils.
|
||||
if ordRts, err = orderRatesOnIntervals(aRates, sTime, usage, true, 1000000); err != nil {
|
||||
return
|
||||
}
|
||||
rpCost = &engine.RateProfileCost{ID: rtPfl.ID}
|
||||
rpCost = &engine.RateProfileCost{
|
||||
ID: rtPfl.ID,
|
||||
MinCost: rtPfl.MinCost,
|
||||
MaxCost: rtPfl.MaxCost,
|
||||
RoundingDecimals: rtPfl.RoundingDecimals,
|
||||
RoundingMethod: rtPfl.RoundingMethod,
|
||||
}
|
||||
if rpCost.RateSIntervals, err = computeRateSIntervals(ordRts, 0, usage); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user