Exemplo n.º 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;
}
Exemplo n.º 2
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;
}