]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/test-std.cc
rational cleanups: suppress some automatic conversions.
[lilypond.git] / flower / test-std.cc
index 72e86f110afef40499396116a34431dfd4a6672e..ed317f7f631a13c4850ed307118a859bb2d7c276 100644 (file)
@@ -1,21 +1,25 @@
+#define STD_VECTOR 1
+
 #if !STD_VECTOR
 #define Array flower_vector
 #endif
-#include "std-vector.hh"
 
-#include "parray.hh"
+#define HAVE_BOOST_LAMBDA 1
+#include "std-vector.hh"
 
 #include <iostream>
 
 #include <boost/test/auto_unit_test.hpp>
 #include <boost/test/floating_point_comparison.hpp>
 
-using boost::unit_test::test_suite;
-
 #if !STD_VECTOR
 #define vector flower_vector
 #endif
 
+using namespace std;
+using boost::unit_test::test_suite;
+using namespace boost::unit_test;
+
 template<typename T>
 void
 print (vector<T> v)
@@ -25,6 +29,7 @@ print (vector<T> v)
   cout << endl;
 }
 
+#if !STD_VECTOR
 template<typename T>
 void
 print (Link_array<T> v)
@@ -33,7 +38,7 @@ print (Link_array<T> v)
     cout << "v[" << i << "] = " << *v[i] << endl;
   cout << endl;
 }
-
+#endif
 
 BOOST_AUTO_UNIT_TEST (vector_erase)
 {
@@ -80,7 +85,8 @@ BOOST_AUTO_UNIT_TEST (vector_sorting)
 #if VECTOR_SORT
   v.sort (default_compare);
 #else
-  vector_sort (v, default_compare);
+  //sort (v.begin (), v.end ());
+  vector_sort (v, less<int> ());
 #endif
   BOOST_CHECK_EQUAL (v[0], 0);
   BOOST_CHECK_EQUAL (v[1], 1);
@@ -114,21 +120,25 @@ BOOST_AUTO_UNIT_TEST (vector_insert)
 
 BOOST_AUTO_UNIT_TEST (parray_concat)
 {
+#if !STD_VECTOR
   Link_array<int> u, v;
+#else
+  vector<int*> u, v;
+#endif  
   int a[5] = { 0, 1, 2, 3, 4 };
   u.push_back (&a[0]);
   u.push_back (&a[1]);
   u.push_back (&a[2]);
   v.push_back (&a[3]);
   v.push_back (&a[4]);
-  u.concat (v);
+  concat (u, v);
   BOOST_CHECK_EQUAL (u[0], &a[0]);
   BOOST_CHECK_EQUAL (u[1], &a[1]);
   BOOST_CHECK_EQUAL (u[2], &a[2]);
   BOOST_CHECK_EQUAL (u[3], &a[3]);
   BOOST_CHECK_EQUAL (u[4], &a[4]);
   BOOST_CHECK_EQUAL (u.size (), vsize (5));
-  u.concat (v);
+  concat (u, v);
   BOOST_CHECK_EQUAL (u.size (), vsize (7));
 
   u.clear ();
@@ -138,7 +148,7 @@ BOOST_AUTO_UNIT_TEST (parray_concat)
   v.push_back (&a[2]);
   v.push_back (&a[3]);
   v.push_back (&a[4]);
-  u.concat (v);
+  concat (u, v);
   BOOST_CHECK_EQUAL (u[0], &a[0]);
   BOOST_CHECK_EQUAL (u[1], &a[1]);
   BOOST_CHECK_EQUAL (u[2], &a[2]);
@@ -147,14 +157,84 @@ BOOST_AUTO_UNIT_TEST (parray_concat)
   BOOST_CHECK_EQUAL (u.size (), vsize (5));
 }
 
+BOOST_AUTO_UNIT_TEST (parray_uniq)
+{
+  vector<int> v;
+  v.push_back (0);
+  v.push_back (1);
+  v.push_back (0);
+  vector_sort (v, less<int> ());
+  uniq (v);
+  BOOST_CHECK_EQUAL (v.size (), vsize (2));
+}
+
+BOOST_AUTO_UNIT_TEST (vector_search)
+{
+  vector<int> v;
+  v.push_back (0);
+  v.push_back (1);
+  v.push_back (2);
+  vsize i = binary_search (v, 1, less<int> ());
+  BOOST_CHECK_EQUAL (i, vsize (1));
+}
+
+#if 0
+#include "file-name.hh"
+string slashify (string file_name);
+
+BOOST_AUTO_UNIT_TEST (mingw_slashify)
+{
+  File_name f = string ("foe.ly");
+  string s = slashify (f.to_string ());
+  cout << s << endl;
+  BOOST_CHECK_EQUAL (s, "foe.ly");
+  f = string ("/tmp/x.ly");
+  s = slashify (f.to_string ());
+  cout << s << endl;
+  BOOST_CHECK_EQUAL (s, "/tmp/x.ly");
+  f = string ("c:/tmp/x.ly");
+  s = slashify (f.to_string ());
+  cout << s << endl;
+  BOOST_CHECK_EQUAL (s, "c:/tmp/x.ly");
+  f = string ("\\tmp\\x.ly");
+  s = slashify (f.to_string ());
+  cout << s << endl;
+  BOOST_CHECK_EQUAL (s, "/tmp/x.ly");
+}
+#endif
+
+void mingw_slashify ();
+void file_find ();
+
+#include <boost/test/results_reporter.hpp>
+#include <boost/test/framework.hpp>
+#include <boost/test/detail/unit_test_parameters.hpp>
+
 test_suite*
 init_unit_test_suite (int, char**)
 {
-  test_suite *test = BOOST_TEST_SUITE("std::Flower");
+  vsize i = 0;
+  vsize j = 0;
+  vector<int> v;
+  binary_search (v, 1, less<int> (), i, j);
+  //binary_search_bounds (v, 1, &default_compare, 0, 0);
+  
+  //Link_array<char> w;
+  vector<char*> w;
+  binary_search (w, (char*)1, less<char*> (), i, j);
+  
+  test_suite *test = BOOST_TEST_SUITE("Flower");
+
+
   test->add (BOOST_TEST_CASE (vector_erase));
   test->add (BOOST_TEST_CASE (vector_slice));
   test->add (BOOST_TEST_CASE (vector_sorting));
   test->add (BOOST_TEST_CASE (vector_insert));
   test->add (BOOST_TEST_CASE (parray_concat));
+  test->add (BOOST_TEST_CASE (parray_uniq));
+  test->add (BOOST_TEST_CASE (vector_search));
+  test->add (BOOST_TEST_CASE (mingw_slashify));
+  test->add (BOOST_TEST_CASE (file_find));
+
   return test;
 }