'Test gradient for quad_over_lin'

def test_quad_over_lin(self):

    expr = quad_over_lin(self.x, self.a)
    self.x.value = [1, 2]
    self.a.value = 2
    self.assertItemsAlmostEqual(expr.grad[self.x].todense(), [1, 2])
    self.assertAlmostEqual(expr.grad[self.a], [(-1.25)])
    self.a.value = 0
    self.assertAlmostEqual(expr.grad[self.x], None)
    self.assertAlmostEqual(expr.grad[self.a], None)
    expr = quad_over_lin(self.A, self.a)
    self.A.value = np.eye(2)
    self.a.value = 2
    self.assertItemsAlmostEqual(expr.grad[self.A].todense(), [1, 0, 0, 1])
    self.assertAlmostEqual(expr.grad[self.a], [(-0.5)])
    expr = (quad_over_lin(self.x, self.a) + quad_over_lin(self.y, self.a))
    self.x.value = [1, 2]
    self.a.value = 2
    self.y.value = [1, 2]
    self.a.value = 2
    self.assertItemsAlmostEqual(expr.grad[self.x].todense(), [1, 2])
    self.assertItemsAlmostEqual(expr.grad[self.y].todense(), [1, 2])
    self.assertAlmostEqual(expr.grad[self.a], [(-2.5)])
