'Test that variables and constraints keep a consistent order.'

def test_consistency(self):

    import itertools
    num_solves = 4
    vars_lists = []
    ineqs_lists = []
    var_ids_order_created = []
    for k in range(num_solves):
        sum = 0
        constraints = []
        var_ids = []
        for i in range(100):
            var = Variable(name=str(i))
            var_ids.append(var.id)
            sum += var
            constraints.append((var >= i))
        var_ids_order_created.append(var_ids)
        obj = Minimize(sum)
        p = Problem(obj, constraints)
        (objective, constraints) = p.canonicalize()
        sym_data = SymData(objective, constraints, SOLVERS[s.ECOS])
        vars_ = sorted(sym_data.var_offsets.items(), key=(lambda key_val: key_val[1]))
        vars_ = [var_id for (var_id, offset) in vars_]
        vars_lists.append(vars_)
        ineqs_lists.append(sym_data.constr_map[s.LEQ])
    for i in range(num_solves):
        self.assertEqual(var_ids_order_created[i], vars_lists[i])
    for i in range(num_solves):
        for (idx, constr) in enumerate(ineqs_lists[i]):
            (var_id, _) = lu.get_expr_vars(constr.expr)[0]
            self.assertEqual(var_ids_order_created[i][idx], var_id)
