diff options
author | Johannes Schickel | 2008-09-01 16:52:09 +0000 |
---|---|---|
committer | Johannes Schickel | 2008-09-01 16:52:09 +0000 |
commit | 2db5747642446bad3e1824afd0358f51c1965c20 (patch) | |
tree | 90a0ddc2bba1d44c53f7c375c4b7a51f46f57a2e /test/common | |
parent | c2f2269852c817ccbe43141820896455ee1d3854 (diff) | |
download | scummvm-rg350-2db5747642446bad3e1824afd0358f51c1965c20.tar.gz scummvm-rg350-2db5747642446bad3e1824afd0358f51c1965c20.tar.bz2 scummvm-rg350-2db5747642446bad3e1824afd0358f51c1965c20.zip |
- Added tests for newly added Common::Queue
- Changed Common::Queue::front and Common::Queue::back to return references instead of values
svn-id: r34240
Diffstat (limited to 'test/common')
-rw-r--r-- | test/common/queue.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/common/queue.h b/test/common/queue.h new file mode 100644 index 0000000000..7eedec9a5d --- /dev/null +++ b/test/common/queue.h @@ -0,0 +1,80 @@ +#include <cxxtest/TestSuite.h> + +#include "common/queue.h" + +class QueueTestSuite : public CxxTest::TestSuite { +public: + void test_empty_clear() { + Common::Queue<int> queue; + TS_ASSERT(queue.empty()); + + queue.push(1); + queue.push(2); + TS_ASSERT(!queue.empty()); + + queue.clear(); + + TS_ASSERT(queue.empty()); + } + + void test_size() { + Common::Queue<int> queue; + TS_ASSERT_EQUALS(queue.size(), 0); + + queue.push(5); + TS_ASSERT_EQUALS(queue.size(), 1); + + queue.push(9); + queue.push(0); + TS_ASSERT_EQUALS(queue.size(), 3); + + queue.pop(); + TS_ASSERT_EQUALS(queue.size(), 2); + } + + void test_front_back_pop() { + Common::Queue<int> queue; + + queue.push( 42); + queue.push(-23); + + TS_ASSERT_EQUALS(queue.front(), 42); + TS_ASSERT_EQUALS(queue.back(), -23); + + queue.front() = -23; + queue.back() = 42; + TS_ASSERT_EQUALS(queue.front(), -23); + TS_ASSERT_EQUALS(queue.back(), 42); + + queue.pop(); + TS_ASSERT_EQUALS(queue.front(), 42); + } + + void test_assign() { + Common::Queue<int> q1, q2; + + for (int i = 0; i < 5; ++i) { + q1.push(i); + q2.push(4-i); + } + + Common::Queue<int> q3(q1); + + for (int i = 0; i < 5; ++i) { + TS_ASSERT_EQUALS(q3.front(), i); + q3.pop(); + } + + TS_ASSERT(q3.empty()); + + q3 = q2; + + for (int i = 4; i >= 0; --i) { + TS_ASSERT_EQUALS(q3.front(), i); + q3.pop(); + } + + TS_ASSERT(q3.empty()); + } +}; + |