Beispiel #1
0
void algebraicTests(void) {
	Set empty;
	Set universal;
	int i;
	Set s;
	Set t;
	Set u;
	Set v;
	Set w;
	
	createEmptySet(&empty);
	createEmptySet(&universal);
	for (i = 0; i < maximum_set_size; i += 1) {
		insertSet(&universal, i);
	}
	
	createEmptySet(&s);
	createEmptySet(&t);
	createEmptySet(&u);
	createEmptySet(&v);
	createEmptySet(&w);

	for (i = 0; i < number_of_tests; i += 1) {
		randomSet(&u);
		randomSet(&v);
		randomSet(&w);
	  
		/* u + v == v + u */
		assignSet(&s, &u);
		unionInSet(&s, &v);
		assignSet(&t, &v);
		unionInSet(&t, &u);
		assert(isEqualToSet(&s, &t));
			
		/* u + (v + w) == (u + v) + w */	  
		assignSet(&t, &v);
		unionInSet(&t, &w);
		assignSet(&s, &u);
		unionInSet(&s, &t);
		assignSet(&t, &u);
		unionInSet(&t, &v);
		unionInSet(&t, &w);
		assert(isEqualToSet(&s, &t));

		/* u * v == v * u */
		assignSet(&s, &u);
		intersectFromSet(&s, &v);
		assignSet(&t, &v);
		intersectFromSet(&t, &u);
		assert(isEqualToSet(&s, &t));

		/* u * (v * w) == (u * v) * w */	  
		assignSet(&t, &v);
		intersectFromSet(&t, &w);
		assignSet(&s, &u);
		intersectFromSet(&s, &t);
		assignSet(&t, &u);
		intersectFromSet(&t, &v);
		intersectFromSet(&t, &w);
		assert(isEqualToSet(&s, &t));

		/* u - v == u - (u * v) */
		assignSet(&s, &u);
		intersectFromSet(&s, &v);
		assignSet(&t, &u);
		subtractFromSet(&t, &s);
		assignSet(&s, &u);
		subtractFromSet(&s, &v);
		assert(isEqualToSet(&s, &t));

		/* additional tests, not implemented 
	  assert(w * (u - v) == w * u - w * v);
	  assert(u * (v + w) == (u * v) + (u * w));
	  assert(universal - (u * v) == (universal - u) + (universal - v));
	  assert(universal - (u + v) == (universal - u) * (universal - v)); 
	  */
	}
	printf("The algebraic tests have been passed\n"); 
	destroySet(&empty);
	destroySet(&universal);
	destroySet(&s);
	destroySet(&t);
	destroySet(&u);
	destroySet(&v);
	destroySet(&w);
}
Beispiel #2
0
void intersectTimeFun(void) {
	Set t;
	createCopySet(&t, setA);
	intersectFromSet(&t, setB);
	destroySet(&t);
}
Beispiel #3
0
TEST(Test07, AlgebraicTests)
{
    {
        Set empty;
        Set universal;
        Set r;
        Set s;
        Set t;
        Set u;
        Set v;
        Set w;
        int i;

        createEmptySet(&empty);
        createEmptySet(&universal);

        for (i = 0; i < MAX_SET_SIZE; i++)
        {
            insertSet(&universal, i);
        }

        createEmptySet(&r);
        createEmptySet(&s);
        createEmptySet(&t);
        createEmptySet(&u);
        createEmptySet(&v);
        createEmptySet(&w);

        ASSERT_FALSE(isEqualToSet(&empty, &universal));

        for (i = 0; i < NUM_TESTS; i++)
        {
            randomSet(&u);
            randomSet(&v);
            randomSet(&w);

            /* w * (u - v) == w * u - w * v */
            assignSet(&s, &u);
            subtractFromSet(&s, &v);
            assignSet(&r, &w);
            intersectFromSet(&r, &s);
            assignSet(&t, &w);
            intersectFromSet(&t, &v);
            assignSet(&s, &w);
            intersectFromSet(&s, &u);
            subtractFromSet(&s, &t);
            ASSERT_TRUE(isEqualToSet(&r, &s));

            /* u * (v + w) == (u * v) + (u * w) */
            assignSet(&s, &v);
            unionInSet(&s, &w);
            assignSet(&r, &u);
            intersectFromSet(&r, &s);
            assignSet(&t, &u);
            intersectFromSet(&t, &w);
            assignSet(&s, &u);
            intersectFromSet(&s, &v);
            unionInSet(&s, &t);
            ASSERT_TRUE(isEqualToSet(&r, &s));

            /* universal - (u * v) == (universal - u) + (universal - v) */
            assignSet(&s, &u);
            intersectFromSet(&s, &v);
            assignSet(&r, &universal);
            subtractFromSet(&r, &s);
            assignSet(&t, &universal);
            subtractFromSet(&t, &v);
            assignSet(&s, &universal);
            subtractFromSet(&s, &u);
            unionInSet(&s, &t);
            ASSERT_TRUE(isEqualToSet(&r, &s));

            /* universal - (u + v) == (universal - u) * (universal - v) */
            assignSet(&s, &u);
            unionInSet(&s, &v);
            assignSet(&r, &universal);
            subtractFromSet(&r, &s);

            assignSet(&t, &universal);
            subtractFromSet(&t, &v);
            assignSet(&s, &universal);
            subtractFromSet(&s, &u);
            intersectFromSet(&s, &t);
            ASSERT_TRUE(isEqualToSet(&r, &s));
        }

        destroySet(&empty);
        destroySet(&universal);
        destroySet(&r);
        destroySet(&s);
        destroySet(&t);
        destroySet(&u);
        destroySet(&v);
        destroySet(&w);
    }
}