def update(self, *args, **kargs): left_list = args[0] right_list = args[1] if (self.begin > 0): since = SinceOperation() hist = HistoricallyBoundedOperation(0, self.begin) once = OnceBoundedOperation(self.begin, self.end) andop = AndOperation() out1 = once.update(right_list) out2 = since.update(left_list, right_list) out3 = hist.update(out2) out = andop.update(out1, out3) else: since = SinceOperation() once = OnceBoundedOperation(self.begin, self.end) andop = AndOperation() out1 = once.update(right_list) out2 = since.update(left_list, right_list) out = andop.update(out1, out2) return out
def test_historically_bounded(self): oper = HistoricallyBoundedOperation(0, 1) op = [[0, 4], [5, 2], [10, 5], [15, 3]] out = oper.update(op) expected = [[0, 4], [5, 2], [11, 5], [15, 3]] self.assertListEqual(expected, out, "historically[0,1] offline dense time 1") ####################################################################### oper = HistoricallyBoundedOperation(0, 1) op = [[0, 4], [5, 2], [10, 5], [15, 6]] out = oper.update(op) expected = [[0, 4], [5, 2], [11, 5], [15, 5]] self.assertListEqual(expected, out, "historically[0,1] offline dense time 2") ####################################################################### oper = HistoricallyBoundedOperation(0, 1) op = [] out = oper.update(op) expected = [] self.assertListEqual(expected, out, "historically[0,1] offline dense time 3") ####################################################################### oper = HistoricallyBoundedOperation(0, 1) op = [[2, 1]] out = oper.update(op) expected = [[2, 1]] self.assertListEqual(expected, out, "historically[0,1] offline dense time 4") ####################################################################### oper = HistoricallyBoundedOperation(0, 1) op = [[0, 4], [5, 6], [5.5, 3], [15, 6]] out = oper.update(op) expected = [[0, 4], [5.5, 3], [15, 3]] self.assertListEqual(expected, out, "historically[0,1] offline dense time 5") ####################################################################### oper = HistoricallyBoundedOperation(1, 2) op = [[0, 4], [5, 2], [10, 5], [15, 3]] out = oper.update(op) expected = [[0, float('inf')], [1, 4], [6, 2], [12, 5], [15, 5]] self.assertListEqual(expected, out, "historically[1,2] offline dense time 6") ####################################################################### oper = HistoricallyBoundedOperation(2, 2) op = [[0, 4], [5, 2], [10, 5], [15, 3]] out = oper.update(op) expected = [[0, float('inf')], [2, 4], [7, 2], [12, 5], [15, 5]] self.assertListEqual(expected, out, "historically[2,2] offline dense time 7") ####################################################################### oper = HistoricallyBoundedOperation(1, 2) op = [[0, 4], [5, 6], [5.1, 10], [5.2, 11], [5.3, 12], [5.5, 7], [15, 3]] out = oper.update(op) expected = [[0, float('inf')], [1, 4], [7, 6], [7.1, 7], [15, 7]] self.assertListEqual(expected, out, "historically[1,2] offline dense time 8") ####################################################################### oper = HistoricallyBoundedOperation(0, 1) op = [[0, 10], [5, 6], [7, 8], [7.5, 6], [15, 8]] out = oper.update(op) expected = [[0, 10], [5, 6], [15, 6]] self.assertListEqual(expected, out, "historically[0,1] offline dense time 9")
def test_historically_1_2(self): oper = HistoricallyBoundedOperation(1, 2) in_data = [[5, 3], [5.3, 1], [5.75, 2], [6.5, 5], [6.75, 6], [9, 5], [9.25, 4], [10, 2]] out_expected = [[6, 3], [6.3, 1], [7.75, 2], [8.5, 5], [8.75, 6], [10, 5], [10.25, 4], [12, 2]] out_computed = oper.update(in_data) self.assertListEqual(out_expected, out_computed, "Problem with 1st example:\nExpected output: %s\nComputed output: %s" % ( out_expected, out_computed)) in_data = [[0, 1], [0.5, 2], [1, 3], [1.5, 4], [2, 5]] out_expected = [[1, 1], [2.5, 2], [3, 3], [3.5, 4], [4, 5]] out_computed = oper.update(in_data) self.assertListEqual(out_expected, out_computed, "Problem with 2nd example:\nExpected output: %s\nComputed output: %s" % ( out_expected, out_computed)) in_data = [[0, 5], [0.5, 4], [1, 3], [1.5, 2], [2, 1]] out_expected = [[1, 5], [1.5, 4], [2, 3], [2.5, 2], [4, 1]] out_computed = oper.update(in_data) self.assertListEqual(out_expected, out_computed, "Problem with 3rd example:\nExpected output: %s\nComputed output: %s" % ( out_expected, out_computed)) in_data = [[5, 3], [5.3, 1], [5.75, 2], [6.5, 5], [6.75, 1], [9, 5], [9.25, 4], [10, 2]] out_expected = [[6, 3], [6.3, 1], [11, 4], [12, 2]] out_computed = oper.update(in_data) self.assertListEqual(out_expected, out_computed, "Problem with 4th example:\nExpected output: %s\nComputed output: %s" % ( out_expected, out_computed)) in_data = [[6, 2], [8, 1], [8.1, 2], [10, 3]] out_expected = [[7, 2], [9, 1], [10.1, 2], [12, 3]] out_computed = oper.update(in_data) self.assertListEqual(out_expected, out_computed, "Problem with 5th example:\nExpected output: %s\nComputed output: %s" % ( out_expected, out_computed)) in_data = [[6, 2], [8, 3], [8.1, 2], [10, 3]] out_expected = [[7, 2], [12, 3]] out_computed = oper.update(in_data) self.assertListEqual(out_expected, out_computed, "Problem with 6th example:\nExpected output: %s\nComputed output: %s" % ( out_expected, out_computed)) in_data = [] out_expected = [] out_computed = oper.update(in_data) self.assertListEqual(out_expected, out_computed, "Problem with 7th example:\nExpected output: %s\nComputed output: %s" % ( out_expected, out_computed)) in_data = [[2, 5]] out_expected = [] out_computed = oper.update(in_data) self.assertListEqual(out_expected, out_computed, "Problem with 8th example:\nExpected output: %s\nComputed output: %s" % ( out_expected, out_computed))