Пример #1
0
void test_rf_set_new_intersection() {
	char *a = "a";
	char *b = "b";
	char *c = "c";

	rf_SetElement *elems1[3] = {
		rf_set_element_new_string(a),
		rf_set_element_new_string(b),
		rf_set_element_new_string(c),
	};

	rf_SetElement *elems2[2] = {
		rf_set_element_new_string(b),
		rf_set_element_new_string(c),
	};

	rf_Set *set1 = rf_set_new(3, elems1);
	rf_Set *set2 = rf_set_new(2, elems2);

	rf_Set *result = rf_set_new_intersection(set1, set2);

	CU_ASSERT_EQUAL(result->cardinality, 2);
	CU_ASSERT_TRUE(rf_set_contains_element(result, elems2[0]));
	CU_ASSERT_TRUE(rf_set_contains_element(result, elems2[1]));

	rf_set_free(set1);
	rf_set_free(set2);
	rf_set_free(result);
}
Пример #2
0
static
Value *
builtin_set_new_intersection(Scope *args, MemorySpace *memspace) {
	Value *arg[] = {
		get_value_by_name(args, memspace, "0"),
		get_value_by_name(args, memspace, "1"),
	};
	Value *rval = value_new();

	value_set_set(rval, rf_set_new_intersection(arg[0]->as_Set, arg[1]->as_Set));

	return rval;
}