Esempio n. 1
0
static void test_bv_xor(TestCase *tc, void *data)
{
#   define XOR_SIZE 1000
    static const int xor_cnt = 500;
    BitVector *xor_bv;
    BitVector *bv1 = bv_new();
    BitVector *bv2 = bv_new();
    char set[XOR_SIZE];
    char set1[XOR_SIZE];
    char set2[XOR_SIZE];
    int i;
    int count = 0;
    (void)data;

    memset(set, 0, XOR_SIZE);
    memset(set1, 0, XOR_SIZE);
    memset(set2, 0, XOR_SIZE);
    for (i = 0; i < xor_cnt; i++) {
        int bit = rand() % XOR_SIZE;
        bv_set(bv1, bit);
        set1[bit] = 1;
    }
    for (i = 0; i < xor_cnt; i++) {
        int bit = rand() % XOR_SIZE;
        bv_set(bv2, bit);
        set2[bit] = 1;
    }
    for (i = 0; i < XOR_SIZE; i++) {
        if (set1[i] != set2[i]) {
            set[i] = 1;
            count++;
        }
    }

    xor_bv = bv_xor(bv1, bv2);

    Aiequal(count, xor_bv->count);
    for (i = 0; i < XOR_SIZE; i++) {
        if (!Aiequal(set[i], bv_get(xor_bv, i))) {
            Tmsg("At position %d, bv1 is %d and bv2 is %d\n", i,
                 bv_get(bv1, i), bv_get(bv2, i));
        }
    }

    bv1 = bv_xor_x(bv1, bv2);
    Assert(bv_eq(bv1, xor_bv), "BitVectors should be equal");

    bv_destroy(bv2);
    bv_destroy(xor_bv);

    bv2 = bv_new();
    xor_bv = bv_xor(bv1, bv2);

    Assert(bv_eq(bv1, xor_bv), "XORed BitVector equals bv1");

    bv_destroy(bv1);
    bv_destroy(bv2);
    bv_destroy(xor_bv);
}
Esempio n. 2
0
/*
 *  call-seq:
 *     bv1.xor!(bv2) -> self
 *  
 *  Perform a boolean _xor_ operation on +bv1+ and
 *  +bv2+ in place on +bv1+
 */
VALUE
frt_bv_xor_x(VALUE self, VALUE other)
{
    BitVector *bv1, *bv2;
    GET_BV(bv1, self);
    GET_BV(bv2, other);
    bv_xor_x(bv1, bv2);
    return self;
}