4 #define Array flower_vector
7 #define HAVE_BOOST_LAMBDA 1
8 #include "std-vector.hh"
12 #include <boost/test/auto_unit_test.hpp>
13 #include <boost/test/floating_point_comparison.hpp>
15 using boost::unit_test::test_suite;
18 #define vector flower_vector
27 for (vsize i = 0; i < v.size (); i++)
28 cout << "v[" << i << "] = " << v[i] << endl;
35 print (Link_array<T> v)
37 for (vsize i = 0; i < v.size (); i++)
38 cout << "v[" << i << "] = " << *v[i] << endl;
43 BOOST_AUTO_UNIT_TEST (vector_erase)
48 BOOST_CHECK_EQUAL (v.size (), vsize (2));
49 v.erase (v.begin () + 1);
50 BOOST_CHECK_EQUAL (v.size (), vsize (1));
51 BOOST_CHECK_EQUAL (v.back (), 0);
54 BOOST_CHECK_EQUAL (v.size (), vsize (2));
55 v.erase (v.begin () + 0);
56 BOOST_CHECK_EQUAL (v.size (), vsize (1));
57 BOOST_CHECK_EQUAL (v.back (), 1);
60 BOOST_AUTO_UNIT_TEST (vector_slice)
68 BOOST_CHECK_EQUAL (v.slice (0, 0).size (), vsize (0));
69 BOOST_CHECK_EQUAL (v.slice (0, v.size ()).size (), v.size ());
70 BOOST_CHECK_EQUAL (v.slice (1, 2).size (), vsize (1));
72 BOOST_CHECK_EQUAL (vector<int> (v.begin (), v.begin ()).size (), vsize (0));
73 BOOST_CHECK_EQUAL (vector<int> (v.begin (), v.end ()).size (), v.size ());
74 BOOST_CHECK_EQUAL (vector<int> (v.begin () + 1, v.begin () + 2).size (),
79 BOOST_AUTO_UNIT_TEST (vector_sorting)
86 v.sort (default_compare);
88 vector_sort (v, default_compare);
90 BOOST_CHECK_EQUAL (v[0], 0);
91 BOOST_CHECK_EQUAL (v[1], 1);
92 BOOST_CHECK_EQUAL (v[2], 2);
95 BOOST_AUTO_UNIT_TEST (vector_insert)
102 v.insert (v.begin (), 1);
104 BOOST_CHECK_EQUAL (v[0], 1);
106 v.insert (2, v.size ());
108 v.insert (v.end (), 2);
110 BOOST_CHECK_EQUAL (v.back (), 2);
112 u.insert (u.begin (), v.begin (), v.end ());
113 BOOST_CHECK_EQUAL (u.size (), v.size ());
115 u.insert (u.end (), v.begin (), v.end ());
116 BOOST_CHECK_EQUAL (u.size (), v.size ());
120 BOOST_AUTO_UNIT_TEST (parray_concat)
123 Link_array<int> u, v;
127 int a[5] = { 0, 1, 2, 3, 4 };
134 BOOST_CHECK_EQUAL (u[0], &a[0]);
135 BOOST_CHECK_EQUAL (u[1], &a[1]);
136 BOOST_CHECK_EQUAL (u[2], &a[2]);
137 BOOST_CHECK_EQUAL (u[3], &a[3]);
138 BOOST_CHECK_EQUAL (u[4], &a[4]);
139 BOOST_CHECK_EQUAL (u.size (), vsize (5));
141 BOOST_CHECK_EQUAL (u.size (), vsize (7));
151 BOOST_CHECK_EQUAL (u[0], &a[0]);
152 BOOST_CHECK_EQUAL (u[1], &a[1]);
153 BOOST_CHECK_EQUAL (u[2], &a[2]);
154 BOOST_CHECK_EQUAL (u[3], &a[3]);
155 BOOST_CHECK_EQUAL (u[4], &a[4]);
156 BOOST_CHECK_EQUAL (u.size (), vsize (5));
159 BOOST_AUTO_UNIT_TEST (parray_uniq)
165 vector_sort (v, default_compare);
167 BOOST_CHECK_EQUAL (v.size (), vsize (2));
170 BOOST_AUTO_UNIT_TEST (vector_search)
176 vsize i = binary_search (v, 1, &default_compare);
177 BOOST_CHECK_EQUAL (i, vsize (1));
181 init_unit_test_suite (int, char**)
186 binary_search_bounds (v, 1, &default_compare, &i, &j);
187 //binary_search_bounds (v, 1, &default_compare, 0, 0);
189 //Link_array<char> w;
191 binary_search_bounds (w, (char*)1, &default_compare, &i, &j);
193 test_suite *test = BOOST_TEST_SUITE("Flower");
194 test->add (BOOST_TEST_CASE (vector_erase));
195 test->add (BOOST_TEST_CASE (vector_slice));
196 test->add (BOOST_TEST_CASE (vector_sorting));
197 test->add (BOOST_TEST_CASE (vector_insert));
198 test->add (BOOST_TEST_CASE (parray_concat));
199 test->add (BOOST_TEST_CASE (parray_uniq));
200 test->add (BOOST_TEST_CASE (vector_search));