TEST(Subsets, encode6) { // test the increment and decrement functions too const int n = 21; const int p = 7; const int n_choose_p = 116280; Subsets C(n,p); Subset a(p, 0); Subset b(p, 0); for (size_t i=0; i<p; i++) b[i] = i; for (size_t i=0; i<n_choose_p; i++) { C.decode(i, a); EXPECT_TRUE(sameSubset(a,b)); EXPECT_TRUE(C.isValid(a)); size_t j = C.encode(a); EXPECT_EQ(i,j); bool ret = Subsets::increment(n, b); EXPECT_EQ(ret, i+1 != n_choose_p); } }
TEST(Subsets, concatenateSubsets) { const int n = 7; const int p = 3; const int q = 2; const int n_choose_p = 35; Subsets C(n, std::max(p, q)); Subset a(p, 0); Subset b(q, 0); Subset c(p + q, 0); Subset d(p + q, 0); int sign; if ((p % 2 == 1) && (q % 2 == 1)) sign = -1; else sign = 1; for (size_t i = 0; i < n_choose_p; i++) { C.decode(i, a); EXPECT_TRUE(C.isValid(a)); for (size_t j = 0; j < n_choose_p; j++) { C.decode(j, b); EXPECT_TRUE(C.isValid(b)); int ret1 = Subsets::concatenateSubsets(a, b, c); int ret2 = Subsets::concatenateSubsets(b, a, d); if (ret1 == 0 || ret2 == 0) { EXPECT_EQ(ret1, ret2); break; } EXPECT_EQ(ret1, sign * ret2); EXPECT_TRUE(sameSubset(c, d)); } } }