From 6afd7ee19f547605e7672c8dc94327db459410cc Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Wed, 24 Jul 2013 19:10:50 +0300 Subject: [PATCH] one more test for group split --- engine/timespans_test.go | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/engine/timespans_test.go b/engine/timespans_test.go index a3c8db967..859f75bc2 100644 --- a/engine/timespans_test.go +++ b/engine/timespans_test.go @@ -473,3 +473,47 @@ func TestTimespanSplitGroupSecondSplit(t *testing.T) { t.Error("Wrong durations.for Intervals", nts.GetDuration().Seconds(), nnts.GetDuration().Seconds()) } } + +func TestTimespanSplitMultipleGroup(t *testing.T) { + i := &Interval{ + EndTime: "17:05:00", + Prices: PriceGroups{&Price{0, 2, 1}, &Price{60, 1, 1}, &Price{180, 1, 1}}, + } + t1 := time.Date(2012, time.February, 3, 17, 00, 0, 0, time.UTC) + t2 := time.Date(2012, time.February, 3, 17, 04, 0, 0, time.UTC) + ts := &TimeSpan{TimeStart: t1, TimeEnd: t2, CallDuration: 240} + oldDuration := ts.GetDuration() + nts := ts.SplitByInterval(i) + splitTime := time.Date(2012, time.February, 3, 17, 01, 00, 0, time.UTC) + if ts.TimeStart != t1 || ts.TimeEnd != splitTime { + t.Error("Incorrect first half", nts) + } + if nts.TimeStart != splitTime || nts.TimeEnd != t2 { + t.Error("Incorrect second half", nts) + } + if ts.Interval != i { + t.Error("Interval not attached correctly") + } + + if ts.GetDuration().Seconds() != 60 || nts.GetDuration().Seconds() != 180 { + t.Error("Wrong durations.for Intervals", ts.GetDuration().Seconds(), nts.GetDuration().Seconds()) + } + if ts.GetDuration().Seconds()+nts.GetDuration().Seconds() != oldDuration.Seconds() { + t.Errorf("The duration has changed: %v + %v != %v", ts.GetDuration().Seconds(), nts.GetDuration().Seconds(), oldDuration.Seconds()) + } + nnts := nts.SplitByInterval(i) + nsplitTime := time.Date(2012, time.February, 3, 17, 03, 00, 0, time.UTC) + if nts.TimeStart != splitTime || nts.TimeEnd != nsplitTime { + t.Error("Incorrect first half", nts) + } + if nnts.TimeStart != nsplitTime || nnts.TimeEnd != t2 { + t.Error("Incorrect second half", nnts) + } + if nts.Interval != i { + t.Error("Interval not attached correctly") + } + + if nts.GetDuration().Seconds() != 120 || nnts.GetDuration().Seconds() != 60 { + t.Error("Wrong durations.for Intervals", nts.GetDuration().Seconds(), nnts.GetDuration().Seconds()) + } +}