From eddd834f48d5386265cb9ecb6cc24c5692823d1f Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 20 Feb 2012 18:38:33 +0200 Subject: [PATCH] restutured userbuget --- timespans/minute_buckets.go | 20 ++++++++++++++++++++ timespans/minute_buckets_test.go | 0 timespans/tariff_plans.go | 6 ++++++ timespans/tariff_plans_test.go | 0 timespans/userbudget.go | 20 -------------------- timespans/userbudget_test.go | 6 +++--- 6 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 timespans/minute_buckets.go create mode 100644 timespans/minute_buckets_test.go create mode 100644 timespans/tariff_plans.go create mode 100644 timespans/tariff_plans_test.go diff --git a/timespans/minute_buckets.go b/timespans/minute_buckets.go new file mode 100644 index 000000000..05de97398 --- /dev/null +++ b/timespans/minute_buckets.go @@ -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 +} diff --git a/timespans/minute_buckets_test.go b/timespans/minute_buckets_test.go new file mode 100644 index 000000000..e69de29bb diff --git a/timespans/tariff_plans.go b/timespans/tariff_plans.go new file mode 100644 index 000000000..086e05985 --- /dev/null +++ b/timespans/tariff_plans.go @@ -0,0 +1,6 @@ +package timespans + +type TariffPlan struct { + Id string + MinuteBuckets []*MinuteBucket +} diff --git a/timespans/tariff_plans_test.go b/timespans/tariff_plans_test.go new file mode 100644 index 000000000..e69de29bb diff --git a/timespans/userbudget.go b/timespans/userbudget.go index d1e436fdd..8718cb0aa 100644 --- a/timespans/userbudget.go +++ b/timespans/userbudget.go @@ -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 -} diff --git a/timespans/userbudget_test.go b/timespans/userbudget_test.go index 21e3f092d..93b19540c 100644 --- a/timespans/userbudget_test.go +++ b/timespans/userbudget_test.go @@ -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()