Loading Common/Libraries/IRALibrary/include/FastQueue.h +4 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ public: * It construct the buffer with the specified number of elements. The array cannot be resized. * @param positions the size of the buffer. */ CFastQueue(const unsigned& positions) : m_positions(positions), m_head(0), m_end(0), m_array(NULL) CFastQueue(const unsigned& positions) : m_positions(positions+1), m_head(0), m_end(0), m_array(NULL) { m_array=new T[m_positions] ; } Loading @@ -39,18 +39,18 @@ public: * @return true is the queue is full */ inline bool isFull() const { return (m_head==((m_end+m_positions-1)%m_positions)); return (size()==m_positions-1); } /** * @return true is the queue is empty */ inline bool isEmpty() const { return (m_head==m_end); return (size()==0); } inline unsigned size() const { return (m_head-m_end)%m_positions; return (m_head-m_end+m_positions)%m_positions; } /** Loading Common/Libraries/IRALibrary/tests/FastQueue_test.i +41 −4 Original line number Diff line number Diff line Loading @@ -11,13 +11,50 @@ public: RecordProperty("description","check the limits of the queue"); IRA::CFastQueue<unsigned> queue(FASTQUEUE_SIZE); if (!queue.isEmpty()) ::testing::AssertionFailure() << " the container should be empty"; for (unsigned i=1;i<FASTQUEUE_SIZE;i++) { for (unsigned i=0;i<FASTQUEUE_SIZE;i++) { if (!queue.pushFront(i)) { return ::testing::AssertionFailure() << i << " element cannot be inserted"; return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } if (queue.size()!=i+1) { return ::testing::AssertionFailure() << " the size of the container is not expected"; } } if (queue.pushFront(1)) return ::testing::AssertionFailure() << " insertion should have failed because of container limits"; if (!queue.isFull()) return ::testing::AssertionFailure() << " ithe container should be full"; return ::testing::AssertionSuccess(); } ::testing::AssertionResult FastQueue_checkConsistency() { RecordProperty("description","check the data consistency of the queue"); IRA::CFastQueue<unsigned> queue(FASTQUEUE_SIZE); unsigned elem; // assign some elements for (unsigned i=0;i<1000;i++) { if (!queue.pushFront(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } } for (unsigned i=0;i<500;i++) { if (!queue.popBack(elem)) { return ::testing::AssertionFailure() << " element " << i << " cannot be extracted"; } if (elem!=i) { return ::testing::AssertionFailure() << " element " << i << " does not match with the inserted one"; } } for (unsigned i=1000;i<2000;i++) { if (!queue.pushFront(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } } for (unsigned i=500;i<2000;i++) { if (!queue.popBack(elem)) { return ::testing::AssertionFailure() << " element " << i << " cannot be extracted"; } if (elem!=i) { return ::testing::AssertionFailure() << " element " << i << " does not match with the inserted one"; } } if (queue.pushFront(1)) ::testing::AssertionFailure() << " insertion should have failed because of container limits"; if (queue.size()!=FASTQUEUE_SIZE) ::testing::AssertionFailure() << " the size of the container is not expected"; return ::testing::AssertionSuccess(); } Loading Common/Libraries/IRALibrary/tests/unittest.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -25,3 +25,7 @@ TEST_F(IRALibrary_IRATools, fileExists_checkNoExistance){ TEST_F(IRALibrary_FastQueue,FastQueue_checkLimits){ EXPECT_TRUE(FastQueue_checkLimits()); } TEST_F(IRALibrary_FastQueue,FastQueue_checkConsistency){ EXPECT_TRUE(FastQueue_checkConsistency()); } Loading
Common/Libraries/IRALibrary/include/FastQueue.h +4 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ public: * It construct the buffer with the specified number of elements. The array cannot be resized. * @param positions the size of the buffer. */ CFastQueue(const unsigned& positions) : m_positions(positions), m_head(0), m_end(0), m_array(NULL) CFastQueue(const unsigned& positions) : m_positions(positions+1), m_head(0), m_end(0), m_array(NULL) { m_array=new T[m_positions] ; } Loading @@ -39,18 +39,18 @@ public: * @return true is the queue is full */ inline bool isFull() const { return (m_head==((m_end+m_positions-1)%m_positions)); return (size()==m_positions-1); } /** * @return true is the queue is empty */ inline bool isEmpty() const { return (m_head==m_end); return (size()==0); } inline unsigned size() const { return (m_head-m_end)%m_positions; return (m_head-m_end+m_positions)%m_positions; } /** Loading
Common/Libraries/IRALibrary/tests/FastQueue_test.i +41 −4 Original line number Diff line number Diff line Loading @@ -11,13 +11,50 @@ public: RecordProperty("description","check the limits of the queue"); IRA::CFastQueue<unsigned> queue(FASTQUEUE_SIZE); if (!queue.isEmpty()) ::testing::AssertionFailure() << " the container should be empty"; for (unsigned i=1;i<FASTQUEUE_SIZE;i++) { for (unsigned i=0;i<FASTQUEUE_SIZE;i++) { if (!queue.pushFront(i)) { return ::testing::AssertionFailure() << i << " element cannot be inserted"; return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } if (queue.size()!=i+1) { return ::testing::AssertionFailure() << " the size of the container is not expected"; } } if (queue.pushFront(1)) return ::testing::AssertionFailure() << " insertion should have failed because of container limits"; if (!queue.isFull()) return ::testing::AssertionFailure() << " ithe container should be full"; return ::testing::AssertionSuccess(); } ::testing::AssertionResult FastQueue_checkConsistency() { RecordProperty("description","check the data consistency of the queue"); IRA::CFastQueue<unsigned> queue(FASTQUEUE_SIZE); unsigned elem; // assign some elements for (unsigned i=0;i<1000;i++) { if (!queue.pushFront(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } } for (unsigned i=0;i<500;i++) { if (!queue.popBack(elem)) { return ::testing::AssertionFailure() << " element " << i << " cannot be extracted"; } if (elem!=i) { return ::testing::AssertionFailure() << " element " << i << " does not match with the inserted one"; } } for (unsigned i=1000;i<2000;i++) { if (!queue.pushFront(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } } for (unsigned i=500;i<2000;i++) { if (!queue.popBack(elem)) { return ::testing::AssertionFailure() << " element " << i << " cannot be extracted"; } if (elem!=i) { return ::testing::AssertionFailure() << " element " << i << " does not match with the inserted one"; } } if (queue.pushFront(1)) ::testing::AssertionFailure() << " insertion should have failed because of container limits"; if (queue.size()!=FASTQUEUE_SIZE) ::testing::AssertionFailure() << " the size of the container is not expected"; return ::testing::AssertionSuccess(); } Loading
Common/Libraries/IRALibrary/tests/unittest.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -25,3 +25,7 @@ TEST_F(IRALibrary_IRATools, fileExists_checkNoExistance){ TEST_F(IRALibrary_FastQueue,FastQueue_checkLimits){ EXPECT_TRUE(FastQueue_checkLimits()); } TEST_F(IRALibrary_FastQueue,FastQueue_checkConsistency){ EXPECT_TRUE(FastQueue_checkConsistency()); }