def test_reduce_sqr_diff(self): a = MatrixPointer([1, 2, 3, 4], (2, 2)) b = MatrixPointer([4, 3, 2, 1], (2, 2)) c = a.reduce(lambda accumulator, x, y: accumulator + (x - y)**2, 0, b) self.assertEqual(c, 20)
def test_reduce_sum(self): a = MatrixPointer([1, 2, 3, 4], (2, 2)) b = MatrixPointer([4, 3, 2, 1], (2, 2)) c = a.reduce(lambda accumulator, x, y: accumulator + x + y, 0, b) self.assertEqual(c, sum([5]*4))