Пример #1
0
void LinkedHashSetTest::testRemove() {

    LinkedHashSet<int> set;
    populateSet(set);
    int size = set.size();
    set.remove(98);
    CPPUNIT_ASSERT_MESSAGE("Failed to remove element", !set.contains(98));
    CPPUNIT_ASSERT_MESSAGE("Failed to decrement set size", set.size() == size - 1);
}
Пример #2
0
void LinkedHashSetTest::testSize() {

    LinkedHashSet<int> set;
    populateSet(set);

    CPPUNIT_ASSERT_MESSAGE("Returned incorrect size", set.size() == SET_SIZE);
    set.clear();
    CPPUNIT_ASSERT_MESSAGE("Cleared set returned non-zero size", 0 == set.size());
}
Пример #3
0
void LinkedHashSetTest::testClear() {

    LinkedHashSet<int> set;
    populateSet(set);

    CPPUNIT_ASSERT(set.size() > 0);
    set.clear();
    CPPUNIT_ASSERT(set.size() == 0);
    CPPUNIT_ASSERT(!set.contains(1));
}
void OpenwireNonBlockingRedeliveryTest::testMessageRedeliveriesAreInOrder() {

    LinkedHashSet< Pointer<MessageId> > received;
    LinkedHashSet< Pointer<MessageId> > beforeRollback;
    LinkedHashSet< Pointer<MessageId> > afterRollback;

    const int MSG_COUNT = 100;
    const std::string destinationName = "testMessageDeleiveredWhenNonBlockingEnabled";

    destroyDestination(getBrokerURL(), destinationName);

    Pointer<ActiveMQConnectionFactory> connectionFactory(new ActiveMQConnectionFactory(getBrokerURL()));
    Pointer<Connection> connection(connectionFactory->createConnection());
    Pointer<Session> session(connection->createSession(Session::SESSION_TRANSACTED));
    Pointer<Destination> destination(session->createQueue(destinationName));
    Pointer<MessageConsumer> consumer(session->createConsumer(destination.get()));

    ReceivedListener receivedListener(&received);
    consumer->setMessageListener(&receivedListener);
    sendMessages(getBrokerURL(), destinationName, MSG_COUNT);

    connection->start();

    CPPUNIT_ASSERT_MESSAGE("Pre-Rollack received size incorrect", assertTrue(received, MSG_COUNT));

    beforeRollback.addAll(received);
    received.clear();
    session->rollback();

    CPPUNIT_ASSERT_MESSAGE("Post-Rollack received size incorrect", assertTrue(received, MSG_COUNT));

    afterRollback.addAll(received);
    received.clear();

    CPPUNIT_ASSERT_EQUAL(beforeRollback.size(), afterRollback.size());
    CPPUNIT_ASSERT(beforeRollback.equals(afterRollback));

    Pointer< Iterator<Pointer<MessageId> > > after(afterRollback.iterator());
    Pointer< Iterator<Pointer<MessageId> > > before(beforeRollback.iterator());

    while (before->hasNext() && after->hasNext()) {
        Pointer<MessageId> original = before->next();
        Pointer<MessageId> rolledBack = after->next();

        long long originalSeq = original->getProducerSequenceId();
        long long rolledbackSeq = rolledBack->getProducerSequenceId();

        CPPUNIT_ASSERT_EQUAL(originalSeq, rolledbackSeq);
    }

    session->commit();
    connection->close();
    destroyDestination(getBrokerURL(), destinationName);
}
Пример #5
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));
}
Пример #6
0
void LinkedHashSetTest::testConstructor() {

    LinkedHashSet<int> set;
    CPPUNIT_ASSERT(set.isEmpty());
    CPPUNIT_ASSERT_EQUAL(0, set.size());
    CPPUNIT_ASSERT_EQUAL(false, set.contains(1));
}
void OpenwireNonBlockingRedeliveryTest::testMessageDeleiveryDoesntStop() {

    LinkedHashSet< Pointer<MessageId> > received;
    LinkedHashSet< Pointer<MessageId> > beforeRollback;
    LinkedHashSet< Pointer<MessageId> > afterRollback;

    const int MSG_COUNT = 100;
    const std::string destinationName = "testMessageDeleiveryDoesntStop";

    destroyDestination(getBrokerURL(), destinationName);

    Pointer<ActiveMQConnectionFactory> connectionFactory(new ActiveMQConnectionFactory(getBrokerURL()));
    Pointer<Connection> connection(connectionFactory->createConnection());
    Pointer<Session> session(connection->createSession(Session::SESSION_TRANSACTED));
    Pointer<Destination> destination(session->createQueue(destinationName));
    Pointer<MessageConsumer> consumer(session->createConsumer(destination.get()));

    ReceivedListener receivedListener(&received);
    consumer->setMessageListener(&receivedListener);
    sendMessages(getBrokerURL(), destinationName, MSG_COUNT);

    connection->start();

    CPPUNIT_ASSERT_MESSAGE("Pre-Rollack received size incorrect", assertTrue(received, MSG_COUNT));

    beforeRollback.addAll(received);
    received.clear();
    session->rollback();

    sendMessages(getBrokerURL(), destinationName, MSG_COUNT);

    CPPUNIT_ASSERT_MESSAGE("Post-Rollack received size incorrect", assertTrue(received, MSG_COUNT * 2));

    afterRollback.addAll(received);
    received.clear();

    CPPUNIT_ASSERT_EQUAL(beforeRollback.size() * 2, afterRollback.size());
    session->commit();
    connection->close();

    destroyDestination(getBrokerURL(), destinationName);
}
Пример #8
0
void LinkedHashSetTest::testConstructorI() {

    LinkedHashSet<int> set;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Created incorrect LinkedHashSet", 0, set.size());

    try {
        LinkedHashSet<int> set(-1);
    } catch (IllegalArgumentException& e) {
        return;
    }

    CPPUNIT_FAIL("Failed to throw IllegalArgumentException for capacity < 0");
}
Пример #9
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;
    }
}
Пример #10
0
void LinkedHashSetTest::testCopy2() {

    LinkedList<int> collection;

    for (int i = 0; i < 50; ++i) {
        collection.add(i);
    }

    LinkedHashSet<int> set;

    set.copy(collection);

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

    for (int i = 0; i < 50; ++i) {
        CPPUNIT_ASSERT(set.contains(i));
    }

    CPPUNIT_ASSERT(set.equals(collection));
}
Пример #11
0
void LinkedHashSetTest::testRetainAll() {

    LinkedHashSet<int> set;
    populateSet(set, 3);

    ArrayList<int> collection;
    collection.add(1);
    collection.add(2);

    set.retainAll(collection);

    CPPUNIT_ASSERT_EQUAL(2, set.size());

    LinkedHashSet<int> set2;
    set2.retainAll(collection);
    CPPUNIT_ASSERT_EQUAL(0, set2.size());

    LinkedHashSet<int> set3;
    populateSet(set3, 3);
    collection.clear();

    set3.retainAll(collection);
    CPPUNIT_ASSERT_EQUAL(0, set3.size());
}
Пример #12
0
/*******************************************************************************

  Purpose - assumes that all corners with horizontal bisectors are at the same
  height(?), and that all faces that need to be merged, have been.

 *******************************************************************************/
