Exemplo n.º 1
0
void LinkedHashSetTest::testAdd() {

    LinkedHashSet<int> set;
    populateSet(set);
    int size = set.size();

    set.add(8);
    CPPUNIT_ASSERT_MESSAGE("Added element already contained by set", set.size() == size);
    set.add(-9);
    CPPUNIT_ASSERT_MESSAGE("Failed to increment set size after add", set.size() == size + 1);
    CPPUNIT_ASSERT_MESSAGE("Failed to add element to set", set.contains(-9));
}
Exemplo n.º 2
0
void LinkedHashSetTest::testIsEmpty() {
    LinkedHashSet<int> set;
    CPPUNIT_ASSERT_MESSAGE("Empty set returned true", set.isEmpty());
    set.add(1);
    CPPUNIT_ASSERT_MESSAGE("Non-empty set returned true", !set.isEmpty());

    CPPUNIT_ASSERT_MESSAGE("Empty set returned false", LinkedHashSet<std::string>().isEmpty());
}
Exemplo n.º 3
0
void LinkedHashSetTest::testIterator() {

    LinkedHashSet<int> set;
    populateSet(set);
    Pointer< Iterator<int> > iter(set.iterator());
    // Tests that the LinkedHashSet iterates in order of insertion.
    for (int j = 0; iter->hasNext(); j++) {
        int value = iter->next();
        CPPUNIT_ASSERT_MESSAGE("Incorrect element found", value == j);
    }

    {
        LinkedHashSet<string> set;

        set.add( "fred1" );
        set.add( "fred2" );
        set.add( "fred3" );

        Iterator<string>* iterator1 = set.iterator();
        CPPUNIT_ASSERT( iterator1 != NULL );
        CPPUNIT_ASSERT( iterator1->hasNext() == true );

        int count = 0;
        while( iterator1->hasNext() ) {
            iterator1->next();
            ++count;
        }

        CPPUNIT_ASSERT( count == set.size() );

        Iterator<string>* iterator2 = set.iterator();

        while( iterator2->hasNext() ) {
            iterator2->next();
            iterator2->remove();
        }

        CPPUNIT_ASSERT( set.isEmpty() );

        delete iterator1;
        delete iterator2;
    }
}
TIMED_TEST(LinkedHashSetTests, hashcodeTest_LinkedHashSet, TEST_TIMEOUT_DEFAULT) {
    LinkedHashSet<int> hset;
    hset.add(69);
    hset.add(42);
    assertEqualsInt("hashcode of self LinkedHashSet", hashCode(hset), hashCode(hset));

    LinkedHashSet<int> hset2;
    hset2.add(42);
    hset2.add(69);
    assertEqualsInt("hashcode of LinkedHashSet other order", hashCode(hset), hashCode(hset2));

    LinkedHashSet<int> copy = hset;
    assertEqualsInt("hashcode of copy LinkedHashSet", hashCode(hset), hashCode(copy));

    LinkedHashSet<int> empty;
    HashSet<LinkedHashSet<int> > hashhashset {hset, copy, hset2, empty, empty};
    assertEqualsInt("hashset of LinkedHashset size", 2, hashhashset.size());
}