static Value * builtin_set_new_powerset(Scope *args, MemorySpace *memspace) { Value *arg[] = { get_value_by_name(args, memspace, "0"), }; Value *rval = value_new(); value_set_set(rval, rf_set_new_powerset(arg[0]->as_Set)); return rval; }
void test_rf_set_new_powerset() { CU_FAIL_FATAL("not implemented"); char a[] = "a"; char b[] = "b"; char c[] = "c"; char *results[] = { " ", " ", " ", " ", " ", " ", " ", '\0' }; char *expected[] = { "a", "b", "c", "ab", "ac", "bc", "abc", '\0' }; rf_SetElement *elems[] = { rf_set_element_new_string(a), rf_set_element_new_string(b), rf_set_element_new_string(c), }; rf_Set *set1 = rf_set_new(3, elems); CU_ASSERT_TRUE(set1 != NULL); rf_Set *powerset = rf_set_new_powerset(set1); CU_ASSERT_EQUAL(powerset->cardinality, 8); /* for(int i = 0; i < 8; i++) { for(int j = 0; j < 3; j++) { results[i][j] = 0; } } */ for(int i = 0; i < powerset->cardinality; i++) { rf_SetElement *tmp1 = powerset->elements[i]; for(int j = 0; j < tmp1->value.set->cardinality; j++) { rf_SetElement *tmp2 = tmp1->value.set->elements[j]; if(tmp2 != NULL) { results[i][j] = *tmp2->value.string; } } // printf("### ^%s$\n", results[i]); } for(int i = 0; i < 8; i++) { bool contains = false; for(int j = 0; j < 3; j++) { if(strcmp(results[i], expected[j]) == 0) { printf("[%s|%s]\n", results[i], expected[i]); contains = true; } } CU_ASSERT_TRUE(contains); } rf_set_free(set1); rf_set_free(powerset); }