script.scm: Quantize staccatissimo; de-quantize accent, espressivo.
[lilypond/mpolesky.git] / flower / test-std.cc
blob1c1a71fa3a058f3e91a388cedc749010c6b39a14
1 #define STD_VECTOR 1
3 #if !STD_VECTOR
4 #define Array flower_vector
5 #endif
7 #define HAVE_BOOST_LAMBDA 1
8 #include "std-vector.hh"
10 #include <iostream>
12 #define YAFFUT_MAIN
13 #include "yaffut.hh"
15 #if !STD_VECTOR
16 #define vector flower_vector
17 #endif
19 using namespace std;
21 template<typename T>
22 void
23 print (vector<T> v)
25 for (vsize i = 0; i < v.size (); i++)
26 cout << "v[" << i << "] = " << v[i] << endl;
27 cout << endl;
30 #if !STD_VECTOR
31 template<typename T>
32 void
33 print (Link_array<T> v)
35 for (vsize i = 0; i < v.size (); i++)
36 cout << "v[" << i << "] = " << *v[i] << endl;
37 cout << endl;
39 #endif
41 FUNC (vector_erase)
43 vector<int> v;
44 v.push_back (0);
45 v.push_back (1);
46 EQUAL (v.size (), vsize (2));
47 v.erase (v.begin () + 1);
48 EQUAL (v.size (), vsize (1));
49 EQUAL (v.back (), 0);
51 v.push_back (1);
52 EQUAL (v.size (), vsize (2));
53 v.erase (v.begin () + 0);
54 EQUAL (v.size (), vsize (1));
55 EQUAL (v.back (), 1);
58 FUNC (vector_slice)
60 vector<int> v;
61 v.push_back (0);
62 v.push_back (1);
63 v.push_back (2);
64 v.push_back (3);
65 #if VECTOR_SLICE
66 EQUAL (v.slice (0, 0).size (), vsize (0));
67 EQUAL (v.slice (0, v.size ()).size (), v.size ());
68 EQUAL (v.slice (1, 2).size (), vsize (1));
69 #else
70 EQUAL (vector<int> (v.begin (), v.begin ()).size (), vsize (0));
71 EQUAL (vector<int> (v.begin (), v.end ()).size (), v.size ());
72 EQUAL (vector<int> (v.begin () + 1, v.begin () + 2).size (),
73 vsize (1));
74 #endif
77 FUNC (vector_sorting)
79 vector<int> v;
80 v.push_back (2);
81 v.push_back (1);
82 v.push_back (0);
83 #if VECTOR_SORT
84 v.sort (default_compare);
85 #else
86 //sort (v.begin (), v.end ());
87 vector_sort (v, less<int> ());
88 #endif
89 EQUAL (v[0], 0);
90 EQUAL (v[1], 1);
91 EQUAL (v[2], 2);
94 FUNC (vector_insert)
96 vector<int> v;
97 v.push_back (0);
98 #if VECTOR_INSERT
99 v.insert (1, 0);
100 #else
101 v.insert (v.begin (), 1);
102 #endif
103 EQUAL (v[0], 1);
104 #if VECTOR_INSERT
105 v.insert (2, v.size ());
106 #else
107 v.insert (v.end (), 2);
108 #endif
109 EQUAL (v.back (), 2);
110 vector<int> u;
111 u.insert (u.begin (), v.begin (), v.end ());
112 EQUAL (u.size (), v.size ());
113 u.clear ();
114 u.insert (u.end (), v.begin (), v.end ());
115 EQUAL (u.size (), v.size ());
116 u.clear ();
119 FUNC (parray_concat)
121 #if !STD_VECTOR
122 Link_array<int> u, v;
123 #else
124 vector<int*> u, v;
125 #endif
126 int a[5] = { 0, 1, 2, 3, 4 };
127 u.push_back (&a[0]);
128 u.push_back (&a[1]);
129 u.push_back (&a[2]);
130 v.push_back (&a[3]);
131 v.push_back (&a[4]);
132 concat (u, v);
133 EQUAL (u[0], &a[0]);
134 EQUAL (u[1], &a[1]);
135 EQUAL (u[2], &a[2]);
136 EQUAL (u[3], &a[3]);
137 EQUAL (u[4], &a[4]);
138 EQUAL (u.size (), vsize (5));
139 concat (u, v);
140 EQUAL (u.size (), vsize (7));
142 u.clear ();
143 v.clear ();
144 v.push_back (&a[0]);
145 v.push_back (&a[1]);
146 v.push_back (&a[2]);
147 v.push_back (&a[3]);
148 v.push_back (&a[4]);
149 concat (u, v);
150 EQUAL (u[0], &a[0]);
151 EQUAL (u[1], &a[1]);
152 EQUAL (u[2], &a[2]);
153 EQUAL (u[3], &a[3]);
154 EQUAL (u[4], &a[4]);
155 EQUAL (u.size (), vsize (5));
158 FUNC (parray_uniq)
160 vector<int> v;
161 v.push_back (0);
162 v.push_back (1);
163 v.push_back (0);
164 vector_sort (v, less<int> ());
165 uniq (v);
166 EQUAL (v.size (), vsize (2));
169 FUNC (vector_search)
171 vector<int> v;
172 v.push_back (0);
173 v.push_back (1);
174 v.push_back (2);
175 vsize i = binary_search (v, 1, less<int> ());
176 EQUAL (i, vsize (1));