Beispiel #1
0
bool testPhongTran2() {
    cout << "[testing PhongTran2]" << endl;
    bool isOk(true);
    uword iTotal = static_cast<uword> (1000); // when 1000 does not fit in uword, then it will be casted
    EWAHBoolArray<uword> myarray;
    for (uword x = static_cast<uword> (100); x < iTotal; x++) {
        myarray.addWord(x);
    }
    string indexfile("testingewahboolarray.bin");
    ::remove(indexfile.c_str());
    ofstream out(indexfile.c_str(), ios::out | ios::binary);
    myarray.write(out);
    out.close();
    EWAHBoolArray<uword> lmyarray;
    ifstream in(indexfile.c_str(), ios::binary);
    lmyarray.read(in);
    in.close();
    if (!(myarray == lmyarray)) {
        cout << "bad news, they are not equal" << endl;
        cout << "size in bits: " << myarray.sizeInBits() << " vs. "
             << lmyarray.sizeInBits() << endl;
        isOk = false;
    }
    EWAHBoolArrayIterator<uword> i = myarray.uncompress();
    EWAHBoolArrayIterator<uword> j = lmyarray.uncompress();
    while (i.hasNext()) {
        if (!j.hasNext()) {
            cout << "the two arrays don't have the same size?" << endl;
            isOk = false;
            break;
        }
        uword val = i.next();
        uword val2 = j.next();
        if (val != val2) {
            cout << "the two arrays differ " << endl;
            isOk = false;
        }
    }
    if (isOk)
        ::remove(indexfile.c_str());
    if (!isOk)
        cout << testfailed << endl;
    return isOk;
}
Beispiel #2
0
// unit test contributed by Phong Tran
bool testPhongTran() {
    cout << "[testing PhongTran]" << endl;
    bool isOk(true);
    EWAHBoolArray<uint32_t> myarray;
    for (uint32_t x = 0; x < 10000; x++) {
        myarray.addWord(x);
    }
    string indexfile("testingewahboolarray.bin");
    ::remove(indexfile.c_str());
    ofstream out(indexfile.c_str(), ios::out | ios::binary);
    myarray.write(out);
    out.close();
    EWAHBoolArray<uint32_t> lmyarray;
    ifstream in(indexfile.c_str(), ios::binary);
    lmyarray.read(in);
    in.close();
    EWAHBoolArrayIterator<uint32_t> i = myarray.uncompress();
    EWAHBoolArrayIterator<uint32_t> j = lmyarray.uncompress();
    while (i.hasNext() or j.hasNext()) {
        if ((!j.hasNext()) or (!i.hasNext())) {
            cout << "the two arrays don't have the same size?" << endl;
            isOk = false;
            break;
        }
        uint32_t val = i.next();
        uint32_t val2 = j.next();
        if (val != val2) {
            cout << "the two arrays differ" << endl;
            isOk = false;
            break;
        }
    }

    if (isOk)
        ::remove(indexfile.c_str());
    if (!isOk)
        cout << testfailed << endl;
    return isOk;
}
Beispiel #3
0
bool testEWAHBoolArrayLogical() {
    cout << "[testing EWAHBoolArrayLogical] word size = "<< sizeof(uword) << endl;
    bool isOk(true);
    EWAHBoolArray<uword> myarray1;
    EWAHBoolArray<uword> myarray2;

    uword allones =  static_cast<uword> (~0LL);
    const uint32_t N = 16;
    uword x1[N] = { 1, 0, 54, 24, 145, 0, 0, 0, allones,
                    allones,allones,
                    43, 0, 0, 0, 1
                  };
    uword x2[N] = { allones, 1, 0, 0, 0, 0, 0, 0, 0,
                    allones,
                    allones, allones, 0,4, 0, 0
                  };
    uword xand[N];
    uword xxor[N];
    size_t usedN = 10;
    if(sizeof(uword)>2) return true;

    for (uint32_t k = 0; k < usedN; ++k) {
        myarray1.addWord(x1[k]);
        myarray2.addWord(x2[k]);
        xand[k] = static_cast<uword>(x1[k] & x2[k]);
        xxor[k] = static_cast<uword>(x1[k] | x2[k]);
    }
    EWAHBoolArray<uword> myand;
    EWAHBoolArray<uword> myor;
    EWAHBoolArray<uword> myxor;
    EWAHBoolArray<uword> myxoralt;

    myarray1.logicaland(myarray2, myand);
    myarray1.logicalor(myarray2, myor);
    myarray1.logicalxor(myarray2, myxor);
    EWAHBoolArray<uword> tmp(myand);
    tmp.inplace_logicalnot();
    myor.logicaland(tmp, myxoralt);
    if(myxoralt != myxor) {
        isOk = false;
        if (!isOk)
            cout << testfailed << endl;
        return isOk;
    }

    EWAHBoolArrayIterator<uword> i = myand.uncompress();
    EWAHBoolArrayIterator<uword> j = myor.uncompress();
    EWAHBoolArrayIterator<uword> it1 = myarray1.uncompress();
    EWAHBoolArrayIterator<uword> it2 = myarray2.uncompress();
    for (uint32_t k = 0; k < usedN; ++k) {
        const uword m1 = it1.next();
        const uword m2 = it2.next();
        if (!i.hasNext()) {
            if((m1 & m2) != 0) {
                cout << "type 1 error" << endl;
                isOk = false;
                break;
            }
        } else {
            const uword inter = i.next();
            if (inter != xand[k]) {
                cout << "type 4 error" << endl;
                isOk = false;
                break;
            }
        }
        if (!j.hasNext()) {
            if((m1 | m2) != 0) {
                cout << "type 3 error" << endl;
                isOk = false;
                break;
            }
        } else {
            const uword jor = j.next();
            if (jor != xxor[k]) {
                cout << "type 6 error OR" << endl;
                isOk = false;
                break;
            }
        }

    }
    if (!isOk)
        cout << testfailed << endl;
    return isOk;
}
Beispiel #4
0
bool testEWAHBoolArray() {
    cout << "[testing EWAHBoolArray]" << endl;
    bool isOk(true);
    EWAHBoolArray<uword> myarray;
    BoolArray<uword> ba(10 * sizeof(uword) * 8);
    uword zero = 0;
    uword notzero = static_cast<uword> (~zero);
    myarray.addWord(zero);
    ba.setWord(0, zero);
    myarray.addWord(zero);
    ba.setWord(1, zero);
    myarray.addWord(zero);
    ba.setWord(2, zero);
    uword specialval = 1UL + (1UL << 4) + (static_cast<uword> (1)
                                           << (sizeof(uword) * 8 - 1));
    myarray.addWord(specialval);
    ba.setWord(3, specialval);
    myarray.addWord(notzero);
    ba.setWord(4, notzero);
    myarray.addWord(notzero);
    ba.setWord(5, notzero);
    myarray.addWord(notzero);
    ba.setWord(6, notzero);
    myarray.addWord(notzero);
    ba.setWord(7, notzero);
    myarray.addWord(specialval);
    ba.setWord(8, specialval);
    myarray.addWord(zero);
    ba.setWord(9, zero);
    if (myarray.sizeInBits() != 10 * sizeof(uword) * 8) {
        cout << "expected " << 10 * sizeof(uword) * 8 << " bits but found "
             << myarray.sizeInBits() << endl;
        isOk = false;
    }
    string indexfile("testingewahboolarray.bin");
    ::remove(indexfile.c_str());
    ofstream out(indexfile.c_str(), ios::out | ios::binary);
    myarray.write(out);
    out.close();
    EWAHBoolArray<uword> lmyarray;
    ifstream in(indexfile.c_str(), ios::binary);
    lmyarray.read(in);
    in.close();
    if (!(myarray == lmyarray)) {
        cout << "bad news, they are not equal" << endl;
        cout << "size in bits: " << myarray.sizeInBits() << " vs. "
             << lmyarray.sizeInBits() << endl;
        isOk = false;
    }
    EWAHBoolArrayIterator<uword> i = myarray.uncompress();
    EWAHBoolArrayIterator<uword> j = lmyarray.uncompress();
    uint32_t k = 0;
    while (i.hasNext()) {
        if (!j.hasNext()) {
            cout << "the two arrays don't have the same size?" << endl;
            isOk = false;
            break;
        }
        uword val = i.next();
        uword val2 = j.next();
        uword valref = ba.getWord(k++);
        if (val != valref) {
            cout << "the two arrays differ from uncompressed array at " << k
                 << " " << val << " " << val2 << " " << valref << endl;
            isOk = false;
        }
        if (val != val2) {
            cout << "the two arrays differ at " << k << " " << val << " "
                 << val2 << " " << valref << endl;
            isOk = false;
        }
    }
    if (isOk)
        ::remove(indexfile.c_str());
    if (!isOk)
        cout << testfailed << endl;
    return isOk;
}