From c2497219ef422e30dd7002b5515927c8181ca112 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 9 Feb 2012 16:01:08 +0200 Subject: [PATCH] more tests more corrections --- timespans/activationperiod.go | 7 +++++-- timespans/calldesc.go | 2 +- timespans/calldesc_test.go | 14 ++++++++++++++ timespans/intervals.go | 1 + timespans/test.kch | Bin 6298256 -> 6298256 bytes timespans/test_data.json | 7 +++++++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/timespans/activationperiod.go b/timespans/activationperiod.go index ecca7e133..f3a73975c 100644 --- a/timespans/activationperiod.go +++ b/timespans/activationperiod.go @@ -4,6 +4,7 @@ import ( "strconv" "strings" "time" + //"log" ) /* @@ -61,8 +62,10 @@ func (ap *ActivationPeriod) restore(input string) { i.Month = time.Month(month) i.MonthDay, _ = strconv.Atoi(ise[1]) for _, d := range strings.Split(ise[2], ",") { - wd, _ := strconv.Atoi(d) - i.WeekDays = append(i.WeekDays, time.Weekday(wd)) + if d != ""{ + wd, _ := strconv.Atoi(d) + i.WeekDays = append(i.WeekDays, time.Weekday(wd)) + } } i.StartTime = ise[3] i.EndTime = ise[4] diff --git a/timespans/calldesc.go b/timespans/calldesc.go index ee9c9000f..e20be8248 100644 --- a/timespans/calldesc.go +++ b/timespans/calldesc.go @@ -118,7 +118,7 @@ func (cd *CallDescriptor) GetCost(sg StorageGetter) (result *CallCost, err error destPrefix, err := cd.RestoreFromStorage(sg) timespans := cd.splitInTimeSpans() - + cost := 0.0 for _, ts := range timespans { cost += ts.GetCost() diff --git a/timespans/calldesc_test.go b/timespans/calldesc_test.go index e4de5a678..d8893ba54 100644 --- a/timespans/calldesc_test.go +++ b/timespans/calldesc_test.go @@ -126,6 +126,20 @@ func TestLessThanAMinute(t *testing.T) { } } +func TestUniquePrice(t *testing.T) { + getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10) + defer getter.Close() + + t1 := time.Date(2012, time.February, 8, 22, 50, 0, 0, time.UTC) + t2 := time.Date(2012, time.February, 8, 23, 50, 21, 0, time.UTC) + cd := &CallDescriptor{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0723045326", TimeStart: t1, TimeEnd: t2} + result, _ := cd.GetCost(getter) + expected := &CallCost{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0723", Cost: 60.35, ConnectFee: 0} + if *result != *expected { + t.Errorf("Expected %v was %v", expected, result) + } +} + /*********************************** BENCHMARKS ***************************************/ func BenchmarkRedisGetting(b *testing.B) { b.StopTimer() diff --git a/timespans/intervals.go b/timespans/intervals.go index 6495ebc06..f082dbdbc 100644 --- a/timespans/intervals.go +++ b/timespans/intervals.go @@ -4,6 +4,7 @@ import ( "strconv" "strings" "time" + //"log" ) /* diff --git a/timespans/test.kch b/timespans/test.kch index db7902939b8ace54dabe4ce74f399561c3471857..cf1a25715bd64d1eef147c1719b803e92262fd09 100644 GIT binary patch delta 468 zcmZ|LIZi?W6a`TAtN0b?5fv3Doc-_>0u+uoqh6e63S(kRVMU?E)fOvvU}s`O+=PiM zU@K`+?Qc$4#P^Ir4PnR_Fh=XDz;`6N2ig)SQJk7MQoh*F}AFo<%Zf~X`ML{$dn zTg-48p8r<}lc*+Y2q#fX)DiVW1JOt{5zRyk(Mq%t?L-IRB07mKqML9NJwz|jM|g;S zVt^PVhKOOpONM!c=(l~gf7T8LtfEA$l$BEQL5X&I71ctz7G4&TmXZ^ff%qw)uKpnn1*9;0