'Test negative indices.'

def test_neg_indices(self):

    c = Constant([[1, 2], [3, 4]])
    exp = c[((-1), (-1))]
    self.assertEqual(exp.value, 4)
    self.assertEqual(exp.size, (1, 1))
    self.assertEqual(exp.curvature, s.CONSTANT)
    c = Constant([1, 2, 3, 4])
    exp = c[1:(-1)]
    self.assertItemsAlmostEqual(exp.value, [2, 3])
    self.assertEqual(exp.size, (2, 1))
    self.assertEqual(exp.curvature, s.CONSTANT)
    c = Constant([1, 2, 3, 4])
    exp = c[::(-1)]
    self.assertItemsAlmostEqual(exp.value, [4, 3, 2, 1])
    self.assertEqual(exp.size, (4, 1))
    self.assertEqual(exp.curvature, s.CONSTANT)
    x = Variable(4)
    Problem(Minimize(0), [(x[::(-1)] == c)]).solve()
    self.assertItemsAlmostEqual(x.value, [4, 3, 2, 1])
    self.assertEqual(x[::(-1)].size, (4, 1))
    x = Variable(2)
    self.assertEqual(x[::(-1)].size, (2, 1))
    x = Variable(100, name='x')
    self.assertEqual('x[:-1,    0]', str(x[:(-1)]))
    c = Constant([[1, 2], [3, 4]])
    expr = c[0, 2:0:(-1)]
    self.assertEqual(expr.size, (1, 1))
    self.assertAlmostEqual(expr.value, 3)
    expr = c[0, 2::(-1)]
    self.assertEqual(expr.size, (1, 2))
    self.assertItemsAlmostEqual(expr.value, [3, 1])
