Jamoma API  0.6.0.a19
TemperatureDataspace.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief Unit tests for the #TemperatureDataspace.
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 "TemperatureDataspace.h"
20 
21 
22 TTErr TemperatureDataspace::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("temperature"));
32 
33  TTValue v;
34  TTValue expected;
35 
36 
37  /************************************************/
38  /* */
39  /* Test conversions to neutral unit */
40  /* */
41  /************************************************/
42 
43 
44  // Kelvin => Kelvin
45 
46  myDataspace.set(TT("inputUnit"), TT("Kelvin"));
47  myDataspace.set(TT("outputUnit"), TT("Kelvin"));
48 
49  v = TTValue(256.);
50  expected = TTValue(256.);
51 
52  myDataspace.send(TT("convert"), v, v);
53 
54  TTTestAssertion("Kelvin to Kelvin",
55  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
56  testAssertionCount,
57  errorCount);
58 
59 
60 
61  // Celsius => Kelvin
62  // Expected value according to Google search: "0 Celsius to Kelvin"
63 
64  myDataspace.set(TT("inputUnit"), TT("Celsius"));
65  myDataspace.set(TT("outputUnit"), TT("Kelvin"));
66 
67  v = TTValue(0.);
68  expected = TTValue(273.15);
69 
70  myDataspace.send(TT("convert"), v, v);
71 
72  TTTestAssertion("Celsius to Kelvin",
73  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
74  testAssertionCount,
75  errorCount);
76 
77 
78  // Fahrenheit => Kelvin
79  // Expected value according to Google search: "32 Farhenheit to Kelvin"
80 
81  myDataspace.set(TT("inputUnit"), TT("Fahrenheit"));
82  myDataspace.set(TT("outputUnit"), TT("Kelvin"));
83 
84  v = TTValue(32.);
85  expected = TTValue(273.15);
86 
87  myDataspace.send(TT("convert"), v, v);
88 
89  TTTestAssertion("Fahrenheit to Kelvin",
90  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
91  testAssertionCount,
92  errorCount);
93 
94 
95 
96  /************************************************/
97  /* */
98  /* Test conversions from neutral unit */
99  /* */
100  /************************************************/
101 
102  // Kelvin => Celsius
103  // Expected value according to Google search: "0 Celsius to Kelvin"
104 
105  myDataspace.set(TT("inputUnit"), TT("Kelvin"));
106  myDataspace.set(TT("outputUnit"), TT("Celsius"));
107 
108  v = TTValue(273.15);
109  expected = TTValue(0.0);
110 
111  myDataspace.send(TT("convert"), v, v);
112 
113  TTTestAssertion("Kelvin to Celsius",
114  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
115  testAssertionCount,
116  errorCount);
117 
118 
119  // Fahrenheit => Kelvin
120  // Expected value according to Google search: "32 Farhenheit to Kelvin"
121 
122  myDataspace.set(TT("inputUnit"), TT("Kelvin"));
123  myDataspace.set(TT("outputUnit"), TT("Fahrenheit"));
124 
125  v = TTValue(273.15);
126  expected = TTValue(32.0);
127 
128  myDataspace.send(TT("convert"), v, v);
129 
130  TTTestAssertion("Kelvin to Fahrenheit",
131  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
132  testAssertionCount,
133  errorCount);
134 
135  }
136  catch (...) {
137  TTLogMessage("TemperatureDataspace::test TOTAL FAILURE");
138  errorCount = 1;
139  testAssertionCount = 1;
140  }
141 
142  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
143 }
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
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
The TemperatureDataspace converts between different measurement untis describing temperature.