def test_sum_min_max(self): a = Vector(1, 2, 3, 4, 5) # after initialisation expected_min = (1.0, 0) expected_max = (5.0, 4) expected_sum = 15 self.assertEqual(expected_min, a.min) self.assertEqual(expected_max, a.max) self.assertEqual(expected_sum, a.sum) # after changing a component a[1] = -2 expected_min = (-2.0, 1) expected_max = (5.0, 4) expected_sum = 11 self.assertEqual(expected_min, a.min) self.assertEqual(expected_max, a.max) self.assertEqual(expected_sum, a.sum) # after deletion a.pop(1) expected_min = (1.0, 0) expected_max = (5.0, 3) expected_sum = 13 self.assertEqual(expected_min, a.min) self.assertEqual(expected_max, a.max) self.assertEqual(expected_sum, a.sum) # after appending a scalar a.append(-2) expected_min = (-2.0, 4) expected_max = (5.0, 3) expected_sum = 11 self.assertEqual(expected_min, a.min) self.assertEqual(expected_max, a.max) self.assertEqual(expected_sum, a.sum) # after inserting a value a.insert(2, -20) expected_min = (-20.0, 2) expected_max = (5.0, 4) expected_sum = -9 self.assertEqual(expected_min, a.min) self.assertEqual(expected_max, a.max) self.assertEqual(expected_sum, a.sum) # after inserting a value at min position a.insert(2, -21) expected_min = (-21.0, 2) expected_max = (5.0, 5) expected_sum = -30 self.assertEqual(expected_min, a.min) self.assertEqual(expected_max, a.max) self.assertEqual(expected_sum, a.sum) # after inserting a value at max position a.insert(5, 10) expected_min = (-21.0, 2) expected_max = (10, 5) expected_sum = -20 self.assertEqual(expected_min, a.min) self.assertEqual(expected_max, a.max) self.assertEqual(expected_sum, a.sum) # after appending a sequence a.append([-22, 20, 1]) expected_min = (-22.0, 8) expected_max = (20.0, 9) expected_sum = -21.0 self.assertEqual(expected_min, a.min) self.assertEqual(expected_max, a.max) self.assertEqual(expected_sum, a.sum)
def test_insert(self): a = Vector(1, 2, 3) a.insert(1, 2) expected_a_after_insert = Vector(1, 2, 2, 3) self.assertEqual(expected_a_after_insert, a)