Skip to content

Commit

Permalink
Fixed assertion location
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hader committed May 29, 2024
1 parent 4f1235d commit b1153d2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/polynomial/feasibility_set_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,11 @@ void lp_feasibility_set_int_invert(lp_feasibility_set_int_t *set) {
long lb = lp_integer_to_int(&set->K->lb);
long ub = lp_integer_to_int(&set->K->ub);
for (long val = lb; val <= ub; ++val) {
assert(pos_new < cnt);
assert(pos_old >= set->size || lp_integer_cmp_int(lp_Z, old + pos_old, val) >= 0);
if (pos_old < set->size && lp_integer_cmp_int(lp_Z, old + pos_old, val) == 0) {
++ pos_old;
} else {
assert(pos_new < cnt);
lp_integer_construct_from_int(lp_Z, new + pos_new, val);
++ pos_new;
}
Expand Down
49 changes: 49 additions & 0 deletions test/poly/test_feasible_int_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,55 @@ TEST_CASE("feasibility_set_int::intersect") {
CHECK_EQ(K.get_internal()->ref_count, 1);
}

TEST_CASE("feasibility_set_int::intersect_wrap_around") {
Integer prime(3);
IntegerRing K(prime, true);

lp_feasibility_set_int_t *set1 = integer_list({1,-1}).gen_set(K, false);
lp_feasibility_set_int_t *set2 = integer_list({-1}).gen_set(K, false);
lp_feasibility_set_int_t *set1_inv = integer_list({0}).gen_set(K, true);
lp_feasibility_set_int_t *set2_inv = integer_list({0,1}).gen_set(K, true);

SUBCASE("feasibility_set_int::intersect_wrap_around1") {
lp_feasibility_set_int_status_t status;
lp_feasibility_set_int_t *s = lp_feasibility_set_int_intersect_with_status(set1, set2, &status);
CHECK(lp_feasibility_set_int_size_approx(s) == 1);
CHECK(status == LP_FEASIBILITY_SET_INT_S2);
CHECK(lp_feasibility_set_int_contains(s, Integer(K, -1).get_internal()));
lp_feasibility_set_int_delete(s);
}
SUBCASE("feasibility_set_int::intersect_wrap_around2") {
lp_feasibility_set_int_status_t status;
lp_feasibility_set_int_t *s = lp_feasibility_set_int_intersect_with_status(set1, set2_inv, &status);
CHECK(lp_feasibility_set_int_size_approx(s) == 1);
CHECK(status == LP_FEASIBILITY_SET_INT_S2);
CHECK(lp_feasibility_set_int_contains(s, Integer(K, -1).get_internal()));
lp_feasibility_set_int_delete(s);
}
SUBCASE("feasibility_set_int::intersect_wrap_around3") {
lp_feasibility_set_int_status_t status;
lp_feasibility_set_int_t *s = lp_feasibility_set_int_intersect_with_status(set1_inv, set2, &status);
CHECK(lp_feasibility_set_int_size_approx(s) == 1);
CHECK(status == LP_FEASIBILITY_SET_INT_S2);
CHECK(lp_feasibility_set_int_contains(s, Integer(K, -1).get_internal()));
lp_feasibility_set_int_delete(s);
}
SUBCASE("feasibility_set_int::intersect_wrap_around2") {
lp_feasibility_set_int_status_t status;
lp_feasibility_set_int_t *s = lp_feasibility_set_int_intersect_with_status(set1_inv, set2_inv, &status);
CHECK(lp_feasibility_set_int_size_approx(s) == 1);
CHECK(status == LP_FEASIBILITY_SET_INT_S2);
CHECK(lp_feasibility_set_int_contains(s, Integer(K, -1).get_internal()));
lp_feasibility_set_int_delete(s);
}

lp_feasibility_set_int_delete(set1);
lp_feasibility_set_int_delete(set1_inv);
lp_feasibility_set_int_delete(set2);
lp_feasibility_set_int_delete(set2_inv);
CHECK_EQ(K.get_internal()->ref_count, 1);
}

TEST_CASE("feasibility_set_int::intersect_empty") {
Integer prime(7);
IntegerRing K(prime, true);
Expand Down

0 comments on commit b1153d2

Please sign in to comment.