summaryrefslogtreecommitdiff
path: root/test/SegListTest.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-10-29 21:51:58 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-10-29 21:51:58 +0900
commit78c3bcd199bfe9113e2a17299d008d7fa464f38a (patch)
treef6a75ec3e098a4d9f035f91926314409c8dac0c9 /test/SegListTest.cc
parent695c65eb862e8f64eb8c64ce0a8c79e33ff67f9e (diff)
Added SegList<T>, replacement of Sequence<T>
Diffstat (limited to 'test/SegListTest.cc')
-rw-r--r--test/SegListTest.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/SegListTest.cc b/test/SegListTest.cc
new file mode 100644
index 00000000..d5d3819b
--- /dev/null
+++ b/test/SegListTest.cc
@@ -0,0 +1,66 @@
+#include "SegList.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace aria2 {
+
+class SegListTest:public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE(SegListTest);
+ CPPUNIT_TEST(testNext);
+ CPPUNIT_TEST(testNormalize);
+ CPPUNIT_TEST_SUITE_END();
+public:
+ void testNext();
+ void testNormalize();
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SegListTest);
+
+void SegListTest::testNext()
+{
+ SegList<int> sgl;
+ sgl.add(-500, -498);
+ sgl.add(5, 10);
+ sgl.add(1, 5);
+ for(int i = -500; i < -498; ++i) {
+ CPPUNIT_ASSERT(sgl.hasNext());
+ CPPUNIT_ASSERT_EQUAL(i, sgl.next());
+ }
+ for(int i = 5; i < 10; ++i) {
+ CPPUNIT_ASSERT(sgl.hasNext());
+ CPPUNIT_ASSERT_EQUAL(i, sgl.next());
+ }
+ for(int i = 1; i < 5; ++i) {
+ CPPUNIT_ASSERT(sgl.hasNext());
+ CPPUNIT_ASSERT_EQUAL(i, sgl.next());
+ }
+ CPPUNIT_ASSERT(!sgl.hasNext());
+ CPPUNIT_ASSERT_EQUAL(0, sgl.next());
+}
+
+void SegListTest::testNormalize()
+{
+ SegList<int> sgl;
+ sgl.add(10, 15);
+ sgl.add(0, 1);
+ sgl.add(1, 5);
+ sgl.add(14, 16);
+ sgl.add(2, 4);
+ sgl.add(20, 21);
+ sgl.normalize();
+ for(int i = 0; i < 5; ++i) {
+ CPPUNIT_ASSERT(sgl.hasNext());
+ CPPUNIT_ASSERT_EQUAL(i, sgl.next());
+ }
+ for(int i = 10; i < 16; ++i) {
+ CPPUNIT_ASSERT(sgl.hasNext());
+ CPPUNIT_ASSERT_EQUAL(i, sgl.next());
+ }
+ CPPUNIT_ASSERT(sgl.hasNext());
+ CPPUNIT_ASSERT_EQUAL(20, sgl.next());
+ CPPUNIT_ASSERT(!sgl.hasNext());
+}
+
+} // namespace aria2