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>
16 #define vector flower_vector
20 using boost::unit_test::test_suite;
21 using namespace boost::unit_test;
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 //sort (v.begin (), v.end ());
89 vector_sort (v, less<int> ());
91 BOOST_CHECK_EQUAL (v[0], 0);
92 BOOST_CHECK_EQUAL (v[1], 1);
93 BOOST_CHECK_EQUAL (v[2], 2);
96 BOOST_AUTO_UNIT_TEST (vector_insert)
103 v.insert (v.begin (), 1);
105 BOOST_CHECK_EQUAL (v[0], 1);
107 v.insert (2, v.size ());
109 v.insert (v.end (), 2);
111 BOOST_CHECK_EQUAL (v.back (), 2);
113 u.insert (u.begin (), v.begin (), v.end ());
114 BOOST_CHECK_EQUAL (u.size (), v.size ());
116 u.insert (u.end (), v.begin (), v.end ());
117 BOOST_CHECK_EQUAL (u.size (), v.size ());
121 BOOST_AUTO_UNIT_TEST (parray_concat)
124 Link_array<int> u, v;
128 int a[5] = { 0, 1, 2, 3, 4 };
135 BOOST_CHECK_EQUAL (u[0], &a[0]);
136 BOOST_CHECK_EQUAL (u[1], &a[1]);
137 BOOST_CHECK_EQUAL (u[2], &a[2]);
138 BOOST_CHECK_EQUAL (u[3], &a[3]);
139 BOOST_CHECK_EQUAL (u[4], &a[4]);
140 BOOST_CHECK_EQUAL (u.size (), vsize (5));
142 BOOST_CHECK_EQUAL (u.size (), vsize (7));
152 BOOST_CHECK_EQUAL (u[0], &a[0]);
153 BOOST_CHECK_EQUAL (u[1], &a[1]);
154 BOOST_CHECK_EQUAL (u[2], &a[2]);
155 BOOST_CHECK_EQUAL (u[3], &a[3]);
156 BOOST_CHECK_EQUAL (u[4], &a[4]);
157 BOOST_CHECK_EQUAL (u.size (), vsize (5));
160 BOOST_AUTO_UNIT_TEST (parray_uniq)
166 vector_sort (v, less<int> ());
168 BOOST_CHECK_EQUAL (v.size (), vsize (2));
171 BOOST_AUTO_UNIT_TEST (vector_search)
177 vsize i = binary_search (v, 1, less<int> ());
178 BOOST_CHECK_EQUAL (i, vsize (1));
182 #include "file-name.hh"
183 string slashify (string file_name);
185 BOOST_AUTO_UNIT_TEST (mingw_slashify)
187 File_name f = string ("foe.ly");
188 string s = slashify (f.to_string ());
190 BOOST_CHECK_EQUAL (s, "foe.ly");
191 f = string ("/tmp/x.ly");
192 s = slashify (f.to_string ());
194 BOOST_CHECK_EQUAL (s, "/tmp/x.ly");
195 f = string ("c:/tmp/x.ly");
196 s = slashify (f.to_string ());
198 BOOST_CHECK_EQUAL (s, "c:/tmp/x.ly");
199 f = string ("\\tmp\\x.ly");
200 s = slashify (f.to_string ());
202 BOOST_CHECK_EQUAL (s, "/tmp/x.ly");
206 void mingw_slashify ();
209 #include <boost/test/results_reporter.hpp>
210 #include <boost/test/framework.hpp>
211 #include <boost/test/detail/unit_test_parameters.hpp>
214 init_unit_test_suite (int, char**)
219 binary_search (v, 1, less<int> (), i, j);
220 //binary_search_bounds (v, 1, &default_compare, 0, 0);
222 //Link_array<char> w;
224 binary_search (w, (char*)1, less<char*> (), i, j);
226 test_suite *test = BOOST_TEST_SUITE("Flower");
229 test->add (BOOST_TEST_CASE (vector_erase));
230 test->add (BOOST_TEST_CASE (vector_slice));
231 test->add (BOOST_TEST_CASE (vector_sorting));
232 test->add (BOOST_TEST_CASE (vector_insert));
233 test->add (BOOST_TEST_CASE (parray_concat));
234 test->add (BOOST_TEST_CASE (parray_uniq));
235 test->add (BOOST_TEST_CASE (vector_search));
236 test->add (BOOST_TEST_CASE (mingw_slashify));
237 test->add (BOOST_TEST_CASE (file_find));