Jamoma API  0.6.0.a19
TTValue.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationLibrary
4  *
5  * @brief #TTValueTest is an class used for unit tests of the #TTValue class.
6  *
7  * @details
8  *
9  * @author Tim Place, Théo de la Hogue, Nathan Wolek, Julien Rabin, Nils Peters, Trond Lossius
10  *
11  * @copyright Copyright © 2011, Timothy Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 #include "TTValue.test.h"
17 
18 #define thisTTClass TTValueTest
19 #define thisTTClassName "value.test"
20 #define thisTTClassTags "test, foundation"
21 
22 
24 {;}
25 
26 
27 TTValueTest::~TTValueTest()
28 {;}
29 
30 
31 void TTValueTestFloatAssertion32(int& errorCount, int&testAssertionCount)
32 {
33  TTTestLog("\n");
34  TTTestLog("Testing TTTestFloatEquivalence method used to compare TTFloat32");
35 
36  TTFloat32 zero1 = 0.;
37  TTFloat32 zero2 = 0.;
38 
39  // Create various special numbers
40 
41  TTFloat32 negativeZero;
42 
43  // Initialize negativeZero with its integer representation
44  *(TTInt32*)&negativeZero = 0x80000000;
45 
46  // Create a NAN
47  TTFloat32 nan1 = sqrt(-1.0f);
48 
49  // Create a NAN a different way - should give the same NAN on Intel chips.
50  TTFloat32 nan2 = zero1 / zero2;
51 
52  // Create an infinity
53  TTFloat32 inf = 1 / zero1;
54 
55  // Create a NAN a third way - should give the same NAN on Intel chips.
56  TTFloat32 nan3 = inf - inf;
57 
58  // Copy one of the NANs and modify its representation.
59  // This will still give a NAN, just a different one.
60  TTFloat32 nan4 = nan3;
61  (*(TTInt32*)&nan4) += 1;
62 
63  // Create a denormal by starting with zero and incrementing
64  // the integer representation.
65  TTFloat32 smallestDenormal = 0;
66  (*(TTInt32*)&smallestDenormal) += 1;
67 
68 
69  // The first set of tests check things that any self-respecting
70  // comparison function should agree upon.
71 
72 
73  // The following test is expected to fail, hence the !
74  TTTestAssertion("TTFloat32: Test fails if epsilon is negative.",
75  !TTTestFloatEquivalence(TTFloat32(3.14), TTFloat32(3.14), false, TTFloat32(-0.1)),
76  testAssertionCount,
77  errorCount);
78 
79  TTTestAssertion("TTFloat32: zero and negativeZero compare as equal.",
80  TTTestFloatEquivalence(zero1, negativeZero),
81  testAssertionCount,
82  errorCount);
83 
84  TTTestAssertion("TTFloat32: Nearby numbers compare as equal.",
85  TTTestFloatEquivalence(TTFloat32(2.0), TTFloat32(1.9999999f)),
86  testAssertionCount,
87  errorCount);
88 
89  TTTestAssertion("TTFloat32: Same test fails with smaller epsilon.",
90  TTTestFloatEquivalence(TTFloat32(2.0), TTFloat32(1.9999999f), false, TTFloat32(0.0000000001)),
91  testAssertionCount,
92  errorCount);
93 
94  TTTestAssertion("TTFloat32: Slightly more distant numbers compare as equal.",
95  TTTestFloatEquivalence(TTFloat32(2.0), TTFloat32(1.9999995f)),
96  testAssertionCount,
97  errorCount);
98 
99  TTTestAssertion("TTFloat32: The results are the same with parameters reversed.",
100  TTTestFloatEquivalence(TTFloat32(1.9999995f), TTFloat32(2.0)),
101  testAssertionCount,
102  errorCount);
103 
104  TTTestAssertion("TTFloat32: Even more distant numbers don't compare as equal",
105  TTTestFloatEquivalence(TTFloat32(1.8), TTFloat32(2.0), false),
106  testAssertionCount,
107  errorCount);
108 
109  TTTestAssertion("TTFloat32: But it pass if epsilon is upped",
110  TTTestFloatEquivalence(TTFloat32(1.8), TTFloat32(2.0), true, TTFloat32(0.5)),
111  testAssertionCount,
112  errorCount);
113 
114  TTTestAssertion("TTFloat32: Nearby negative numbers compare as equal.",
115  TTTestFloatEquivalence(TTFloat32(-2.0), TTFloat32(-1.9999999f)),
116  testAssertionCount,
117  errorCount);
118 
119  TTTestAssertion("TTFloat32: Slightly more distant negative numbers compare as equal.",
120  TTTestFloatEquivalence(TTFloat32(-2.0), TTFloat32(-1.9999995f)),
121  testAssertionCount,
122  errorCount);
123 
124  TTTestAssertion("TTFloat32: The results are the same with parameters reversed.",
125  TTTestFloatEquivalence(TTFloat32(-1.9999995f), TTFloat32(-2.0)),
126  testAssertionCount,
127  errorCount);
128 
129  TTTestAssertion("TTFloat32: Even more distant negative numbers don't compare as equal",
130  TTTestFloatEquivalence(TTFloat32(-1.8), TTFloat32(-2.0), false),
131  testAssertionCount,
132  errorCount);
133 
134  TTTestAssertion("TTFloat32: Positive and negative numbers don't compare as equal",
135  TTTestFloatEquivalence(TTFloat32(-2.0), TTFloat32(2.0), false),
136  testAssertionCount,
137  errorCount);
138 
139  // The next set of tests check things where the correct answer isn't
140  // as obvious or important. Some of these tests check for cases that
141  // are rare or can easily be avoided.
142 #ifdef RARE
143  TTTestAssertion("TTFloat32: inf == inf.",
144  TTTestFloatEquivalence(inf, inf),
145  testAssertionCount,
146  errorCount);
147 
148  TTTestAssertion("TTFloat32: -inf == -inf.",
149  TTTestFloatEquivalence(-inf, -inf),
150  testAssertionCount,
151  errorCount);
152  TTTestAssertion("TTFloat32: inf != -inf.",
153  TTTestFloatEquivalence(inf, -inf, false),
154  testAssertionCount,
155  errorCount);
156 #endif
157 
158 // FLT_MAX is not defined for the iOS
159 //#ifndef TT_PLATFORM_IOS
160 // TTTestAssertion("TTFloat32: FLT_MAX != inf",
161 //#ifdef TT_PLATFORM_WIN
162 // TTTestFloatEquivalence(FLT_MAX, inf, false),
163 //#else
164 // TTTestFloatEquivalence(std::numeric_limits<float>::max(), inf, false),
165 //#endif
166 // testAssertionCount,
167 // errorCount);
168 //#endif
169  TTTestAssertion("TTFloat32: 3.14 != inf",
170  TTTestFloatEquivalence(TTFloat32(3.14), inf, false),
171  testAssertionCount,
172  errorCount);
173 
174 
175  // The IEEE standard says that any comparison operation involving a NAN must return false.
176  TTTestAssertion("TTFloat32: nan1==3.14 => false (according to IEEE standard)",
177  TTTestFloatEquivalence(nan1, TTFloat32(3.14), false),
178  testAssertionCount,
179  errorCount);
180 
181  TTTestAssertion("TTFloat32: nan1==nan1 => false (according to IEEE standard).",
182  TTTestFloatEquivalence(nan1, nan1, false),
183  testAssertionCount,
184  errorCount);
185 
186  TTTestAssertion("TTFloat32: nan2==nan2 => false (according to IEEE standard).",
187  TTTestFloatEquivalence(nan2, nan2, false),
188  testAssertionCount,
189  errorCount);
190 
191  TTTestAssertion("TTFloat32: nan3==nan3 => false (according to IEEE standard).",
192  TTTestFloatEquivalence(nan3, nan3, false),
193  testAssertionCount,
194  errorCount);
195 
196  TTTestAssertion("TTFloat32: nan4==nan4 => false (according to IEEE standard).",
197  TTTestFloatEquivalence(nan4, nan4, false),
198  testAssertionCount,
199  errorCount);
200 
201  TTTestAssertion("TTFloat32: nan1==nan2 => false (according to IEEE standard).",
202  TTTestFloatEquivalence(nan1, nan2, false),
203  testAssertionCount,
204  errorCount);
205 
206  TTTestAssertion("TTFloat32: nan1==nan3 => false (according to IEEE standard).",
207  TTTestFloatEquivalence(nan1, nan3, false),
208  testAssertionCount,
209  errorCount);
210 
211  TTTestAssertion("TTFloat32: nan1==nan4 => false (according to IEEE standard).",
212  TTTestFloatEquivalence(nan1, nan4, false),
213  testAssertionCount,
214  errorCount);
215 
216  TTTestAssertion("TTFloat32: nan1==inf => false (according to IEEE standard).",
217  TTTestFloatEquivalence(nan1, inf, false),
218  testAssertionCount,
219  errorCount);
220 
221  // Tests for denormals
222  TTTestAssertion("TTFloat32: Tiny numbers of opposite signs compare as equal.",
223  TTTestFloatEquivalence(smallestDenormal, -smallestDenormal),
224  testAssertionCount,
225  errorCount);
226 
227  TTTestAssertion("TTFloat32: The results are the same with parameters reversed.",
228  TTTestFloatEquivalence(-smallestDenormal, smallestDenormal),
229  testAssertionCount,
230  errorCount);
231 }
232 
233 void TTValueTestFloatAssertion64(int& errorCount, int&testAssertionCount)
234 {
235  TTTestLog("\n");
236  TTTestLog("Testing TTTestFloatEquivalence method used to compare TTFloat64");
237 
238  TTFloat64 zero1 = 0.;
239  TTFloat64 zero2 = 0.;
240 
241  // Create various special numbers
242 
243  // TTFloat64 negativeZero;
244 
245  // Initialize negativeZero with its integer representation
246  // *(TTInt64*)&negativeZero = TTInt64(0x8000000000000000);
247 
248  // Create a NAN
249  TTFloat64 nan1 = sqrt(-1.0f);
250 
251  // Create a NAN a different way - should give the same NAN on Intel chips.
252  TTFloat64 nan2 = zero1 / zero2;
253 
254  // Create an infinity
255  TTFloat64 inf = 1 / zero1;
256 
257  // Create a NAN a third way - should give the same NAN on Intel chips.
258  TTFloat64 nan3 = inf - inf;
259 
260  // Copy one of the NANs and modify its representation.
261  // This will still give a NAN, just a different one.
262  TTFloat64 nan4 = nan3;
263  (*(TTInt64*)&nan4) += 10;
264 
265  // Create a denormal by starting with zero and incrementing
266  // the integer representation.
267  TTFloat64 smallestDenormal = TTInt64(0);
268  (*(TTInt64*)&smallestDenormal) += 1;
269 
270  // The first set of tests check things that any self-respecting
271  // comparison function should agree upon.
272 
273  // The following test is expected to fail, hence the !
274  TTTestAssertion("TTFloat64: Test fails if epsilon is negative.",
275  !TTTestFloatEquivalence(TTFloat64(3.14), TTFloat64(3.14), false, TTFloat64(-0.0001)),
276  testAssertionCount,
277  errorCount);
278 
279  /* TL: It doesn't seem possible to create negatie zeros for doubles, so test is commented out.
280  TTTestAssertion("TTFloat64: zero and negativeZero compare as equal.",
281  TTTestFloatEquivalence(zero1, negativeZero),
282  testAssertionCount,
283  errorCount);
284  */
285 
286  TTTestAssertion("TTFloat64: Nearby numbers compare as equal.",
287  TTTestFloatEquivalence(TTFloat64(2.0), TTFloat64(1.99999999999999)),
288  testAssertionCount,
289  errorCount);
290 
291  TTTestAssertion("TTFloat64: Same test fails with smaller epsilon.",
292  TTTestFloatEquivalence(TTFloat64(2.0), TTFloat64(1.99999999999999), false, TTFloat64(0.0000000000000000001)),
293  testAssertionCount,
294  errorCount);
295 
296 
297  TTTestAssertion("TTFloat64: Slightly more distant numbers compare as equal.",
298  TTTestFloatEquivalence(TTFloat64(2.0), TTFloat64(1.9999999999999)),
299  testAssertionCount,
300  errorCount);
301 
302  TTTestAssertion("TTFloat64: The results are the same with parameters reversed.",
303  TTTestFloatEquivalence(TTFloat64(1.9999999999999), TTFloat64(2.0)),
304  testAssertionCount,
305  errorCount);
306 
307  TTTestAssertion("TTFloat64: Even more distant numbers don't compare as equal",
308  TTTestFloatEquivalence(TTFloat64(1.8), TTFloat64(2.0), false),
309  testAssertionCount,
310  errorCount);
311 
312  TTTestAssertion("TTFloat32: But it pass if epsilon is upped",
313  TTTestFloatEquivalence(TTFloat64(1.8), TTFloat64(2.0), true, TTFloat64(0.5)),
314  testAssertionCount,
315  errorCount);
316 
317  TTTestAssertion("TTFloat64: Nearby negative numbers compare as equal.",
318  TTTestFloatEquivalence(TTFloat64(-2.0), TTFloat64(-1.99999999999999)),
319  testAssertionCount,
320  errorCount);
321 
322  TTTestAssertion("TTFloat64: Slightly more distant negative numbers compare as equal.",
323  TTTestFloatEquivalence(TTFloat64(-2.0), TTFloat64(-1.9999999999999)),
324  testAssertionCount,
325  errorCount);
326 
327  TTTestAssertion("TTFloat64: The results are the same with parameters reversed.",
328  TTTestFloatEquivalence(TTFloat64(-1.9999999999999), TTFloat64(-2.0)),
329  testAssertionCount,
330  errorCount);
331 
332  TTTestAssertion("TTFloat64: Even more distant negative numbers don't compare as equal",
333  TTTestFloatEquivalence(TTFloat64(-1.8), TTFloat64(-2.0), false),
334  testAssertionCount,
335  errorCount);
336 
337  TTTestAssertion("TTFloat64: Positive and negative numbers don't compare as equal",
338  TTTestFloatEquivalence(TTFloat64(-2.0), TTFloat64(2.0), false),
339  testAssertionCount,
340  errorCount);
341 
342  // The next set of tests check things where the correct answer isn't
343  // as obvious or important. Some of these tests check for cases that
344  // are rare or can easily be avoided.
345 #ifdef RARE
346  TTTestAssertion("TTFloat64: inf == inf.",
347  TTTestFloatEquivalence(inf, inf),
348  testAssertionCount,
349  errorCount);
350 
351  TTTestAssertion("TTFloat64: -inf == -inf.",
352  TTTestFloatEquivalence(-inf, -inf),
353  testAssertionCount,
354  errorCount);
355  TTTestAssertion("TTFloat64: inf != -inf.",
356  TTTestFloatEquivalence(inf, -inf, false),
357  testAssertionCount,
358  errorCount);
359 #endif
360 
361 // DBL_MAX is not defined for the iOS
362 //#ifndef TT_PLATFORM_IOS
363 // TTTestAssertion("TTFloat64: DBL_MAX != inf",
364 //#ifdef TT_PLATFORM_WIN
365 // TTTestFloatEquivalence(DBL_MAX, inf, false),
366 //#else
367 // TTTestFloatEquivalence(std::numeric_limits<double>::max(), inf, false),
368 //#endif
369 // testAssertionCount,
370 // errorCount);
371 //#endif
372  TTTestAssertion("TTFloat64: 3.14 != inf",
373  TTTestFloatEquivalence(TTFloat64(3.14), inf, false),
374  testAssertionCount,
375  errorCount);
376 
377 
378  // The IEEE standard says that any comparison operation involving a NAN must return false.
379  TTTestAssertion("TTFloat64: nan1==3.14 => false (according to IEEE standard)",
380  TTTestFloatEquivalence(nan1, TTFloat64(3.14), false),
381  testAssertionCount,
382  errorCount);
383 
384  TTTestAssertion("TTFloat64: nan1==nan1 => false (according to IEEE standard).",
385  TTTestFloatEquivalence(nan1, nan1, false),
386  testAssertionCount,
387  errorCount);
388 
389  TTTestAssertion("TTFloat64: nan2==nan2 => false (according to IEEE standard).",
390  TTTestFloatEquivalence(nan2, nan2, false),
391  testAssertionCount,
392  errorCount);
393 
394  TTTestAssertion("TTFloat64: nan3==nan3 => false (according to IEEE standard).",
395  TTTestFloatEquivalence(nan3, nan3, false),
396  testAssertionCount,
397  errorCount);
398 
399  TTTestAssertion("TTFloat64: nan4==nan4 => false (according to IEEE standard).",
400  TTTestFloatEquivalence(nan4, nan4, false),
401  testAssertionCount,
402  errorCount);
403 
404  TTTestAssertion("TTFloat64: nan1==nan2 => false (according to IEEE standard).",
405  TTTestFloatEquivalence(nan1, nan2, false),
406  testAssertionCount,
407  errorCount);
408 
409  TTTestAssertion("TTFloat64: nan1==nan3 => false (according to IEEE standard).",
410  TTTestFloatEquivalence(nan1, nan3, false),
411  testAssertionCount,
412  errorCount);
413 
414  TTTestAssertion("TTFloat64: nan1==nan4 => false (according to IEEE standard).",
415  TTTestFloatEquivalence(nan1, nan4, false),
416  testAssertionCount,
417  errorCount);
418 
419  TTTestAssertion("TTFloat64: nan1==inf => false (according to IEEE standard).",
420  TTTestFloatEquivalence(nan1, inf, false),
421  testAssertionCount,
422  errorCount);
423 
424  // Tests for denormals
425 
426  /* Don't manage to create denorm values, so these tests are commented out.
427  TTTestAssertion("TTFloat64: Tiny numbers of opposite signs compare as equal.",
428  TTTestFloatEquivalence(smallestDenormal, -smallestDenormal),
429  testAssertionCount,
430  errorCount);
431 
432  TTTestAssertion("TTFloat64: The results are the same with parameters reversed.",
433  TTTestFloatEquivalence(-smallestDenormal, smallestDenormal),
434  testAssertionCount,
435  errorCount);
436  */
437 }
438 
439 /** Test the method used to compare floats for equity.
440  @group unittest
441  @param a Errors counter
442  @param b Assertions counter */
443 void TTValueTestFloatAssertion(int& errorCount, int&testAssertionCount)
444 {
445  // Testing for TTFloat32
446  TTValueTestFloatAssertion32(errorCount, testAssertionCount);
447 
448  // Testing for TTFloat64
449  TTValueTestFloatAssertion64(errorCount, testAssertionCount);
450 }
451 
452 
453 void TTValueTestBasic(int& errorCount, int&testAssertionCount)
454 {
455  TTTestLog("\n");
456  TTTestLog("Testing basic TTValue operation");
457 
458  TTValue v0;
459  TTTestAssertion("init with nothing",
460  v0.empty(),
461  testAssertionCount,
462  errorCount);
463 
464  TTValue v1(3.14);
465 
466  TTTestAssertion("init with a double is correctly typed as kTypeFloat64",
467  v1[0].type() == kTypeFloat64,
468  testAssertionCount,
469  errorCount);
470 
471  TTTestAssertion("init with a double has correct element count",
472  v1.size() == 1,
473  testAssertionCount,
474  errorCount);
475 
476  TTTestAssertion("init with a double has correct value when retrieved as a double",
477  TTTestFloatEquivalence(double(v1), 3.14),
478  testAssertionCount,
479  errorCount);
480 
481  TTTestAssertion("init with a double has correct value when retrieved as an TTInt32",
482  TTInt32(v1) == 3,
483  testAssertionCount,
484  errorCount);
485 
486  TTTestLog("Appending a symbol to TTValue");
487  v1.append(TTSymbol("foo"));
488 
489  TTTestAssertion("TTValue correctly updated element count to 2",
490  v1.size() == 2,
491  testAssertionCount,
492  errorCount);
493 
494  TTTestAssertion("first item still is correctly typed as kTypeFloat64",
495  v1[0].type() == kTypeFloat64,
496  testAssertionCount,
497  errorCount);
498 
499  TTTestAssertion("first item still has correct value when retrieved as a double",
500  TTTestFloatEquivalence(double(v1), 3.14),
501  testAssertionCount,
502  errorCount);
503 
504  TTTestAssertion("second item has correct type",
505  v1[1].type() == kTypeSymbol,
506  testAssertionCount,
507  errorCount);
508 
509  TTSymbol s = v1[1];
510  TTTestAssertion("second item has correct value, retreiving with get() method",
511  s == "foo",
512  testAssertionCount,
513  errorCount);
514 
515  TTTestLog("Prepending a TTValue with one symbol to TTValue");
516  v1.prepend(TTValue(kTTSym_value));
517 
518  TTTestAssertion("TTValue correctly updated element count to 3",
519  v1.size() == 3,
520  testAssertionCount,
521  errorCount);
522 
523  TTTestAssertion("first item should be typed as kTypeSymbol",
524  v1[0].type() == kTypeSymbol,
525  testAssertionCount,
526  errorCount);
527 
528  s = v1[0];
529  TTTestAssertion("first item should be \"value\" symbol",
530  s == kTTSym_value,
531  testAssertionCount,
532  errorCount);
533 
534  TTTestAssertion("second item still is correctly typed as kTypeFloat64",
535  v1[1].type() == kTypeFloat64,
536  testAssertionCount,
537  errorCount);
538 
539  TTTestAssertion("third item has correct type",
540  v1[2].type() == kTypeSymbol,
541  testAssertionCount,
542  errorCount);
543 
544 
545  // BUG : when value v1 is set as below,
546  // there is a problem during the copy of the memory (cf memcpy in copy method)
547  // and there is a crash when the value is deleted at the end of this method.
548 
549  //v1 = TTString("test");
550 
551  TTTestLog("Clearing TTValue");
552  v1.clear();
553 
554  TTTestAssertion("element count is zero",
555  v1.size() == 0,
556  testAssertionCount,
557  errorCount);
558 
559  // TODO: document that we check size rather than type
560 #ifdef OLD
561  TTTestAssertion("type of TTValue which is returned is kTypeNone",
562  v1.getType() == kTypeNone,
563  testAssertionCount,
564  errorCount);
565 #endif
566 
567 }
568 
569 
570 void TTValueTestStringConversion(int& errorCount, int&testAssertionCount)
571 {
572  TTTestLog("\n");
573  TTTestLog("Testing TTValue string conversion methods");
574 
575  TTValue v;
576  TTString aString;
577  TTSymbol aSymbol = kTTSymEmpty;
578  TTInt32 i;
579  TTFloat32 f;
580 
581  // test toString()
582  v = TTValue("victor","bravo",74,0.6);
583  v.toString();
584  aString = TTString("victor bravo 74 0.600000");
585 
586  TTTestAssertion("4 element TTValue is converted into a single TTString",
587  v[0].type() == kTypeString &&
588  v.size() == 1,
589  testAssertionCount,
590  errorCount);
591 
592  TTTestAssertion("new TTString has the expected value",
593  v == aString,
594  testAssertionCount,
595  errorCount);
596 
597  // test fromString()
598  v.clear();
599  aString = TTString("0");
600  v = aString;
601  v.fromString();
602 
603  TTTestAssertion("\"0\" string is converted into a TTInt32 0 value",
604  v[0].type() == kTypeInt32 &&
605  v[0] == 0,
606  testAssertionCount,
607  errorCount);
608 
609  v.clear();
610  aString = TTString("0.000000");
611  v = aString;
612  v.fromString();
613 
614  TTTestAssertion("\"0.000000\" string is converted into a TTFloat64 0.000000 value",
615  v[0].type() == kTypeFloat64 &&
616  v[0] == 0.f,
617  testAssertionCount,
618  errorCount);
619 
620  v.clear();
621  aString = TTString("1");
622  v = aString;
623  v.fromString();
624 
625  TTTestAssertion("\"1\" string is converted into a TTInt32 1 value",
626  v[0].type() == kTypeInt32 &&
627  v[0] == 1,
628  testAssertionCount,
629  errorCount);
630 
631  v.clear();
632  aString = TTString("1234u");
633  v = aString;
634  v.fromString();
635 
636  TTTestAssertion("\"1234u\" string is converted into a TTUInt32 1234 value",
637  v[0].type() == kTypeUInt32 &&
638  v[0] == 1234,
639  testAssertionCount,
640  errorCount);
641 
642  v.clear();
643  aString = TTString("uzi");
644  v = aString;
645  v.fromString();
646 
647  TTTestAssertion("\"uzi\" string is not converted into a TTUInt32 0 value",
648  v[0].type() != kTypeUInt32 &&
649  v[0].type() == kTypeSymbol,
650  testAssertionCount,
651  errorCount);
652 
653  v.clear();
654  aString = TTString("1.234567");
655  v = aString;
656  v.fromString();
657 
658  TTTestAssertion("\"1.234567\" string is converted into a TTFloat32 1.234567 value",
659  v[0].type() == kTypeFloat64 &&
660  TTTestFloatEquivalence(TTFloat32(v[0]), 1.234567f),
661  testAssertionCount,
662  errorCount);
663 
664  v.clear();
665  aString = TTString("value");
666  v = aString;
667  v.fromString();
668  aSymbol = v[0];
669 
670  TTTestAssertion("\"value\" string is converted into a TTSymbolPtr kTTSym_value",
671  v[0].type() == kTypeSymbol &&
672  aSymbol == kTTSym_value,
673  testAssertionCount,
674  errorCount);
675 
676  v.clear();
677  aString = TTString("sampleRate 1 1.234567");
678  v = aString;
679  v.fromString();
680  aSymbol = v[0];
681  i = v[1];
682  f = v[2];
683 
684  TTTestAssertion("\"sampleRate 1 1.234567\" string is converted into a 3 datas value",
685  v[0].type() == kTypeSymbol &&
686  v[1].type() == kTypeInt32 &&
687  v[2].type() == kTypeFloat64 &&
688  aSymbol == kTTSym_sampleRate &&
689  i == 1 &&
690  TTTestFloatEquivalence(f, 1.234567f) &&
691  v.size() == 3,
692  testAssertionCount,
693  errorCount);
694 
695  // test transformCSVStringToSymbolArray()
696  v.clear();
697  aString = TTString("tango,wilco,1977");
698  v = aString;
700 
701  TTTestAssertion("\"tango,wilco,1977\" CSV string is converted into a 3 symbols",
702  v[0].type() == kTypeSymbol &&
703  v[1].type() == kTypeSymbol &&
704  v[2].type() == kTypeSymbol &&
705  v.size() == 3,
706  testAssertionCount,
707  errorCount);
708 
709  /*
710  // TODO: test values after transformCSVStringToSymbolArray()
711  aSymbol = v[0];
712 
713  TTTestAssertion("3 new TTSymbols have expected values",
714  aSymbol == TT("tango") &&
715  //v[1] == TT("wilco") &&
716  //v[2] == TT("1977") &&
717  v.size() == 3,
718  testAssertionCount,
719  errorCount);
720  */
721 
722  v.clear();
723 
724 }
725 
726 
727 void TTValueTestNumericTransformations(int& errorCount, int&testAssertionCount)
728 {
729  TTTestLog("\n");
730  TTTestLog("Testing TTValue numeric transformations");
731 
732 
733  /****************************************************************************************************/
734  TTTestLog("\n");
735  TTTestLog("Testing clip()");
736  /****************************************************************************************************/
737 
738 
739  // TTFloat32
740 
741  TTValue v1;
742 
743  v1 = TTFloat32(3.14);
744  v1.clip(6.0, 12.0);
745  TTTestAssertion("positive TTFloat32 clipped (out of lower bound)",
746  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(6.0)),
747  testAssertionCount,
748  errorCount);
749 
750  v1 = TTFloat32(3.14);
751  v1.clip(0.0, 4.0);
752  TTTestAssertion("positive TTFloat32 not clipped (within range)",
753  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(3.14)),
754  testAssertionCount,
755  errorCount);
756 
757  v1 = TTFloat32(3.14);
758  v1.clip(0.0, 2.0);
759  TTTestAssertion("positive TTFloat32 clipped (out of upper bound)",
760  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(2.0)),
761  testAssertionCount,
762  errorCount);
763 
764  v1 = TTFloat32(-3.14);
765  v1.clip(-2.0, 0.0);
766  TTTestAssertion("negative TTFloat32 clipped (out of lower bound)",
767  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(-2.0)),
768  testAssertionCount,
769  errorCount);
770 
771  v1 = TTFloat32(-3.14);
772  v1.clip(-4.0, 0.0);
773  TTTestAssertion("negative TTFloat32 not clipped (within range)",
774  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(-3.14)),
775  testAssertionCount,
776  errorCount);
777 
778  v1 = TTFloat32(-3.14);
779  v1.clip(-8.0, -4.0);
780  TTTestAssertion("negative TTFloat32 clipped (out of upper bound)",
781  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(-4.0)),
782  testAssertionCount,
783  errorCount);
784 
785 
786 
787  // TTFloat64
788 
789  v1 = TTFloat64(3.14);
790  v1.clip(6.0, 12.0);
791  TTTestAssertion("positive TTFloat64 clipped (out of lower bound)",
792  TTTestFloatEquivalence(double(v1), 6.0),
793  testAssertionCount,
794  errorCount);
795 
796  v1 = TTFloat64(3.14);
797  v1.clip(0.0, 4.0);
798  TTTestAssertion("positive TTFloat64 not clipped (within range)",
799  TTTestFloatEquivalence(double(v1), 3.14),
800  testAssertionCount,
801  errorCount);
802 
803  v1 = TTFloat64(3.14);
804  v1.clip(0.0, 2.0);
805  TTTestAssertion("positive TTFloat64 clipped (out of upper bound)",
806  TTTestFloatEquivalence(double(v1), 2.0),
807  testAssertionCount,
808  errorCount);
809 
810  v1 = TTFloat64(-3.14);
811  v1.clip(-2.0, 0.0);
812  TTTestAssertion("negative TTFloat64 clipped (out of lower bound)",
813  TTTestFloatEquivalence(double(v1), -2.0),
814  testAssertionCount,
815  errorCount);
816 
817  v1 = TTFloat64(-3.14);
818  v1.clip(-4.0, 0.0);
819  TTTestAssertion("negative TTFloat64 not clipped (within range)",
820  TTTestFloatEquivalence(double(v1), -3.14),
821  testAssertionCount,
822  errorCount);
823 
824  v1 = TTFloat64(-3.14);
825  v1.clip(-8.0, -4.0);
826  TTTestAssertion("negative TTFloat64 clipped (out of upper bound)",
827  TTTestFloatEquivalence(double(v1), -4.0),
828  testAssertionCount,
829  errorCount);
830 
831 
832 
833  // TTInt8
834 
835  v1 = TTInt8(3);
836  v1.clip(6, 12);
837  TTTestAssertion("positive TTInt8 clipped (out of lower bound)",
838  TTInt8(v1) == 6,
839  testAssertionCount,
840  errorCount);
841 
842  v1 = TTInt8(3);
843  v1.clip(0, 4);
844  TTTestAssertion("positive TTInt8 not clipped (within range)",
845  TTInt8(v1) == 3,
846  testAssertionCount,
847  errorCount);
848 
849  v1 = TTInt8(3);
850  v1.clip(0, 2);
851  TTTestAssertion("positive TTInt8 clipped (out of upper bound)",
852  TTInt8(v1) == 2,
853  testAssertionCount,
854  errorCount);
855 
856  v1 = TTInt8(-3);
857  v1.clip(-2, 0);
858  TTTestAssertion("negative TTInt8 clipped (out of lower bound)",
859  TTInt8(v1) == -2,
860  testAssertionCount,
861  errorCount);
862 
863  v1 = TTInt8(-3);
864  v1.clip(-4, 0);
865  TTTestAssertion("negative TTInt8 not clipped (within range)",
866  TTInt8(v1) == -3,
867  testAssertionCount,
868  errorCount);
869 
870  v1 = TTInt8(-3);
871  v1.clip(-8, -4);
872  TTTestAssertion("negative TTInt8 clipped (out of upper bound)",
873  TTInt8(v1) == -4,
874  testAssertionCount,
875  errorCount);
876 
877 
878 
879  // TTUInt8
880 
881  v1 = TTUInt8(3);
882  v1.clip(6, 12);
883  TTTestAssertion("positive TTUInt8 clipped (out of lower bound)",
884  TTUInt8(v1) == 6,
885  testAssertionCount,
886  errorCount);
887 
888  v1 = TTUInt8(3);
889  v1.clip(0, 4);
890  TTTestAssertion("positive TTUInt8 not clipped (within range)",
891  TTUInt8(v1) == 3,
892  testAssertionCount,
893  errorCount);
894 
895  v1 = TTUInt8(3);
896  v1.clip(0, 2);
897  TTTestAssertion("positive TTUInt8 clipped (out of upper bound)",
898  TTUInt8(v1) == 2,
899  testAssertionCount,
900  errorCount);
901 
902 
903 
904  // TTInt16
905 
906  v1 = TTInt16(3);
907  v1.clip(6, 12);
908  TTTestAssertion("positive TTInt16 clipped (out of lower bound)",
909  TTInt16(v1) == 6,
910  testAssertionCount,
911  errorCount);
912 
913  v1 = TTInt16(3);
914  v1.clip(0, 4);
915  TTTestAssertion("positive TTInt16 not clipped (within range)",
916  TTInt16(v1) == 3,
917  testAssertionCount,
918  errorCount);
919 
920  v1 = TTInt16(3);
921  v1.clip(0, 2);
922  TTTestAssertion("positive TTInt16 clipped (out of upper bound)",
923  TTInt16(v1) == 2,
924  testAssertionCount,
925  errorCount);
926 
927  v1 = TTInt16(-3);
928  v1.clip(-2, 0);
929  TTTestAssertion("negative TTInt16 clipped (out of lower bound)",
930  TTInt16(v1) == -2,
931  testAssertionCount,
932  errorCount);
933 
934  v1 = TTInt16(-3);
935  v1.clip(-4, 0);
936  TTTestAssertion("negative TTInt16 not clipped (within range)",
937  TTInt16(v1) == -3,
938  testAssertionCount,
939  errorCount);
940 
941  v1 = TTInt16(-3);
942  v1.clip(-8, -4);
943  TTTestAssertion("negative TTInt16 clipped (out of upper bound)",
944  TTInt16(v1) == -4,
945  testAssertionCount,
946  errorCount);
947 
948 
949 
950  // TTUInt16
951 
952  v1 = TTUInt16(3);
953  v1.clip(6, 12);
954  TTTestAssertion("positive TTUInt16 clipped (out of lower bound)",
955  TTUInt16(v1) == 6,
956  testAssertionCount,
957  errorCount);
958 
959  v1 = TTUInt16(3);
960  v1.clip(0, 4);
961  TTTestAssertion("positive TTUInt16 not clipped (within range)",
962  TTUInt16(v1) == 3,
963  testAssertionCount,
964  errorCount);
965 
966  v1 = TTUInt16(3);
967  v1.clip(0, 2);
968  TTTestAssertion("positive TTUInt16 clipped (out of upper bound)",
969  TTUInt16(v1) == 2,
970  testAssertionCount,
971  errorCount);
972 
973 
974 
975  // TTInt32 -- which is a classic "int" type
976 
977  v1 = 3;
978  v1.clip(6, 12);
979  TTTestAssertion("positive TTInt32 clipped (out of lower bound)",
980  TTInt32(v1) == 6,
981  testAssertionCount,
982  errorCount);
983 
984  v1 = 3;
985  v1.clip(0, 4);
986  TTTestAssertion("positive TTInt32 not clipped (within range)",
987  TTInt32(v1) == 3,
988  testAssertionCount,
989  errorCount);
990 
991  v1 = 3;
992  v1.clip(0, 2);
993  TTTestAssertion("positive TTInt32 clipped (out of upper bound)",
994  TTInt32(v1) == 2,
995  testAssertionCount,
996  errorCount);
997 
998  v1 = -3;
999  v1.clip(-2, 0);
1000  TTTestAssertion("negative TTInt32 clipped (out of lower bound)",
1001  TTInt32(v1) == -2,
1002  testAssertionCount,
1003  errorCount);
1004 
1005  v1 = -3;
1006  v1.clip(-4, 0);
1007  TTTestAssertion("negative TTInt32 not clipped (within range)",
1008  TTInt32(v1) == -3,
1009  testAssertionCount,
1010  errorCount);
1011 
1012  v1 = -3;
1013  v1.clip(-8, -4);
1014  TTTestAssertion("negative TTInt32 clipped (out of upper bound)",
1015  TTInt32(v1) == -4,
1016  testAssertionCount,
1017  errorCount);
1018 
1019 
1020 
1021  // TTUInt32
1022 
1023  v1 = TTUInt32(3);
1024  v1.clip(6, 12);
1025  TTTestAssertion("positive TTUInt32 clipped (out of lower bound)",
1026  TTUInt32(v1) == 6,
1027  testAssertionCount,
1028  errorCount);
1029 
1030  v1 = TTUInt32(3);
1031  v1.clip(0, 4);
1032  TTTestAssertion("positive TTUInt32 not clipped (within range)",
1033  TTUInt32(v1) == 3,
1034  testAssertionCount,
1035  errorCount);
1036 
1037  v1 = TTUInt32(3);
1038  v1.clip(0, 2);
1039  TTTestAssertion("positive TTUInt32 clipped (out of upper bound)",
1040  TTUInt32(v1) == 2,
1041  testAssertionCount,
1042  errorCount);
1043 
1044 
1045 
1046  // TTInt64
1047 
1048  v1 = TTInt64(3);
1049  v1.clip(6, 12);
1050  TTTestAssertion("positive TTInt64 clipped (out of lower bound)",
1051  TTInt64(v1) == 6,
1052  testAssertionCount,
1053  errorCount);
1054 
1055  v1 = TTInt64(3);
1056  v1.clip(0, 4);
1057  TTTestAssertion("positive TTInt64 not clipped (within range)",
1058  TTInt64(v1) == 3,
1059  testAssertionCount,
1060  errorCount);
1061 
1062  v1 = TTInt64(3);
1063  v1.clip(0, 2);
1064  TTTestAssertion("positive TTInt64 clipped (out of upper bound)",
1065  TTInt64(v1) == 2,
1066  testAssertionCount,
1067  errorCount);
1068 
1069  v1 = TTInt64(-3);
1070  v1.clip(-2, 0);
1071  TTTestAssertion("negative TTInt64 clipped (out of lower bound)",
1072  TTInt64(v1) == -2,
1073  testAssertionCount,
1074  errorCount);
1075 
1076  v1 = TTInt64(-3);
1077  v1.clip(-4, 0);
1078  TTTestAssertion("negative TTInt64 not clipped (within range)",
1079  TTInt64(v1) == -3,
1080  testAssertionCount,
1081  errorCount);
1082 
1083  v1 = TTInt64(-3);
1084  v1.clip(-8, -4);
1085  TTTestAssertion("negative TTInt64 clipped (out of upper bound)",
1086  TTInt64(v1) == -4,
1087  testAssertionCount,
1088  errorCount);
1089 
1090 
1091 
1092  // TTUInt64
1093 
1094  v1 = TTUInt64(3);
1095  v1.clip(6, 12);
1096  TTTestAssertion("positive TTUInt64 clipped (out of lower bound)",
1097  TTUInt64(v1) == 6,
1098  testAssertionCount,
1099  errorCount);
1100 
1101  v1 = TTUInt64(3);
1102  v1.clip(0, 4);
1103  TTTestAssertion("positive TTUInt64 not clipped (within range)",
1104  TTUInt64(v1) == 3,
1105  testAssertionCount,
1106  errorCount);
1107 
1108  v1 = TTUInt64(3);
1109  v1.clip(0, 2);
1110  TTTestAssertion("positive TTUInt64 clipped (out of upper bound)",
1111  TTUInt64(v1) == 2,
1112  testAssertionCount,
1113  errorCount);
1114 
1115  // And a final test on an array
1116  TTValue v2;
1117  v2.resize(6);
1118  v2[0] = 2.5;
1119  v2[1] = 2;
1120  v2[2] = 3.14;
1121  v2[3] = 4;
1122  v2[4] = 6.28;
1123  v2[5] = 6;
1124 
1125  v2.clip(3.0, 5.0);
1126 
1127  TTFloat64 aFloat = v2[0];
1128  TTInt32 anInt = v2[1];
1129 
1130  TTTestAssertion("array double clipped (out of lower bound)",
1131  TTTestFloatEquivalence(aFloat, 3.0),
1132  testAssertionCount,
1133  errorCount);
1134 
1135  TTTestAssertion("array integer clipped (out of lower bound)",
1136  anInt == 3,
1137  testAssertionCount,
1138  errorCount);
1139 
1140  aFloat = v2[2];
1141  TTTestAssertion("array double not clipped (within range)",
1142  TTTestFloatEquivalence(aFloat, 3.14),
1143  testAssertionCount,
1144  errorCount);
1145 
1146  anInt = v2[3];
1147  TTTestAssertion("array integer not clipped (within range)",
1148  anInt == 4,
1149  testAssertionCount,
1150  errorCount);
1151 
1152  aFloat = v2[4];
1153  TTTestAssertion("array double clipped (out of upper bound)",
1154  TTTestFloatEquivalence(aFloat, 5.0),
1155  testAssertionCount,
1156  errorCount);
1157 
1158  anInt = v2[5];
1159  TTTestAssertion("array integer clipped (out of upper bound)",
1160  anInt == 5,
1161  testAssertionCount,
1162  errorCount);
1163 
1164 
1165  /****************************************************************************************************/
1166  TTTestLog("\n");
1167  TTTestLog("Testing cliplow()");
1168  /****************************************************************************************************/
1169 
1170  // TTFloat32
1171 
1172  v1 = TTFloat32(3.14);
1173  v1.cliplow(6.0);
1174  TTTestAssertion("positive TTFloat32 clipped at lower limit (out of lower bound)",
1175  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(6.0)),
1176  testAssertionCount,
1177  errorCount);
1178 
1179  v1 = TTFloat32(3.14);
1180  v1.cliplow(0.0);
1181  TTTestAssertion("positive TTFloat32 not clipped at lower limit (within range)",
1182  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(3.14)),
1183  testAssertionCount,
1184  errorCount);
1185 
1186  v1 = TTFloat32(-3.14);
1187  v1.cliplow(-2.0);
1188  TTTestAssertion("negative TTFloat32 clipped at lower limit (out of lower bound)",
1189  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(-2.0)),
1190  testAssertionCount,
1191  errorCount);
1192 
1193  v1 = TTFloat32(-3.14);
1194  v1.cliplow(-4.0);
1195  TTTestAssertion("negative TTFloat32 not clipped at lower limit (within range)",
1196  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(-3.14)),
1197  testAssertionCount,
1198  errorCount);
1199 
1200 
1201 
1202  // TTFloat64
1203 
1204  v1 = TTFloat64(3.14);
1205  v1.cliplow(6.0);
1206  TTTestAssertion("positive TTFloat64 clipped at lower limit (out of lower bound)",
1207  TTTestFloatEquivalence(double(v1), 6.0),
1208  testAssertionCount,
1209  errorCount);
1210 
1211  v1 = 3.14;
1212  v1.cliplow(0.0);
1213  TTTestAssertion("positive TTFloat64 not clipped at lower limit (within range)",
1214  TTTestFloatEquivalence(double(v1), 3.14),
1215  testAssertionCount,
1216  errorCount);
1217 
1218  v1 = -3.14;
1219  v1.cliplow(-2.0);
1220  TTTestAssertion("negative TTFloat64 clipped at lower limit (out of lower bound)",
1221  TTTestFloatEquivalence(double(v1), -2.0),
1222  testAssertionCount,
1223  errorCount);
1224 
1225  v1 = -3.14;
1226  v1.cliplow(-4.0);
1227  TTTestAssertion("negative TTFloat64 not clipped at lower limit (within range)",
1228  TTTestFloatEquivalence(double(v1), -3.14),
1229  testAssertionCount,
1230  errorCount);
1231 
1232 
1233 
1234  // TTInt8
1235 
1236  v1 = TTInt8(3);
1237  v1.cliplow(6);
1238  TTTestAssertion("positive TTInt8 clipped at lower limit (out of lower bound)",
1239  TTInt8(v1) == 6,
1240  testAssertionCount,
1241  errorCount);
1242 
1243  v1 = TTInt8(3);
1244  v1.cliplow(0);
1245  TTTestAssertion("positive TTInt8 not clipped at lower limit (within range)",
1246  TTInt8(v1) == 3,
1247  testAssertionCount,
1248  errorCount);
1249 
1250  v1 = TTInt8(-3);
1251  v1.cliplow(-2);
1252  // TTFloat64 myFloat = v1.get;
1253  TTTestAssertion("negative TTInt8 clipped at lower limit (out of lower bound)",
1254  TTInt8(v1) == -2,
1255  testAssertionCount,
1256  errorCount);
1257 
1258  v1 = TTInt8(-3);
1259  v1.cliplow(-4);
1260  // TTFloat64 myFloat = v1.get;
1261  TTTestAssertion("negative TTInt8 not clipped at lower limit (within range)",
1262  TTInt8(v1) == -3,
1263  testAssertionCount,
1264  errorCount);
1265 
1266 
1267 
1268  // TTUInt8
1269 
1270  v1 = TTUInt8(3);
1271  v1.cliplow(6);
1272  TTTestAssertion("positive TTUInt8 clipped at lower limit (out of lower bound)",
1273  TTUInt8(v1) == 6,
1274  testAssertionCount,
1275  errorCount);
1276 
1277  v1 = TTUInt8(3);
1278  v1.cliplow(0);
1279  TTTestAssertion("positive TTUInt8 not clipped at lower limit (within range)",
1280  TTUInt8(v1) == 3,
1281  testAssertionCount,
1282  errorCount);
1283 
1284 
1285 
1286  // TTInt16
1287 
1288  v1 = TTInt16(3);
1289  v1.cliplow(6);
1290  TTTestAssertion("positive TTInt16 clipped at lower limit (out of lower bound)",
1291  TTInt16(v1) == 6,
1292  testAssertionCount,
1293  errorCount);
1294 
1295  v1 = TTInt16(3);
1296  v1.cliplow(0);
1297  TTTestAssertion("positive TTInt16 not clipped at lower limit (within range)",
1298  TTInt16(v1) == 3,
1299  testAssertionCount,
1300  errorCount);
1301 
1302  v1 = TTInt16(-3);
1303  v1.cliplow(-2);
1304  // TTFloat64 myFloat = v1.get;
1305  TTTestAssertion("negative TTInt16 clipped at lower limit (out of lower bound)",
1306  TTInt16(v1) == -2,
1307  testAssertionCount,
1308  errorCount);
1309 
1310  v1 = TTInt16(-3);
1311  v1.cliplow(-4);
1312  // TTFloat64 myFloat = v1.get;
1313  TTTestAssertion("negative TTInt16 not clipped at lower limit (within range)",
1314  TTInt16(v1) == -3,
1315  testAssertionCount,
1316  errorCount);
1317 
1318 
1319 
1320  // TTUInt16
1321 
1322  v1 = TTUInt16(3);
1323  v1.cliplow(6);
1324  TTTestAssertion("positive TTUInt16 clipped at lower limit (out of lower bound)",
1325  TTUInt16(v1) == 6,
1326  testAssertionCount,
1327  errorCount);
1328 
1329  v1 = TTUInt16(3);
1330  v1.cliplow(0);
1331  TTTestAssertion("positive TTUInt16 not clipped at lower limit (within range)",
1332  TTUInt16(v1) == 3,
1333  testAssertionCount,
1334  errorCount);
1335 
1336 
1337 
1338  // TTInt32 -- the classic C "int" type
1339 
1340  v1 = 3;
1341  v1.cliplow(6);
1342  TTTestAssertion("positive TTInt32 clipped at lower limit (out of lower bound)",
1343  TTInt32(v1) == 6,
1344  testAssertionCount,
1345  errorCount);
1346 
1347  v1 = 3;
1348  v1.cliplow(0);
1349  TTTestAssertion("positive TTInt32 not clipped at lower limit (within range)",
1350  TTInt32(v1) == 3,
1351  testAssertionCount,
1352  errorCount);
1353 
1354  v1 = -3;
1355  v1.cliplow(-2);
1356  // TTFloat64 myFloat = v1.get;
1357  TTTestAssertion("negative TTInt32 clipped at lower limit (out of lower bound)",
1358  TTInt32(v1) == -2,
1359  testAssertionCount,
1360  errorCount);
1361 
1362  v1 = -3;
1363  v1.cliplow(-4);
1364  // TTFloat64 myFloat = v1.get;
1365  TTTestAssertion("negative TTInt32 not clipped at lower limit (within range)",
1366  TTInt32(v1) == -3,
1367  testAssertionCount,
1368  errorCount);
1369 
1370 
1371 
1372  // TTUInt32
1373 
1374  v1 = TTUInt32(3);
1375  v1.cliplow(6);
1376  TTTestAssertion("positive TTUInt32 clipped at lower limit (out of lower bound)",
1377  TTUInt32(v1) == 6,
1378  testAssertionCount,
1379  errorCount);
1380 
1381  v1 = TTUInt32(3);
1382  v1.cliplow(0);
1383  TTTestAssertion("positive TTUInt32 not clipped at lower limit (within range)",
1384  TTUInt32(v1) == 3,
1385  testAssertionCount,
1386  errorCount);
1387 
1388 
1389 
1390  // TTInt64
1391 
1392  v1 = TTInt64(3);
1393  v1.cliplow(6);
1394  TTTestAssertion("positive TTInt64 clipped at lower limit (out of lower bound)",
1395  TTInt64(v1) == 6,
1396  testAssertionCount,
1397  errorCount);
1398 
1399  v1 = TTInt64(3);
1400  v1.cliplow(0);
1401  TTTestAssertion("positive TTInt64 not clipped at lower limit (within range)",
1402  TTInt64(v1) == 3,
1403  testAssertionCount,
1404  errorCount);
1405 
1406  v1 = TTInt64(-3);
1407  v1.cliplow(-2);
1408  // TTFloat64 myFloat = v1.get;
1409  TTTestAssertion("negative TTInt64 clipped at lower limit (out of lower bound)",
1410  TTInt64(v1) == -2,
1411  testAssertionCount,
1412  errorCount);
1413 
1414  v1 = TTInt64(-3);
1415  v1.cliplow(-4);
1416  // TTFloat64 myFloat = v1.get;
1417  TTTestAssertion("negative TTInt64 not clipped at lower limit (within range)",
1418  TTInt64(v1) == -3,
1419  testAssertionCount,
1420  errorCount);
1421 
1422 
1423 
1424  // TTUInt64
1425 
1426  v1 = TTUInt64(3);
1427  v1.cliplow(6);
1428  TTTestAssertion("positive TTUInt64 clipped at lower limit (out of lower bound)",
1429  TTUInt64(v1) == 6,
1430  testAssertionCount,
1431  errorCount);
1432 
1433  v1 = TTUInt64(3);
1434  v1.cliplow(0);
1435  TTTestAssertion("positive TTUInt64 not clipped at lower limit (within range)",
1436  TTUInt64(v1) == 3,
1437  testAssertionCount,
1438  errorCount);
1439 
1440  // And a final test on an array
1441  v2.resize(4);
1442  v2[0] = 2.5;
1443  v2[1] = 2;
1444  v2[2] = 3.14;
1445  v2[3] = 4;
1446 
1447  v2.cliplow(3.0);
1448 
1449  aFloat = v2[0];
1450  TTTestAssertion("array double clipped at lower limit (out of lower bound)",
1451  TTTestFloatEquivalence(aFloat, 3.0),
1452  testAssertionCount,
1453  errorCount);
1454 
1455  anInt = v2[1];
1456  TTTestAssertion("array integer clipped at lower limit (out of lower bound)",
1457  anInt == 3,
1458  testAssertionCount,
1459  errorCount);
1460 
1461  aFloat = v2[2];
1462  TTTestAssertion("array double not clipped at lower limit (within range)",
1463  TTTestFloatEquivalence(aFloat, 3.14),
1464  testAssertionCount,
1465  errorCount);
1466 
1467  anInt = v2[3];
1468  TTTestAssertion("array integer not clipped at lower limit (within range)",
1469  anInt == 4,
1470  testAssertionCount,
1471  errorCount);
1472 
1473 
1474 
1475 
1476  /****************************************************************************************************/
1477  TTTestLog("\n");
1478  TTTestLog("Testing cliphigh()");
1479  /****************************************************************************************************/
1480 
1481 
1482  // TTFloat32
1483 
1484  v1 = TTFloat32(3.14);
1485  v1.cliphigh(4.0);
1486  TTTestAssertion("positive TTFloat32 not clipped at higher limit (within range)",
1487  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(3.14)),
1488  testAssertionCount,
1489  errorCount);
1490 
1491  v1 = TTFloat32(3.14);
1492  v1.cliphigh(2.0);
1493  TTTestAssertion("positive TTFloat32 clipped at higher limit (out of upper bound)",
1494  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(2.0)),
1495  testAssertionCount,
1496  errorCount);
1497 
1498  v1 = TTFloat32(-3.14);
1499  v1.cliphigh(0.0);
1500  TTTestAssertion("negative TTFloat32 not clipped at higher limit (within range)",
1501  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(-3.14)),
1502  testAssertionCount,
1503  errorCount);
1504 
1505  v1 = TTFloat32(-3.14);
1506  v1.cliphigh(-4.0);
1507  TTTestAssertion("negative TTFloat32 clipped at higher limit (out of upper bound)",
1508  TTTestFloatEquivalence(TTFloat32(v1), TTFloat32(-4.0)),
1509  testAssertionCount,
1510  errorCount);
1511 
1512 
1513 
1514  // TTFloat64
1515 
1516  v1 = TTFloat64(3.14);
1517  v1.cliphigh(4.0);
1518  TTTestAssertion("positive TTFloat64 not clipped at higher limit (within range)",
1519  TTTestFloatEquivalence(double(v1), 3.14),
1520  testAssertionCount,
1521  errorCount);
1522 
1523  v1 = TTFloat64(3.14);
1524  v1.cliphigh(2.0);
1525  TTTestAssertion("positive TTFloat64 clipped at higher limit (out of upper bound)",
1526  TTTestFloatEquivalence(double(v1), 2.0),
1527  testAssertionCount,
1528  errorCount);
1529 
1530  v1 = TTFloat64(-3.14);
1531  v1.cliphigh(0.0);
1532  TTTestAssertion("negative TTFloat64 not clipped at higher limit (within range)",
1533  TTTestFloatEquivalence(double(v1), -3.14),
1534  testAssertionCount,
1535  errorCount);
1536 
1537  v1 = TTFloat64(-3.14);
1538  v1.cliphigh(-4.0);
1539  TTTestAssertion("negative TTFloat64 clipped at higher limit (out of upper bound)",
1540  TTTestFloatEquivalence(double(v1), -4.0),
1541  testAssertionCount,
1542  errorCount);
1543 
1544 
1545 
1546  // TTInt8
1547 
1548  v1 = TTInt8(3);
1549  v1.cliphigh(4);
1550  TTTestAssertion("positive TTInt8 not clipped at higher limit (within range)",
1551  TTInt8(v1) == 3,
1552  testAssertionCount,
1553  errorCount);
1554 
1555  v1 = TTInt8(3);
1556  v1.cliphigh(2);
1557  TTTestAssertion("positive TTInt8 clipped at higher limit (out of upper bound)",
1558  TTInt8(v1) == 2,
1559  testAssertionCount,
1560  errorCount);
1561 
1562  v1 = TTInt8(-3);
1563  v1.cliphigh(0);
1564  TTTestAssertion("negative TTInt8 not clipped at higher limit (within range)",
1565  TTInt8(v1) == -3,
1566  testAssertionCount,
1567  errorCount);
1568 
1569  v1 = TTInt8(-3);
1570  v1.cliphigh(-4);
1571  TTTestAssertion("negative TTInt8 clipped at higher limit (out of upper bound)",
1572  TTInt8(v1) == -4,
1573  testAssertionCount,
1574  errorCount);
1575 
1576 
1577 
1578  // TTUInt8
1579 
1580  v1 = TTUInt8(3);
1581  v1.cliphigh(4);
1582  TTTestAssertion("positive TTUInt8 not clipped at higher limit (within range)",
1583  TTUInt8(v1) == 3,
1584  testAssertionCount,
1585  errorCount);
1586 
1587  v1 = TTUInt8(3);
1588  v1.cliphigh(2);
1589  TTTestAssertion("positive TTUInt8 clipped at higher limit (out of upper bound)",
1590  TTUInt8(v1) == 2,
1591  testAssertionCount,
1592  errorCount);
1593 
1594 
1595 
1596  // TTInt16
1597 
1598  v1 = TTInt16(3);
1599  v1.cliphigh(4);
1600  TTTestAssertion("positive TTInt16 not clipped at higher limit (within range)",
1601  TTInt16(v1) == 3,
1602  testAssertionCount,
1603  errorCount);
1604 
1605  v1 = TTInt16(3);
1606  v1.cliphigh(2);
1607  TTTestAssertion("positive TTInt16 clipped at higher limit (out of upper bound)",
1608  TTInt16(v1) == 2,
1609  testAssertionCount,
1610  errorCount);
1611 
1612  v1 = TTInt16(-3);
1613  v1.cliphigh(0);
1614  TTTestAssertion("negative TTInt16 not clipped at higher limit (within range)",
1615  TTInt16(v1) == -3,
1616  testAssertionCount,
1617  errorCount);
1618 
1619  v1 = TTInt16(-3);
1620  v1.cliphigh(-4);
1621  TTTestAssertion("negative TTInt16 clipped at higher limit (out of upper bound)",
1622  TTInt16(v1) == -4,
1623  testAssertionCount,
1624  errorCount);
1625 
1626 
1627 
1628  // TTUInt16
1629 
1630  v1 = TTUInt16(3);
1631  v1.cliphigh(4);
1632  TTTestAssertion("positive TTUInt16 not clipped at higher limit (within range)",
1633  TTUInt16(v1) == 3,
1634  testAssertionCount,
1635  errorCount);
1636 
1637  v1 = TTUInt16(3);
1638  v1.cliphigh(2);
1639  TTTestAssertion("positive TTUInt16 clipped at higher limit (out of upper bound)",
1640  TTUInt16(v1) == 2,
1641  testAssertionCount,
1642  errorCount);
1643 
1644 
1645 
1646  // TTInt32 -- the classic C "int" type
1647 
1648  v1 = 3;
1649  v1.cliphigh(4);
1650  TTTestAssertion("positive TTInt32 not clipped at higher limit (within range)",
1651  TTInt32(v1) == 3,
1652  testAssertionCount,
1653  errorCount);
1654 
1655  v1 = 3;
1656  v1.cliphigh(2);
1657  TTTestAssertion("positive TTInt32 clipped at higher limit (out of upper bound)",
1658  TTInt32(v1) == 2,
1659  testAssertionCount,
1660  errorCount);
1661 
1662  v1 = -3;
1663  v1.cliphigh(0);
1664  TTTestAssertion("negative TTInt32 not clipped at higher limit (within range)",
1665  TTInt32(v1) == -3,
1666  testAssertionCount,
1667  errorCount);
1668 
1669  v1 = -3;
1670  v1.cliphigh(-4);
1671  TTTestAssertion("negative TTInt32 clipped at higher limit (out of upper bound)",
1672  TTInt32(v1) == -4,
1673  testAssertionCount,
1674  errorCount);
1675 
1676 
1677 
1678  // TTUInt32
1679 
1680  v1 = TTUInt32(3);
1681  v1.cliphigh(4);
1682  TTTestAssertion("positive TTUInt32 not clipped at higher limit (within range)",
1683  TTUInt32(v1) == 3,
1684  testAssertionCount,
1685  errorCount);
1686 
1687  v1 = TTUInt32(3);
1688  v1.cliphigh(2);
1689  TTTestAssertion("positive TTUInt32 clipped at higher limit (out of upper bound)",
1690  TTUInt32(v1) == 2,
1691  testAssertionCount,
1692  errorCount);
1693 
1694 
1695 
1696  // TTInt64
1697 
1698  v1 = TTInt64(3);
1699  v1.cliphigh(4);
1700  TTTestAssertion("positive TTInt64 not clipped at higher limit (within range)",
1701  TTInt64(v1) == 3,
1702  testAssertionCount,
1703  errorCount);
1704 
1705  v1 = TTInt64(3);
1706  v1.cliphigh(2);
1707  TTTestAssertion("positive TTInt64 clipped at higher limit (out of upper bound)",
1708  TTInt64(v1) == 2,
1709  testAssertionCount,
1710  errorCount);
1711 
1712  v1 = TTInt64(-3);
1713  v1.cliphigh(0);
1714  TTTestAssertion("negative TTInt64 not clipped at higher limit (within range)",
1715  TTInt64(v1) == -3,
1716  testAssertionCount,
1717  errorCount);
1718 
1719  v1 = TTInt64(-3);
1720  v1.cliphigh(-4);
1721  TTTestAssertion("negative TTInt64 clipped at higher limit (out of upper bound)",
1722  TTInt64(v1) == -4,
1723  testAssertionCount,
1724  errorCount);
1725 
1726 
1727 
1728  // TTUInt64
1729 
1730  v1 = TTUInt64(3);
1731  v1.cliphigh(4);
1732  TTTestAssertion("positive TTUInt64 not clipped at higher limit (within range)",
1733  TTUInt64(v1) == 3,
1734  testAssertionCount,
1735  errorCount);
1736 
1737  v1 = TTUInt64(3);
1738  v1.cliphigh(2);
1739  TTTestAssertion("positive TTUInt64 clipped at higher limit (out of upper bound)",
1740  TTUInt64(v1) == 2,
1741  testAssertionCount,
1742  errorCount);
1743 
1744  // And a final test on an array
1745  v2.resize(4);
1746  v2[0] = 3.14;
1747  v2[1] = 4;
1748  v2[2] = 6.28;
1749  v2[3] = 6;
1750 
1751  v2.cliphigh(5.0);
1752 
1753  aFloat = v2[0];
1754  TTTestAssertion("array double not clipped at higher limit (within range)",
1755  TTTestFloatEquivalence(aFloat, 3.14),
1756  testAssertionCount,
1757  errorCount);
1758 
1759  anInt = v2[1];
1760  TTTestAssertion("array integer not clipped at higher limit (within range)",
1761  anInt == 4,
1762  testAssertionCount,
1763  errorCount);
1764 
1765  aFloat = v2[2];
1766  TTTestAssertion("array double clipped at higher limit (out of upper bound)",
1767  TTTestFloatEquivalence(aFloat, 5.0),
1768  testAssertionCount,
1769  errorCount);
1770 
1771  anInt = v2[3];
1772  TTTestAssertion("array integer clipped at higher limit (out of upper bound)",
1773  anInt == 5,
1774  testAssertionCount,
1775  errorCount);
1776 
1777  // TODO: test round()
1778  /****************************************************************************************************/
1779  // TTTestLog("\n");
1780  // TTTestLog("Testing round()");
1781  /****************************************************************************************************/
1782 
1783 
1784  // TODO: test truncate()
1785  /****************************************************************************************************/
1786  // TTTestLog("\n");
1787  // TTTestLog("Testing truncate()");
1788  /****************************************************************************************************/
1789 
1790 
1791  // TODO: test booleanize()
1792  /****************************************************************************************************/
1793  // TTTestLog("\n");
1794  // TTTestLog("Testing booleanize()");
1795  /****************************************************************************************************/
1796 
1797 }
1798 
1799 
1800 void TTValueTestOperators(int& errorCount, int&testAssertionCount)
1801 {
1802  TTTestLog("\n");
1803  TTTestLog("Testing TTValue operators");
1804 
1805  /****************************************************************************************************/
1806  TTTestLog("\n");
1807  TTTestLog("Testing < operator");
1808  /****************************************************************************************************/
1809 
1810  TTValue v1, v2;
1811 
1812  // TTInt8
1813  v1 = TTInt8(-12);
1814  v2 = TTInt8(120);
1815  TTTestAssertion("TTInt8 < operator comparison (with A < B)",
1816  v1 < v2,
1817  testAssertionCount,
1818  errorCount);
1819 
1820  TTTestAssertion("TTInt8 < operator comparison (with A > B)",
1821  !(v2 < v1),
1822  testAssertionCount,
1823  errorCount);
1824 
1825  // TTUInt8
1826  v1 = TTUInt8(12);
1827  v2 = TTUInt8(204);
1828  TTTestAssertion("TTUInt8 < operator comparison (with A < B)",
1829  v1 < v2,
1830  testAssertionCount,
1831  errorCount);
1832 
1833  TTTestAssertion("TTUInt8 < operator comparison (with A > B)",
1834  !(v2 < v1),
1835  testAssertionCount,
1836  errorCount);
1837 
1838  // TTInt16
1839  v1 = TTInt16(-12);
1840  v2 = TTInt16(204);
1841  TTTestAssertion("TTInt16 < operator comparison (with A < B)",
1842  v1 < v2,
1843  testAssertionCount,
1844  errorCount);
1845 
1846  TTTestAssertion("TTInt16 < operator comparison (with A > B)",
1847  !(v2 < v1),
1848  testAssertionCount,
1849  errorCount);
1850 
1851  // TTUInt16
1852  v1 = TTUInt16(12);
1853  v2 = TTUInt16(204);
1854  TTTestAssertion("TTUInt16 < operator comparison (with A < B)",
1855  v1 < v2,
1856  testAssertionCount,
1857  errorCount);
1858 
1859  TTTestAssertion("TTUInt16 < operator comparison (with A > B)",
1860  !(v2 < v1),
1861  testAssertionCount,
1862  errorCount);
1863 
1864  // TTInt32
1865  v1 = -12;
1866  v2 = 204;
1867  TTTestAssertion("TTInt32 < operator comparison (with A < B)",
1868  v1 < v2,
1869  testAssertionCount,
1870  errorCount);
1871 
1872  TTTestAssertion("TTInt32 < operator comparison (with A > B)",
1873  !(v2 < v1),
1874  testAssertionCount,
1875  errorCount);
1876 
1877  // TTUInt32
1878  v1 = TTUInt32(12);
1879  v2 = TTUInt32(204);
1880  TTTestAssertion("TTUInt32 < operator comparison (with A < B)",
1881  v1 < v2,
1882  testAssertionCount,
1883  errorCount);
1884 
1885  TTTestAssertion("TTUInt32 < operator comparison (with A > B)",
1886  !(v2 < v1),
1887  testAssertionCount,
1888  errorCount);
1889 
1890  // TTInt64
1891  v1 = TTInt64(-12);
1892  v2 = TTInt64(204);
1893  TTTestAssertion("TTInt64 < operator comparison (with A < B)",
1894  v1 < v2,
1895  testAssertionCount,
1896  errorCount);
1897 
1898  TTTestAssertion("TTInt64 < operator comparison (with A > B)",
1899  !(v2 < v1),
1900  testAssertionCount,
1901  errorCount);
1902 
1903  // TTUInt64
1904  v1 = TTUInt64(12);
1905  v2 = TTUInt64(204);
1906  TTTestAssertion("TTUInt64 < operator comparison (with A < B)",
1907  v1 < v2,
1908  testAssertionCount,
1909  errorCount);
1910 
1911  TTTestAssertion("TTUInt64 < operator comparison (with A > B)",
1912  !(v2 < v1),
1913  testAssertionCount,
1914  errorCount);
1915 
1916  // TTFloat32
1917  v1 = TTFloat32(-12);
1918  v2 = TTFloat32(204);
1919  TTTestAssertion("TTFloat32 < operator comparison (with A < B)",
1920  v1 < v2,
1921  testAssertionCount,
1922  errorCount);
1923 
1924  TTTestAssertion("TTFloat32 < operator comparison (with A > B)",
1925  !(v2 < v1),
1926  testAssertionCount,
1927  errorCount);
1928 
1929  // TTFloat64
1930  v1 = TTFloat64(-12);
1931  v2 = TTFloat64(204);
1932  TTTestAssertion("TTFloat64 < operator comparison (with A < B)",
1933  v1 < v2,
1934  testAssertionCount,
1935  errorCount);
1936 
1937  TTTestAssertion("TTFloat64 < operator comparison (with A > B)",
1938  !(v2 < v1),
1939  testAssertionCount,
1940  errorCount);
1941 
1942  // TTSymbol
1943  v1 = TTSymbol("azerty");
1944  v2 = TTSymbol("qwerty");
1945  TTTestAssertion("TTSymbol < operator comparison (with A < B)",
1946  v1 < v2,
1947  testAssertionCount,
1948  errorCount);
1949 
1950  TTTestAssertion("TTSymbol < operator comparison (with A > B)",
1951  !(v2 < v1),
1952  testAssertionCount,
1953  errorCount);
1954 
1955  // TTString
1956  // BUG : if we used the value v1 and v2,
1957  // there is a problem during the copy of the memory (cf memcpy in copy method)
1958  // this bug is relative to a line introduced and commented out into TTValueTestBasic
1959  TTValue s1 = TTString("azerty");
1960  TTValue s2 = TTString("qwerty");
1961  TTTestAssertion("TTString < operator comparison (with A < B)",
1962  s1 < s2,
1963  testAssertionCount,
1964  errorCount);
1965 
1966  TTTestAssertion("TTString < operator comparison (with A > B)",
1967  !(s2 < s1),
1968  testAssertionCount,
1969  errorCount);
1970 
1971  // TTPtr ?
1972 
1973  // TODO: test ==
1974  // TODO: test =
1975  // TODO: test casting
1976  // TODO: should + be concatenating elements to create a new value of a+b element count?
1977 }
1978 
1979 
1980 // TODO: Benchmarking
1981 
1982 
1983 TTErr TTValueTest::test(TTValue& returnedTestInfo)
1984 {
1985  int errorCount = 0;
1986  int testAssertionCount = 0;
1987 
1988  TTValueTestFloatAssertion(errorCount, testAssertionCount);
1989  TTValueTestBasic(errorCount, testAssertionCount);
1990  TTValueTestStringConversion(errorCount, testAssertionCount);
1991  TTValueTestNumericTransformations(errorCount, testAssertionCount);
1992  TTValueTestOperators(errorCount, testAssertionCount);
1993 
1994  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
1995 }
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
void fromString(TTBoolean numberAsSymbol=NO)
Convert a single string into individual elements using space to divide items.
Definition: TTValue.h:386
TTString toString(TTBoolean quotes=YES) const
Return the content as a single string with spaces between elements.
Definition: TTValue.h:351
std::uint64_t TTUInt64
64 bit unsigned integer
Definition: TTBase.h:180
size_type size() const noexcept
Return the number of elements.
Symbol type.
Definition: TTBase.h:282
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
std::int64_t TTInt64
64 bit signed integer
Definition: TTBase.h:179
std::int16_t TTInt16
16 bit signed integer
Definition: TTBase.h:175
void cliplow(const TTFloat64 &aLowBound)
Clip numerical values below a specified boundary.
Definition: TTValue.h:289
64-bit floating point
Definition: TTBase.h:272
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
float TTFloat32
32 bit floating point number
Definition: TTBase.h:187
TTErr transformCSVStringToSymbolArray()
Convert a comma-separated-value string into an array of TTSymbols.
Definition: TTValue.h:463
void cliphigh(const TTFloat64 &aHighBound)
Clip numerical values above a specified boundary.
Definition: TTValue.h:299
void TTValueTestFloatAssertion(int &errorCount, int &testAssertionCount)
Test the method used to compare floats for equity.
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
void clip(const TTFloat64 &aLowBound, const TTFloat64 &aHighBound)
Clip numerical values between low and high boundaries.
Definition: TTValue.h:279
void clear()
Clear all values from the vector, leaving with size of 0.
Definition: TTValue.h:131
32-bit signed integer, range is -2,147,483,648 through 2,147,483,647.
Definition: TTBase.h:277
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
signed char TTInt8
8 bit signed integer (char)
Definition: TTBase.h:173
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
TTValueTest is an class used for unit tests of the TTValue class.
32-bit unsigned integer, range is 0 through 4,294,967,295.
Definition: TTBase.h:278
The TTString class is used to represent a string.
Definition: TTString.h:34
String type.
Definition: TTBase.h:285
TT_OBJECT_CONSTRUCTOR
Constructor macro.
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174