mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 12:49:54 +05:00
Add test for special cases for account with multiple balance of the same type
This commit is contained in:
committed by
Dan Christian Bogos
parent
d9de22cb55
commit
47e7e67f42
@@ -2186,6 +2186,93 @@ func TestAccountAsAccountDigest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountGetBalancesForPrefixSpecialCases(t *testing.T) {
|
||||
acc := &Account{
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{
|
||||
&Balance{
|
||||
ID: "SpecialBalance1",
|
||||
Value: 10,
|
||||
Weight: 10.0,
|
||||
},
|
||||
&Balance{
|
||||
ID: "SpecialBalance2",
|
||||
Value: 10,
|
||||
Weight: 10.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
bcs := acc.getBalancesForPrefix("", "", utils.MONETARY, "")
|
||||
if len(bcs) != 2 && bcs[0].ID != "SpecialBalance1" && bcs[1].ID != "SpecialBalance2" {
|
||||
t.Errorf("Unexpected order balances : %+v", utils.ToJSON(bcs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountGetBalancesForPrefixSpecialCases2(t *testing.T) {
|
||||
acc := &Account{
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{
|
||||
&Balance{
|
||||
ID: "SpecialBalance1",
|
||||
Value: 10,
|
||||
Weight: 10.0,
|
||||
},
|
||||
&Balance{
|
||||
ID: "SpecialBalance2",
|
||||
Value: 10,
|
||||
Weight: 20.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
bcs := acc.getBalancesForPrefix("", "", utils.MONETARY, "")
|
||||
if len(bcs) != 2 && bcs[0].ID != "SpecialBalance2" && bcs[0].Weight != 20.0 {
|
||||
t.Errorf("Unexpected order balances : %+v", utils.ToJSON(bcs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountGetBalancesForPrefixSpecialCases3(t *testing.T) {
|
||||
acc := &Account{
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{
|
||||
&Balance{
|
||||
ID: "SpecialBalance1",
|
||||
Value: 10,
|
||||
Weight: 10.0,
|
||||
},
|
||||
&Balance{
|
||||
ID: "SpecialBalance2",
|
||||
Value: 10,
|
||||
Weight: 10.0,
|
||||
},
|
||||
&Balance{
|
||||
ID: "SpecialBalance3",
|
||||
Value: 10,
|
||||
Weight: 10.0,
|
||||
},
|
||||
&Balance{
|
||||
ID: "SpecialBalance4",
|
||||
Value: 10,
|
||||
Weight: 10.0,
|
||||
},
|
||||
&Balance{
|
||||
ID: "SpecialBalance5",
|
||||
Value: 10,
|
||||
Weight: 10.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
bcs := acc.getBalancesForPrefix("", "", utils.MONETARY, "")
|
||||
if len(bcs) != 5 &&
|
||||
bcs[0].ID != "SpecialBalance1" && bcs[1].ID != "SpecialBalance2" &&
|
||||
bcs[2].ID != "SpecialBalance3" && bcs[3].ID != "SpecialBalance4" &&
|
||||
bcs[4].ID != "SpecialBalance5" {
|
||||
t.Errorf("Unexpected order balances : %+v", utils.ToJSON(bcs))
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************** Benchmarks *******************************/
|
||||
|
||||
func BenchmarkGetSecondForPrefix(b *testing.B) {
|
||||
|
||||
@@ -740,7 +740,6 @@ func (bc Balances) Swap(i, j int) {
|
||||
func (bc Balances) Less(j, i int) bool {
|
||||
return bc[i].precision < bc[j].precision ||
|
||||
(bc[i].precision == bc[j].precision && bc[i].Weight < bc[j].Weight)
|
||||
|
||||
}
|
||||
|
||||
func (bc Balances) Sort() {
|
||||
|
||||
@@ -67,6 +67,28 @@ func TestBalanceSortWeight(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBalanceSortWeight2(t *testing.T) {
|
||||
bs := Balances{
|
||||
&Balance{ID: "B1", Weight: 2, precision: 1},
|
||||
&Balance{ID: "B2", Weight: 1, precision: 1},
|
||||
}
|
||||
bs.Sort()
|
||||
if bs[0].ID != "B1" && bs[1].ID != "B2" {
|
||||
t.Error("Buckets not sorted by precision!")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBalanceSortWeight3(t *testing.T) {
|
||||
bs := Balances{
|
||||
&Balance{ID: "B1", Weight: 2, Value: 10.0},
|
||||
&Balance{ID: "B2", Weight: 4, Value: 10.0},
|
||||
}
|
||||
bs.Sort()
|
||||
if bs[0].ID != "B2" && bs[1].ID != "B1" {
|
||||
t.Error(utils.ToJSON(bs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBalanceSortWeightLess(t *testing.T) {
|
||||
mb1 := &Balance{Weight: 1, precision: 1}
|
||||
mb2 := &Balance{Weight: 2, precision: 1}
|
||||
|
||||
Reference in New Issue
Block a user