Jamoma API  0.6.0.a19
SpeedDataspace.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief Unit tests for the #SpeedDataspace.
6  *
7  * @authors Trond Lossius, Tim Place, Nils Peters, ...
8  *
9  * @copyright Copyright © 2011 Trond Lossius @n
10  * This code is licensed under the terms of the "New BSD License" @n
11  * http://creativecommons.org/licenses/BSD/
12  */
13 
14 
15 // Dataspaces and Units employ C++ double-inheritance and are thus unsuitable for direct use
16 // through the usual TTObject API
17 #define TT_NO_DEPRECATION_WARNINGS
18 
19 #include "SpeedDataspace.h"
20 
21 
22 TTErr SpeedDataspace::test(TTValue& returnedTestInfo)
23 {
24  int errorCount = 0;
25  int testAssertionCount = 0;
26 
27  // Create dataspace object and set to temperature
28  try {
29 
30  TTObject myDataspace("dataspace");
31  myDataspace.set(TT("dataspace"), TT("speed"));
32 
33  TTValue v;
34  TTValue expected;
35 
36 
37  /************************************************/
38  /* */
39  /* Test conversions to neutral unit */
40  /* */
41  /************************************************/
42 
43 
44  // meterPerSecond => meterPerSecond
45 
46  myDataspace.set(TT("inputUnit"), TT("m/s"));
47  myDataspace.set(TT("outputUnit"), TT("m/s"));
48 
49  v = TTValue(256.);
50  expected = TTValue(256.);
51 
52  myDataspace.send(TT("convert"), v, v);
53 
54  TTTestAssertion("m/s to m/s",
55  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
56  testAssertionCount,
57  errorCount);
58 
59 
60 
61  // kilometerPerHour => meterPerSecond
62  // Trivial conversion: 36 km/h = (36000 m) / (60*60 s) = 10 m/s
63 
64  myDataspace.set(TT("inputUnit"), TT("kmph"));
65  myDataspace.set(TT("outputUnit"), TT("m/s"));
66 
67  v = TTValue(36.);
68  expected = TTValue(10.0);
69 
70  myDataspace.send(TT("convert"), v, v);
71 
72  TTTestAssertion("kmph to m/s",
73  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
74  testAssertionCount,
75  errorCount);
76 
77 
78  // milesPerHour => meterPerSecond
79  // Expected value according to Google search: "50 miles per hour to m/s"
80 
81  myDataspace.set(TT("inputUnit"), TT("mph"));
82  myDataspace.set(TT("outputUnit"), TT("m/s"));
83 
84  v = TTValue(50.);
85  expected = TTValue(22.35200);
86 
87  myDataspace.send(TT("convert"), v, v);
88 
89  TTTestAssertion("miles per hour to m/s",
90  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
91  testAssertionCount,
92  errorCount);
93 
94 
95  // knot => meterPerSecond
96  // Expected value according to Google search: "45 knot to m/s"
97  // This is a somewhat rough estimate, with limited precision
98 
99  myDataspace.set(TT("inputUnit"), TT("kn"));
100  myDataspace.set(TT("outputUnit"), TT("m/s"));
101 
102  v = TTValue(45.);
103  expected = TTValue(23.15);
104 
105  myDataspace.send(TT("convert"), v, v);
106 
107  TTTestAssertion("knot to m/s",
108  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.1),
109  testAssertionCount,
110  errorCount);
111 
112 
113  // footPerSecond => meterPerSecond
114  // Expected value according to Google search: "20 foot per second to m/s"
115 
116  myDataspace.set(TT("inputUnit"), TT("ft/s"));
117  myDataspace.set(TT("outputUnit"), TT("m/s"));
118 
119  v = TTValue(20.);
120  expected = TTValue(6.09600);
121 
122  myDataspace.send(TT("convert"), v, v);
123 
124  TTTestAssertion("foot per hour to m/s",
125  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
126  testAssertionCount,
127  errorCount);
128 
129 
130 
131  /************************************************/
132  /* */
133  /* Test conversions from neutral unit */
134  /* */
135  /************************************************/
136 
137  // meterPerSecond =>kilometerPerHour
138 
139  myDataspace.set(TT("inputUnit"), TT("m/s"));
140  myDataspace.set(TT("outputUnit"), TT("kmph"));
141 
142  v = TTValue(10.);
143  expected = TTValue(36.0);
144 
145  myDataspace.send(TT("convert"), v, v);
146 
147  TTTestAssertion("m/s to kmph",
148  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
149  testAssertionCount,
150  errorCount);
151 
152 
153  // milesPerHour => meterPerSecond
154  // Expected value according to Google search: "50 miles per hour to m/s"
155 
156  myDataspace.set(TT("inputUnit"), TT("m/s"));
157  myDataspace.set(TT("outputUnit"), TT("mph"));
158 
159  v = TTValue(22.35200);
160  expected = TTValue(50.);
161 
162  myDataspace.send(TT("convert"), v, v);
163 
164  TTTestAssertion("m/s to miles per hour",
165  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.00001),
166  testAssertionCount,
167  errorCount);
168 
169 
170  // knot => meterPerSecond
171  // Expected value according to Google search: "45 knot to m/s"
172  // This is a somewhat rough estimate, with limited precision
173 
174  myDataspace.set(TT("inputUnit"), TT("m/s"));
175  myDataspace.set(TT("outputUnit"), TT("kn"));
176 
177  v = TTValue(23.15);
178  expected = TTValue(45.);
179 
180  myDataspace.send(TT("convert"), v, v);
181 
182  TTTestAssertion("m/s to knot",
183  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.1),
184  testAssertionCount,
185  errorCount);
186 
187 
188  // footPerSecond => meterPerSecond
189  // Expected value according to Google search: "20 foot per second to m/s"
190 
191  myDataspace.set(TT("inputUnit"), TT("m/s"));
192  myDataspace.set(TT("outputUnit"), TT("ft/s"));
193 
194  v = TTValue(6.09600);
195  expected = TTValue(20.);
196 
197  myDataspace.send(TT("convert"), v, v);
198 
199  TTTestAssertion("m/s to foot per hour",
200  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.00001),
201  testAssertionCount,
202  errorCount);
203 
204  }
205  catch (...) {
206  TTLogMessage("SpeedDataspace::test TOTAL FAILURE");
207  errorCount = 1;
208  testAssertionCount = 1;
209  }
210 
211  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
212 }
Create and use Jamoma object instances.
Definition: TTObject.h:29
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
The SpeedDataspace converts between different measurement untis describing velocity.
void set(const TTUInt16 index, const T &anElementValue)
DEPRECATED.
Definition: TTValue.h:569
void TTFOUNDATION_EXPORT TTLogMessage(TTImmutableCString message,...)
Platform and host independent method for posting log messages.
Definition: TTBase.cpp:534
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34