mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
restutured userbuget
This commit is contained in:
20
timespans/minute_buckets.go
Normal file
20
timespans/minute_buckets.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package timespans
|
||||
|
||||
type MinuteBucket struct {
|
||||
seconds int
|
||||
priority int
|
||||
price float64
|
||||
destination *Destination
|
||||
}
|
||||
|
||||
/*
|
||||
Returns true if the bucket contains specified prefix.
|
||||
*/
|
||||
func (mb *MinuteBucket) containsPrefix(prefix string) bool {
|
||||
for _, p := range mb.destination.Prefixes {
|
||||
if prefix == p {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
0
timespans/minute_buckets_test.go
Normal file
0
timespans/minute_buckets_test.go
Normal file
6
timespans/tariff_plans.go
Normal file
6
timespans/tariff_plans.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package timespans
|
||||
|
||||
type TariffPlan struct {
|
||||
Id string
|
||||
MinuteBuckets []*MinuteBucket
|
||||
}
|
||||
0
timespans/tariff_plans_test.go
Normal file
0
timespans/tariff_plans_test.go
Normal file
@@ -38,23 +38,3 @@ func (ub *UserBudget) GetSecondsForPrefix(prefix string) (seconds int) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type MinuteBucket struct {
|
||||
seconds int
|
||||
priority int
|
||||
price float64
|
||||
destination *Destination
|
||||
}
|
||||
|
||||
func (mb *MinuteBucket) containsPrefix(prefix string) bool {
|
||||
for _, p := range mb.destination.Prefixes {
|
||||
if prefix == p {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type TariffPlan struct {
|
||||
minuteBuckets []*MinuteBucket
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ var (
|
||||
func TestGetSeconds(t *testing.T) {
|
||||
b1 := &MinuteBucket{seconds: 10, priority: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{seconds: 100, priority: 20, destination: retea}
|
||||
tf1 := &TariffPlan{minuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
tf1 := &TariffPlan{MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
|
||||
ub1 := &UserBudget{id: "rif", minuteBuckets: []*MinuteBucket{b1, b2}, credit: 200, tariffPlan: tf1, resetDayOfTheMonth: 10}
|
||||
seconds := ub1.GetSecondsForPrefix("0723")
|
||||
@@ -25,7 +25,7 @@ func TestGetSeconds(t *testing.T) {
|
||||
func TestGetPricedSeconds(t *testing.T) {
|
||||
b1 := &MinuteBucket{seconds: 10, price: 10, priority: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{seconds: 100, price: 1, priority: 20, destination: retea}
|
||||
tf1 := &TariffPlan{minuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
tf1 := &TariffPlan{MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
|
||||
ub1 := &UserBudget{id: "rif", minuteBuckets: []*MinuteBucket{b1, b2}, credit: 21, tariffPlan: tf1, resetDayOfTheMonth: 10}
|
||||
seconds := ub1.GetSecondsForPrefix("0723")
|
||||
@@ -41,7 +41,7 @@ func BenchmarkGetSecondForPrefix(b *testing.B) {
|
||||
b.StopTimer()
|
||||
b1 := &MinuteBucket{seconds: 10, price: 10, priority: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{seconds: 100, price: 1, priority: 20, destination: retea}
|
||||
tf1 := &TariffPlan{minuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
tf1 := &TariffPlan{MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
|
||||
ub1 := &UserBudget{id: "rif", minuteBuckets: []*MinuteBucket{b1, b2}, credit: 21, tariffPlan: tf1, resetDayOfTheMonth: 10}
|
||||
b.StartTimer()
|
||||
|
||||
Reference in New Issue
Block a user