void HeightCollision::processHoriz(Skeleton *skel)
{
    LinkedHashSet<Chain> chains;
    while (newHorizSet.size() > 0)
        chains.push_back(CoSitedCollision::buildChain2(newHorizSet.front(),
                    &newHorizSet));

    if (chains.size() == 0)
        return;

    /* if there are two lines of events at the same height (but different
     * lines), we need them to share their end points
     */
    IndirectLinkedHashSet<Corner *> intraface;
    for (LinkedHashSet<Chain>::iterator chainIt = chains.begin();
            chainIt != chains.end(); ++chainIt)
    {
        /* Naughty! But he does it in Java... they don't have const in Java, you
         * see, so things like this are unchecked.
         * -Tom
         */
        Chain &chain = (Chain &) *chainIt;

        vector<Edge *> priority;
        for (vector<Corner *>::iterator cIt = chain.chain.begin();
                cIt != chain.chain.end(); ++cIt)
        {
            Corner *c = *cIt;

            /* both edges are parallel---these are the only corners added to
             * newHoriz...
             */
            priority.push_back(c->nextL);
            priority.push_back(c->prevL);
        }

        /* find a set of coplanar edges that survive this transition in winners
         * (equal highest priority)
         */
        sort(priority.begin(), priority.end(),
                Skeleton::horizontalComparatorLT);
        IndirectLinkedHashSet<Edge *> winners;
        Edge *winner = priority.front(); priority.erase(priority.begin());
        winners.push_back(winner);
        while (!priority.empty() && Skeleton::horizontalComparator(winner, priority.front()) == 0)
        {
            winners.push_back(priority.front());
            priority.erase(priority.begin());
        }

        /* if first edge needs an additional corner---"if we're adding a cap at
         * the start" and "first isn't already an interface"
         */
        Corner *first = chain.chain.front();
        if (!winners.contains(first->prevL))
        {
            if (!intraface.contains(first->prevC)) // hasn't already been raised up by a previous chain
            {
                Corner *newFirst = GCNEW(Corner(Edge::collide(first->prevC,
                            first->z)));

                Edge *edgeArr[2];
                edgeArr[0] = first->prevL;
                edgeArr[1] = first->prevC->prevL;
                skel->output->addOutputSideTo(first->prevC, newFirst, 2,
                        edgeArr);
                Corner::replace(first->prevC, newFirst, skel);

                chain.chain.insert(chain.chain.begin(), newFirst);
                intraface.push_back(newFirst);
                first = newFirst;
            }
            else
                chain.chain.insert(chain.chain.begin(), first->prevC);
        }
        else
        {
            /* the edge before the first point is a winner, add it */
            chain.chain.insert(chain.chain.begin(), first = first->prevC);
        }
        Corner *last = chain.chain.at(chain.chain.size() - 1);
        /* if last edge needs an additional corner */
        if (!winners.contains(last->nextL))
        {
            if (!intraface.contains(last->nextC)) // hasn't already been raised up by a previous chain
            {
                Corner *newLast = GCNEW(Corner(Edge::collide(last->nextC,
                            last->z)));

                Edge *edgeArr[2];
                edgeArr[0] = last->nextL;
                edgeArr[1] = last->nextC->nextL;
                skel->output->addOutputSideTo(last->nextC, newLast, 2, edgeArr);
                Corner::replace(last->nextC, newLast, skel);

                chain.chain.push_back(newLast);
                intraface.push_back(newLast);
                last = newLast;
            }
            else
                chain.chain.push_back(last->nextC);
        }
        else
        {
            /* the edge after the last point is a winner, add it */
            chain.chain.push_back(last = last->nextC);
        }

        STLIterator<vector<Corner *> > stit(chain.chain);
        ConsecutivePairs<Corner *> pairIt(&stit, false);
        while (pairIt.hasNext())
        {
            tuple<Corner *, Corner *> *pair = pairIt.next();
            Corner *s = pair->get<0>();
            Corner *e = pair->get<1>();
            if (s->nextL != e->prevL)
                throw runtime_error("error! s->nextL != e->prevL");

            /* if this is he edge that spreads out all others */
            if (winners.contains(s->nextL))
            {
                if (s->nextL != winner)
                {
                    skel->output->merge(winner->start, s); // assumes start of edge forms part of its output
                }
                s->nextL->currentCorners.remove(e);
                s->nextL->currentCorners.remove(s);
            }
            else
            {
                /* this (section of this) edge ends at this height */
                s->nextL->currentCorners.remove(s);
                s->nextL->currentCorners.remove(e);

                Edge *edgeArr[2]; edgeArr[0] = s->nextL; edgeArr[1] = winner;
                skel->output->addOutputSideTo(s, e, 2, edgeArr);
            }

            skel->liveCorners.remove(s); // add in first and last below
            skel->liveCorners.remove(e);
        }

        skel->liveCorners.push_back(first);
        skel->liveCorners.push_back(last);

        winner->currentCorners.push_back(first);
        winner->currentCorners.push_back(last);

        first->nextC = last;
        last->prevC = first;
        first->nextL = winner;
        last->prevL = winner;

        for (vector<Corner *>::iterator it = chain.chain.begin();
                it != chain.chain.end(); ++it)
        {
            Corner *c = *it;
            if (c->nextL->currentCorners.size() == 0)
            {
                skel->liveEdges.remove(c->nextL);
            }
        }
    }

    /* no need to recalculate events---no faces added. wrong! any new
     * connectivity needs to be flagged as loop-of-two etc...
     */
    skel->qu->clearFaceEvents();

    /* See Skeleton::refindFaceEventsIfNeeded() for CloneConfirmIterator
     * shenanigans
     *
     * -Tom
     */
    IndirectLinkedHashSet<Corner *> bakLiveCorners;
    bakLiveCorners.insert(bakLiveCorners.end(), skel->liveCorners.begin(),
            skel->liveCorners.end());
    for (IndirectLinkedHashSet<Corner *>::iterator lcit =
            bakLiveCorners.begin(); lcit != bakLiveCorners.end(); ++lcit)
    {
        Corner *lc = *lcit;

        if (!skel->liveCorners.contains(lc))
        {
            cout << "*************DOES NOT CONTAIN!!!***********" << endl;
            continue;
        }
        skel->qu->addCorner(lc, this);
    }

    /* Just a check that my assumption that we don't /add/ to liveCorners
     * while iterating is correct.
     *
     * -Tom
     */
    for (IndirectLinkedHashSet<Corner *>::iterator lcit =
            skel->liveCorners.begin(); lcit != skel->liveCorners.end(); ++lcit)
    {
        Corner *lc = *lcit;
        if (!bakLiveCorners.contains(lc))
        {
            cout << "********liveCorners has but bakLiveCorners doesn't!: " <<
                lc << endl;
            assert(false);
        }
    }
}