Пример #1
0
void Test_Realm::clear() {
    Realm realm;
    realm.push_back(1);

    realm.clear();

    QVERIFY(realm.size() == 0);
    QVERIFY(realm.dimension() == 0);
}
Пример #2
0
/** \todo rewrite to make independent of realm_container_type::operator[] */
bool Realm::operator==(const Realm &other) const {

    if (dimension() != other.dimension()) return false;

    if (dimension() == 0) return (toIndex() == other.toIndex());

    if (_subrealm.size() != other._subrealm.size()) return false;

    /* comparing _subrealm to other._subrealm does not always return true, even
     * if the elements are equal. doing it manually. */
    for (unsigned i = 0; i < _subrealm.size(); ++i) {
        if (!(_subrealm[i] == other._subrealm[i])) return false;
    }

    return true;
}
Пример #3
0
void Test_Realm::push_back() {
    Realm realm;
    realm.push_back(1);
    realm.push_back(2);

    QVERIFY(realm.contains(1));
    QVERIFY(realm.contains(2));
    QVERIFY(realm.dimension() == 1);

    try {
        realm.push_back(realm);
    } catch (std::invalid_argument e) {
        return;
    }
    QFAIL("Expected invalid_argument");
}
Пример #4
0
bool Realm::contains(const Realm &other) const {

    if (std::find(_subrealm.begin(), _subrealm.end(), other) != _subrealm.end()) {
        return true;
    }

    if (other.dimension() < dimension()) {
        for (realm_container_type::const_iterator i = _subrealm.begin();
             i != _subrealm.end(); ++i) {
            if (i->contains(other)) {
                return true;
            }
        }
    }

    return false;
}