Kata Step Seven

Next test: We don’t really want to call Resume() on the consumer every time we enqueue an item. We only want to resume the consumer every time the queue goes from empty to one item.

BoundedQueueTest.cpp

TEST_F(BoundedQueueTest, EnqueueResumesConsumerOnFirstItemOnly) {
        EXPECT_CALL(consumer, Resume()).Times(1);
        q.enqueue(5);
        q.enqueue(5);
}

See if you can make this pass, or read on:











BoundedQueue.h

        void enqueue(const T& item) {
                q.push(item);
                if (q.size() == 1) {
                        consumer.Resume();
                }
        }

We have a green bar. 5 passing tests!

Go on to BoundedQueueKataStepEight.... or go back

BoundedQueueKataStepSeven (last edited 2010-01-17 00:50:01 by KayJohansen)