1*31682d32SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*31682d32SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*31682d32SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*31682d32SAndrew Rist * distributed with this work for additional information 6*31682d32SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*31682d32SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*31682d32SAndrew Rist * "License"); you may not use this file except in compliance 9*31682d32SAndrew Rist * with the License. You may obtain a copy of the License at 10*31682d32SAndrew Rist * 11*31682d32SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*31682d32SAndrew Rist * 13*31682d32SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*31682d32SAndrew Rist * software distributed under the License is distributed on an 15*31682d32SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*31682d32SAndrew Rist * KIND, either express or implied. See the License for the 17*31682d32SAndrew Rist * specific language governing permissions and limitations 18*31682d32SAndrew Rist * under the License. 19*31682d32SAndrew Rist * 20*31682d32SAndrew Rist *************************************************************/ 21*31682d32SAndrew Rist 22*31682d32SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "preextstl.h" 25cdf0e10cSrcweir #include "cppunit/TestAssert.h" 26cdf0e10cSrcweir #include "cppunit/TestFixture.h" 27cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h" 28cdf0e10cSrcweir #include "postextstl.h" 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <o3tl/range.hxx> 31cdf0e10cSrcweir #include <vector> 32cdf0e10cSrcweir #include <deque> 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir using o3tl::range; 37cdf0e10cSrcweir using o3tl::make_range; 38cdf0e10cSrcweir using o3tl::range_of; 39cdf0e10cSrcweir using std::size_t; 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir class range_test : public CppUnit::TestFixture 43cdf0e10cSrcweir { 44cdf0e10cSrcweir public: 45cdf0e10cSrcweir 46cdf0e10cSrcweir void int_test() 47cdf0e10cSrcweir { 48cdf0e10cSrcweir range<int> 49cdf0e10cSrcweir t1(12,88); 50cdf0e10cSrcweir range<int> 51cdf0e10cSrcweir t2(33,33); 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ctor 54cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int ctor1", t1.begin() == 12); 55cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int ctor2", t1.end() == 88); 56cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int ctor3", t2.begin() == 33); 57cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int ctor4", t2.end() == 33); 58cdf0e10cSrcweir 59cdf0e10cSrcweir // make_range 60cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int make_range1", make_range(0,8).begin() == 0); 61cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int make_range2", make_range(0,8).end() == 8); 62cdf0e10cSrcweir 63cdf0e10cSrcweir // size 64cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int size1", t1.size() == size_t(t1.end() - t1.begin()) ); 65cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int size2", t2.size() == size_t(0) ); 66cdf0e10cSrcweir 67cdf0e10cSrcweir // contains 68cdf0e10cSrcweir range<int> t3(0,10); 69cdf0e10cSrcweir range<int> t4(7, 15); 70cdf0e10cSrcweir range<int> t5(12, 12); 71cdf0e10cSrcweir range<int> t6(13, 77); 72cdf0e10cSrcweir range<int> t7(87, 87); 73cdf0e10cSrcweir range<int> t8(87, 88); 74cdf0e10cSrcweir range<int> t9(88, 88); 75cdf0e10cSrcweir range<int> t10(33, 120); 76cdf0e10cSrcweir range<int> t11(90, 100); 77cdf0e10cSrcweir range<int> t12(200,200); 78cdf0e10cSrcweir 79cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains1", t1.contains(t1)); 80cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains2", t1.contains(t2)); 81cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains3", ! t1.contains(t3)); 82cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains4", ! t1.contains(t4)); 83cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains5", t1.contains(t5)); 84cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains6", t1.contains(t6)); 85cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains7", t1.contains(t7)); 86cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains8", t1.contains(t8)); 87cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains9", ! t1.contains(t9)); 88cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains10", ! t1.contains(t10)); 89cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains11", ! t1.contains(t11)); 90cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains12", ! t1.contains(t12)); 91cdf0e10cSrcweir 92cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n1", t1.contains(50)); 93cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n2", t1.contains(12)); 94cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n3", t1.contains(87)); 95cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n4", ! t1.contains(3)); 96cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n5", ! t1.contains(11)); 97cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n6", ! t1.contains(88)); 98cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n7", ! t1.contains(100)); 99cdf0e10cSrcweir 100cdf0e10cSrcweir // overlaps 101cdf0e10cSrcweir range<int> t13(88,99); 102cdf0e10cSrcweir 103cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps1", t1.overlaps(t1)); 104cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps2", t1.overlaps(t2)); 105cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps3", ! t1.overlaps(t3)); 106cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps4", t1.overlaps(t4)); 107cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps5", t1.overlaps(t5)); 108cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps6", t1.overlaps(t6)); 109cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps7", t1.overlaps(t7)); 110cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps8", t1.overlaps(t8)); 111cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps9", ! t1.overlaps(t9)); 112cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps10", t1.overlaps(t10)); 113cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps11", ! t1.overlaps(t11)); 114cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps12", ! t1.overlaps(t12)); 115cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps13", ! t1.overlaps(t13)); 116cdf0e10cSrcweir 117cdf0e10cSrcweir // distance_to 118cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to1", t1.distance_to(t13) == 0); 119cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to2", t1.distance_to(t9) == 0); 120cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to3", t1.distance_to(t11) == 2); 121cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to4", t1.distance_to(t8) == -1); 122cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to5", t1.distance_to(t3) == -88); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir void iterator_test() 126cdf0e10cSrcweir { 127cdf0e10cSrcweir typedef std::vector<char>::const_iterator test_it; 128cdf0e10cSrcweir const std::vector<char> hv(200,'x'); 129cdf0e10cSrcweir 130cdf0e10cSrcweir 131cdf0e10cSrcweir test_it hit1 = hv.begin() + 12; 132cdf0e10cSrcweir test_it hit2 = hv.begin() + 88; 133cdf0e10cSrcweir 134cdf0e10cSrcweir range<test_it> 135cdf0e10cSrcweir t1(hit1, hit2); 136cdf0e10cSrcweir range<test_it> 137cdf0e10cSrcweir t2(hv.begin()+33, hv.begin()+33); 138cdf0e10cSrcweir 139cdf0e10cSrcweir // ctor 140cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec ctor1", t1.begin() == hit1); 141cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec ctor2", t1.end() == hit2); 142cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec ctor3", t2.begin() == hv.begin()+33); 143cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec ctor4", t2.end() == hv.begin()+33); 144cdf0e10cSrcweir 145cdf0e10cSrcweir // make_range 146cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec make_range1", make_range(hv.begin(), hv.begin()+8).begin() == hv.begin()); 147cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec make_range2", make_range(hv.begin(), hv.begin()+8).end() == hv.begin()+8); 148cdf0e10cSrcweir 149cdf0e10cSrcweir // size 150cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec size1", t1.size() == size_t(t1.end() - t1.begin()) ); 151cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec size2", t2.size() == size_t(0) ); 152cdf0e10cSrcweir 153cdf0e10cSrcweir // contains 154cdf0e10cSrcweir range<test_it> t3(hv.begin(), hv.begin() + 10); 155cdf0e10cSrcweir range<test_it> t4(hv.begin() + 7, hv.begin() + 15); 156cdf0e10cSrcweir range<test_it> t5(hit1, hit1); 157cdf0e10cSrcweir range<test_it> t6(hv.begin() + 13, hv.begin() + 77); 158cdf0e10cSrcweir range<test_it> t7(hv.begin() + 87, hv.begin() + 87); 159cdf0e10cSrcweir range<test_it> t8(hv.begin() + 87, hit2); 160cdf0e10cSrcweir range<test_it> t9(hit2, hit2); 161cdf0e10cSrcweir range<test_it> t10(hv.begin() + 33, hv.begin() + 120); 162cdf0e10cSrcweir range<test_it> t11(hv.begin() + 90, hv.begin() + 100); 163cdf0e10cSrcweir range<test_it> t12(hv.begin() + 200,hv.begin() + 200); 164cdf0e10cSrcweir 165cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains1", t1.contains(t1)); 166cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains2", t1.contains(t2)); 167cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains3", ! t1.contains(t3)); 168cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains4", ! t1.contains(t4)); 169cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains5", t1.contains(t5)); 170cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains6", t1.contains(t6)); 171cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains7", t1.contains(t7)); 172cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains8", t1.contains(t8)); 173cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains9", ! t1.contains(t9)); 174cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains10", ! t1.contains(t10)); 175cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains11", ! t1.contains(t11)); 176cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains12", ! t1.contains(t12)); 177cdf0e10cSrcweir 178cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n1", t1.contains(hv.begin() + 50)); 179cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n2", t1.contains(hit1)); 180cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n3", t1.contains(hv.begin() + 87)); 181cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n4", ! t1.contains(hv.begin() + 3)); 182cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n5", ! t1.contains(hv.begin() + 11)); 183cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n6", ! t1.contains(hit2)); 184cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n7", ! t1.contains(hv.begin() + 100)); 185cdf0e10cSrcweir 186cdf0e10cSrcweir // overlaps 187cdf0e10cSrcweir range<test_it> t13(hit2, hv.begin() + 99); 188cdf0e10cSrcweir 189cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps1", t1.overlaps(t1)); 190cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps2", t1.overlaps(t2)); 191cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps3", ! t1.overlaps(t3)); 192cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps4", t1.overlaps(t4)); 193cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps5", t1.overlaps(t5)); 194cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps6", t1.overlaps(t6)); 195cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps7", t1.overlaps(t7)); 196cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps8", t1.overlaps(t8)); 197cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps9", ! t1.overlaps(t9)); 198cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps10", t1.overlaps(t10)); 199cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps11", ! t1.overlaps(t11)); 200cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps12", ! t1.overlaps(t12)); 201cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps13", ! t1.overlaps(t13)); 202cdf0e10cSrcweir 203cdf0e10cSrcweir // distance_to 204cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to1", t1.distance_to(t13) == 0); 205cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to2", t1.distance_to(t8) == -1); 206cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to3", t1.distance_to(t9) == 0); 207cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to4", t1.distance_to(t11) == 2); 208cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to5", t1.distance_to(t3) == -88); 209cdf0e10cSrcweir 210cdf0e10cSrcweir const std::vector< int* > h2(20, (int*)0); 211cdf0e10cSrcweir std::deque< double > h3(30, 0.0); 212cdf0e10cSrcweir 213cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("range_of1", range_of(h2).begin() == h2.begin()); 214cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("range_of2", range_of(h3).end() == h3.end()); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir // insert your test code here. 218cdf0e10cSrcweir void global() 219cdf0e10cSrcweir { 220cdf0e10cSrcweir int_test(); 221cdf0e10cSrcweir iterator_test(); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir 225cdf0e10cSrcweir // These macros are needed by auto register mechanism. 226cdf0e10cSrcweir CPPUNIT_TEST_SUITE(range_test); 227cdf0e10cSrcweir CPPUNIT_TEST(global); 228cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 229cdf0e10cSrcweir }; // class range_test 230cdf0e10cSrcweir 231cdf0e10cSrcweir // ----------------------------------------------------------------------------- 232cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(range_test); 233