1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * See the file "license.terms" for information on usage and |
---|
6 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
7 | * ====================================================================== |
---|
8 | */ |
---|
9 | #include "RpUnits.h" |
---|
10 | #include <list> |
---|
11 | #include <string> |
---|
12 | #include <cassert> |
---|
13 | |
---|
14 | |
---|
15 | void success() |
---|
16 | { |
---|
17 | printf ("Test Successful\n"); |
---|
18 | } |
---|
19 | |
---|
20 | void fail() |
---|
21 | { |
---|
22 | printf ("Test FAILED !!!!!!!!!!!!!!!!!\n"); |
---|
23 | exit(-1); |
---|
24 | } |
---|
25 | |
---|
26 | // compare_numbers() |
---|
27 | |
---|
28 | int main() |
---|
29 | { |
---|
30 | double value = 0.0; |
---|
31 | std::string strValue; |
---|
32 | int result = 0; |
---|
33 | |
---|
34 | // |
---|
35 | // use main to test class functionality |
---|
36 | // |
---|
37 | |
---|
38 | // test define(units,basis) |
---|
39 | // this should create an object of type RpUnits |
---|
40 | // with the units of "m" and basis should be NULL |
---|
41 | // which tells us that this object represents a fundamental system |
---|
42 | // of units |
---|
43 | // |
---|
44 | printf ("=============== TEST 1 ===============\n"); |
---|
45 | |
---|
46 | const RpUnits* meters = RpUnits::find("m"); |
---|
47 | const RpUnits* cmeters = RpUnits::find("cm"); |
---|
48 | const RpUnits* angstrom = RpUnits::find("A"); |
---|
49 | |
---|
50 | value = angstrom->convert(meters,1.0,&result); |
---|
51 | std::cout << "1 angstrom = " << value << " meters" << std::endl; |
---|
52 | std::cout << "result = " << result << std::endl; |
---|
53 | |
---|
54 | result = 0; |
---|
55 | value = cmeters->convert(angstrom,1e-8,&result); |
---|
56 | std::cout << "1.0e-8 centimeter = " << value << " angstroms" << std::endl; |
---|
57 | |
---|
58 | |
---|
59 | const RpUnits* fahrenheit = RpUnits::find("F"); |
---|
60 | const RpUnits* celcius = RpUnits::find("C"); |
---|
61 | const RpUnits* kelvin = RpUnits::find("K"); |
---|
62 | |
---|
63 | value = fahrenheit->convert(celcius,72,&result); |
---|
64 | std::cout << "72 degrees fahrenheit = " << value << " degrees celcius" << std::endl; |
---|
65 | |
---|
66 | value = celcius->convert(fahrenheit,value,&result); |
---|
67 | std::cout << "22.222 degrees celcius = " << value << " degrees fahrenheit" << std::endl; |
---|
68 | |
---|
69 | value = celcius->convert(kelvin,20,&result); |
---|
70 | std::cout << "20 degrees celcius = " << value << " kelvin" << std::endl; |
---|
71 | |
---|
72 | value = kelvin->convert(celcius,300,&result); |
---|
73 | std::cout << "300 kelvin = " << value << " degrees celcius" << std::endl; |
---|
74 | |
---|
75 | /* |
---|
76 | // test getUnits() member function of objects of type RpUnits |
---|
77 | // this test should return the units of "m" for the oject |
---|
78 | // meters |
---|
79 | // |
---|
80 | printf ("=============== TEST 2 ===============\n"); |
---|
81 | (meters->getUnits().c_str()) ? success() : fail(); |
---|
82 | printf("meters units = :%s:\n", meters->getUnits().c_str()); |
---|
83 | |
---|
84 | // test getBasis() functionality of objects of type RpUnits |
---|
85 | // create an object of type RpUnits and associate it with the |
---|
86 | // meters RpUnits object as its basis. |
---|
87 | // print out what it reports its basis is. |
---|
88 | // |
---|
89 | printf ("=============== TEST 3 ===============\n"); |
---|
90 | std::string t3units = "cm"; |
---|
91 | // RpUnits * centimeters = RpUnits::define("cm", meters); |
---|
92 | RpUnits * centimeters = RpUnits::define(t3units, meters); |
---|
93 | (centimeters) ? success() : fail(); |
---|
94 | printf("cm units = :%s:\n", centimeters->getUnits().c_str() ); |
---|
95 | printf("cm basis = :%s:\n", centimeters->getBasis()->getUnits().c_str() ); |
---|
96 | |
---|
97 | // test makeBasis() |
---|
98 | // |
---|
99 | printf ("=============== TEST 4.1 ===============\n"); |
---|
100 | // value = centimeters->makeBasis(100.00); |
---|
101 | value = 100.00; |
---|
102 | failTest = centimeters->makeBasis(&value); |
---|
103 | (value == 1 && !failTest) ? success() : fail(); |
---|
104 | printf("100 cm = :%f: meters\n", value); |
---|
105 | |
---|
106 | // test makeBasis() with a list of values, all the same units |
---|
107 | // |
---|
108 | printf ("=============== TEST 4.2 ===============\n"); |
---|
109 | // |
---|
110 | // double * valueArr = (double *) calloc(12,sizeof(double)); |
---|
111 | // if (!valueArr) { |
---|
112 | // // complain that malloc failed |
---|
113 | // exit(-2); |
---|
114 | // } |
---|
115 | // |
---|
116 | // valueArr = centimeters->makeBasis(100.00); |
---|
117 | // |
---|
118 | // (value == 1) ? success() : fail(); |
---|
119 | // printf("100 cm = :%f: meters\n", value); |
---|
120 | |
---|
121 | // test makeBasis() with a list of values, all different units |
---|
122 | // |
---|
123 | printf ("=============== TEST 4.3 ===============\n"); |
---|
124 | // value = centimeters->makeBasis(100.00); |
---|
125 | // (value == 1) ? success() : fail(); |
---|
126 | // printf("100 cm = :%f: meters\n", value); |
---|
127 | |
---|
128 | */ |
---|
129 | |
---|
130 | printf ("=============== TEST 4.4 ===============\n"); |
---|
131 | |
---|
132 | const RpUnits * millimeter = RpUnits::find("mm"); |
---|
133 | const RpUnits * micrometer = RpUnits::find("um"); |
---|
134 | const RpUnits * nanometer = RpUnits::find("nm"); |
---|
135 | const RpUnits * picometer = RpUnits::find("pm"); |
---|
136 | const RpUnits * femtometer = RpUnits::find("fm"); |
---|
137 | const RpUnits * attometer = RpUnits::find("am"); |
---|
138 | const RpUnits * kilometer = RpUnits::find("km"); |
---|
139 | const RpUnits * megameter = RpUnits::find("Mm"); |
---|
140 | const RpUnits * gigameter = RpUnits::find("Gm"); |
---|
141 | const RpUnits * terameter = RpUnits::find("Tm"); |
---|
142 | const RpUnits * petameter = RpUnits::find("Pm"); |
---|
143 | |
---|
144 | value = 1.0e+3; |
---|
145 | millimeter->makeBasis(&value); |
---|
146 | (value == 1) ? success() : fail(); |
---|
147 | printf("1.0e3 mm = :%f: meters\n", value); |
---|
148 | |
---|
149 | value = 1.0e+6; |
---|
150 | micrometer->makeBasis(&value); |
---|
151 | (value == 1) ? success() : fail(); |
---|
152 | printf("1.0e6 um = :%f: meters\n", value); |
---|
153 | |
---|
154 | value = 1.0e+9; |
---|
155 | nanometer->makeBasis(&value); |
---|
156 | (value == 1) ? success() : fail(); |
---|
157 | printf("1.0e9 nm = :%f: meters\n", value); |
---|
158 | |
---|
159 | value = 1.0e+12; |
---|
160 | picometer->makeBasis(&value); |
---|
161 | (value == 1) ? success() : fail(); |
---|
162 | printf("1.0e12 pm = :%f: meters\n", value); |
---|
163 | |
---|
164 | value = 1.0e+15; |
---|
165 | femtometer->makeBasis(&value); |
---|
166 | (value == 1) ? success() : fail(); |
---|
167 | printf("1.0e15 fm = :%f: meters\n", value); |
---|
168 | |
---|
169 | value = 1.0e+18; |
---|
170 | attometer->makeBasis(&value); |
---|
171 | (value == 1) ? success() : fail(); |
---|
172 | printf("1.0e18 am = :%f: meters\n", value); |
---|
173 | |
---|
174 | value = 1.0e-3; |
---|
175 | kilometer->makeBasis(&value); |
---|
176 | (value == 1) ? success() : fail(); |
---|
177 | printf("1.0e-3 km = :%f: meters\n", value); |
---|
178 | |
---|
179 | value = 1.0e-6; |
---|
180 | megameter->makeBasis(&value); |
---|
181 | (value == 1) ? success() : fail(); |
---|
182 | printf("1.0e-6 Mm = :%f: meters\n", value); |
---|
183 | |
---|
184 | value = 1.0e-9; |
---|
185 | gigameter->makeBasis(&value); |
---|
186 | (value == 1) ? success() : fail(); |
---|
187 | printf("1.0e-9 Gm = :%f: meters\n", value); |
---|
188 | |
---|
189 | value = 1.0e-12; |
---|
190 | terameter->makeBasis(&value); |
---|
191 | (value == 1) ? success() : fail(); |
---|
192 | printf("1.0e-12 Gm = :%f: meters\n", value); |
---|
193 | |
---|
194 | value = 1.0e-15; |
---|
195 | petameter->makeBasis(&value); |
---|
196 | (value == 1) ? success() : fail(); |
---|
197 | printf("1.0e-15 Pm = :%f: meters\n", value); |
---|
198 | |
---|
199 | value = 2; |
---|
200 | meters->makeBasis(&value); |
---|
201 | (value == 2) ? success() : fail(); |
---|
202 | printf("2 m = :%f: meters\n", value); |
---|
203 | |
---|
204 | printf ("=============== TEST 5 ===============\n"); |
---|
205 | |
---|
206 | strValue = RpUnits::convert("72F","C",1); |
---|
207 | std::cout << "result = " << result << std::endl; |
---|
208 | std::cout << "strValue convert(72F,C,1) = " << strValue << std::endl; |
---|
209 | |
---|
210 | strValue = RpUnits::convert("72F","C",0); |
---|
211 | std::cout << "result = " << result << std::endl; |
---|
212 | std::cout << "strValue convert(72F,C,0) = " << strValue << std::endl; |
---|
213 | |
---|
214 | strValue = RpUnits::convert("20C","K",1); |
---|
215 | std::cout << "result = " << result << std::endl; |
---|
216 | std::cout << "strValue convert(20C,K,1) = " << strValue << std::endl; |
---|
217 | |
---|
218 | strValue = RpUnits::convert("20C","K",0); |
---|
219 | std::cout << "result = " << result << std::endl; |
---|
220 | std::cout << "strValue convert(20C,K,1) = " << strValue << std::endl; |
---|
221 | |
---|
222 | strValue = RpUnits::convert("300K","C",1); |
---|
223 | std::cout << "result = " << result << std::endl; |
---|
224 | std::cout << "strValue convert(300K,C,1) = " << strValue << std::endl; |
---|
225 | |
---|
226 | strValue = RpUnits::convert("300K","C",0); |
---|
227 | std::cout << "result = " << result << std::endl; |
---|
228 | std::cout << "strValue convert(300K,C,0) = " << strValue << std::endl; |
---|
229 | |
---|
230 | |
---|
231 | |
---|
232 | |
---|
233 | const RpUnits* eV = RpUnits::find("eV"); |
---|
234 | const RpUnits* joules = RpUnits::find("J"); |
---|
235 | |
---|
236 | value = joules->convert(eV,1,&result); |
---|
237 | std::cout << "1 joule = " << value << " electronVolts" << std::endl; |
---|
238 | |
---|
239 | value = eV->convert(joules,1,&result); |
---|
240 | std::cout << "1 electronVolt = " << value << " joules" << std::endl; |
---|
241 | |
---|
242 | strValue = RpUnits::convert("10eV","J",1); |
---|
243 | std::cout << "strValue convert(10eV,J,1) = " << strValue << std::endl; |
---|
244 | |
---|
245 | strValue = RpUnits::convert("1eV","J",0); |
---|
246 | std::cout << "strValue convert(1eV,J,0) = " << strValue << std::endl; |
---|
247 | |
---|
248 | strValue = RpUnits::convert("10J","eV",1); |
---|
249 | std::cout << "strValue convert(10J,eV,1) = " << strValue << std::endl; |
---|
250 | |
---|
251 | strValue = RpUnits::convert("1J","eV",0); |
---|
252 | std::cout << "strValue convert(1J,eV,0) = " << strValue << std::endl; |
---|
253 | |
---|
254 | |
---|
255 | |
---|
256 | |
---|
257 | |
---|
258 | |
---|
259 | std::cout << "TESTING COPY CONSTRUCTOR" << std::endl; |
---|
260 | |
---|
261 | RpUnits *origRpUnits = RpUnits::define("obj2", NULL, ""); |
---|
262 | RpUnits copyRpUnits = *origRpUnits; |
---|
263 | |
---|
264 | std::cout << "origRpUnits = " << origRpUnits->getUnitsName() << std::endl; |
---|
265 | std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; |
---|
266 | std::cout << "modifying origRpUnits" << std::endl; |
---|
267 | delete origRpUnits; |
---|
268 | origRpUnits = RpUnits::define("obj3",NULL, ""); |
---|
269 | std::cout << "origRpUnits = " << origRpUnits->getUnitsName() << std::endl; |
---|
270 | std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; |
---|
271 | std::cout << "deleting origRpUnits" << std::endl; |
---|
272 | delete origRpUnits; |
---|
273 | std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; |
---|
274 | |
---|
275 | std::cout << "TESTING COPY ASSIGNMENT OPERATOR" << std::endl; |
---|
276 | |
---|
277 | RpUnits *testRpUnits = RpUnits::define("test2", NULL, ""); |
---|
278 | copyRpUnits = *testRpUnits; |
---|
279 | |
---|
280 | std::cout << "testRpUnits = " << testRpUnits->getUnitsName() << std::endl; |
---|
281 | std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; |
---|
282 | std::cout << "modifying testRpUnits" << std::endl; |
---|
283 | delete testRpUnits; |
---|
284 | testRpUnits = RpUnits::define("test3",NULL, ""); |
---|
285 | std::cout << "testRpUnits = " << testRpUnits->getUnitsName() << std::endl; |
---|
286 | std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; |
---|
287 | std::cout << "deleting testRpUnits" << std::endl; |
---|
288 | delete testRpUnits; |
---|
289 | std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; |
---|
290 | |
---|
291 | |
---|
292 | // test deleting a const object |
---|
293 | |
---|
294 | const RpUnits* myobj = RpUnits::define("myunit",NULL, ""); |
---|
295 | delete myobj; |
---|
296 | |
---|
297 | // test /cm2 |
---|
298 | // std::cout << "convert (3m3 -> cm3) = " << RpUnits::convert("3m3","cm3",0) << std::endl; |
---|
299 | // std::cout << "convert (3/m3 -> /cm3) = " << RpUnits::convert("3/m3","/cm3",0) << std::endl; |
---|
300 | // std::cout << "convert (300cm3 -> m3) = " << RpUnits::convert("300cm3","m3",0) << std::endl; |
---|
301 | // std::cout << "convert (300/cm3 -> /m3) = " << RpUnits::convert("300/cm3","/m3",0) << std::endl; |
---|
302 | |
---|
303 | std::cout << "convert (3m3 -> cm3) = " << RpUnits::convert("3m3","cm3",0) << std::endl; |
---|
304 | std::cout << "convert (3/m3 -> /cm3) = " << RpUnits::convert("3/m3","/cm3",0) << std::endl; |
---|
305 | std::cout << "convert (300cm3 -> m3) = " << RpUnits::convert("300cm3","m3",0) << std::endl; |
---|
306 | std::cout << "convert (300/cm3 -> /m3) = " << RpUnits::convert("300/cm3","/m3",0) << std::endl; |
---|
307 | std::cout << "convert (72F -> 22.22C) = " << RpUnits::convert("72F","C",0) << std::endl; |
---|
308 | std::cout << "convert (5J -> 3.12075e+28neV) = " << RpUnits::convert("5J","neV",0) << std::endl; |
---|
309 | std::cout << "convert (5J2 -> 1.9478e+56neV2) = " << RpUnits::convert("5J2","neV2",0) << std::endl; |
---|
310 | |
---|
311 | // testing complex units |
---|
312 | std::cout << "convert (1cm2/Vs -> 0.0001m2/Vs) = " << RpUnits::convert("1cm2/Vs","m2/Vs",0) << std::endl; |
---|
313 | std::cout << "convert (1cm2/Vs -> 0.1m2/kVs) = " << RpUnits::convert("1cm2/Vs","m2/kVs",0) << std::endl; |
---|
314 | std::cout << "convert (1cm2/Vs -> 1e-7m2/kVus) = " << RpUnits::convert("1cm2/Vs","m2/kVus",0) << std::endl; |
---|
315 | |
---|
316 | const RpUnits* myMeters = RpUnits::find("cm"); |
---|
317 | std::list<std::string> convList = myMeters->getCompatible(); |
---|
318 | std::list<std::string>::iterator convListIter; |
---|
319 | |
---|
320 | std::cout << myMeters->getUnitsName() << " is of type: " << myMeters->getType() << std::endl; |
---|
321 | std::cout << myMeters->getUnitsName() << " is compatible with: " << std::endl; |
---|
322 | convListIter = convList.begin(); |
---|
323 | while (convListIter != convList.end()) { |
---|
324 | std::cout << *convListIter << std::endl; |
---|
325 | convListIter++; |
---|
326 | } |
---|
327 | |
---|
328 | std::cout << "convert(\"5.00mm\",\"\",1) = " << RpUnits::convert("5.00mm","",1) << std::endl; |
---|
329 | std::cout << "convert(\"5.00mm\",\"\",0) = " << RpUnits::convert("5.00mm","",0) << std::endl; |
---|
330 | |
---|
331 | // day hour min sec test |
---|
332 | assert((RpUnits::convert("5.00s","s",RpUnits::UNITS_ON)) == "5s"); |
---|
333 | std::cout << "convert(\"5.00s\",\"s\",UNITS_ON) passed" << std::endl; |
---|
334 | assert((RpUnits::convert("5.00s","s",RpUnits::UNITS_OFF)) == "5"); |
---|
335 | std::cout << "convert(\"5.00s\",\"s\",UNITS_OFF) passed" << std::endl; |
---|
336 | assert((RpUnits::convert("5.00min","s",RpUnits::UNITS_ON)) == "300s"); |
---|
337 | std::cout << "convert(\"5.00min\",\"s\",UNITS_ON) passed" << std::endl; |
---|
338 | assert((RpUnits::convert("5.00min","s",RpUnits::UNITS_OFF)) == "300"); |
---|
339 | std::cout << "convert(\"5.00min\",\"s\",UNITS_OFF) passed" << std::endl; |
---|
340 | assert((RpUnits::convert("5.00h","s",RpUnits::UNITS_ON)) == "18000s"); |
---|
341 | std::cout << "convert(\"5.00h\",\"s\",UNITS_ON) passed" << std::endl; |
---|
342 | assert((RpUnits::convert("5.00h","s",RpUnits::UNITS_OFF)) == "18000"); |
---|
343 | std::cout << "convert(\"5.00h\",\"s\",UNITS_OFF) passed" << std::endl; |
---|
344 | assert((RpUnits::convert("5.00d","s",RpUnits::UNITS_ON)) == "432000s"); |
---|
345 | std::cout << "convert(\"5.00d\",\"s\",UNITS_ON) passed" << std::endl; |
---|
346 | assert((RpUnits::convert("5.00d","s",RpUnits::UNITS_OFF)) == "432000"); |
---|
347 | std::cout << "convert(\"5.00d\",\"s\",UNITS_OFF) passed" << std::endl; |
---|
348 | |
---|
349 | assert((RpUnits::convert("5.00s","min",RpUnits::UNITS_ON)) == "0.0833333min"); |
---|
350 | std::cout << "convert(\"5.00s\",\"min\",UNITS_ON) passed" << std::endl; |
---|
351 | assert((RpUnits::convert("5.00s","min",RpUnits::UNITS_OFF)) == "0.0833333"); |
---|
352 | std::cout << "convert(\"5.00s\",\"min\",UNITS_OFF) passed" << std::endl; |
---|
353 | assert((RpUnits::convert("5.00min","min",RpUnits::UNITS_ON)) == "5min"); |
---|
354 | std::cout << "convert(\"5.00min\",\"min\",UNITS_ON) passed" << std::endl; |
---|
355 | assert((RpUnits::convert("5.00min","min",RpUnits::UNITS_OFF)) == "5"); |
---|
356 | std::cout << "convert(\"5.00min\",\"min\",UNITS_OFF) passed" << std::endl; |
---|
357 | assert((RpUnits::convert("5.00h","min",RpUnits::UNITS_ON)) == "300min"); |
---|
358 | std::cout << "convert(\"5.00h\",\"min\",UNITS_ON) passed" << std::endl; |
---|
359 | assert((RpUnits::convert("5.00h","min",RpUnits::UNITS_OFF)) == "300"); |
---|
360 | std::cout << "convert(\"5.00h\",\"min\",UNITS_OFF) passed" << std::endl; |
---|
361 | assert((RpUnits::convert("5.00d","min",RpUnits::UNITS_ON)) == "7200min"); |
---|
362 | std::cout << "convert(\"5.00d\",\"min\",UNITS_ON) passed" << std::endl; |
---|
363 | assert((RpUnits::convert("5.00d","min",RpUnits::UNITS_OFF)) == "7200"); |
---|
364 | std::cout << "convert(\"5.00d\",\"min\",UNITS_OFF) passed" << std::endl; |
---|
365 | |
---|
366 | assert((RpUnits::convert("5.00s","h",RpUnits::UNITS_ON)) == "0.00138889h"); |
---|
367 | std::cout << "convert(\"5.00s\",\"h\",UNITS_ON) passed" << std::endl; |
---|
368 | assert((RpUnits::convert("5.00s","h",RpUnits::UNITS_OFF)) == "0.00138889"); |
---|
369 | std::cout << "convert(\"5.00s\",\"h\",UNITS_OFF) passed" << std::endl; |
---|
370 | assert((RpUnits::convert("5.00min","h",RpUnits::UNITS_ON)) == "0.0833333h"); |
---|
371 | std::cout << "convert(\"5.00min\",\"h\",UNITS_ON) passed" << std::endl; |
---|
372 | assert((RpUnits::convert("5.00min","h",RpUnits::UNITS_OFF)) == "0.0833333"); |
---|
373 | std::cout << "convert(\"5.00min\",\"h\",UNITS_OFF) passed" << std::endl; |
---|
374 | assert((RpUnits::convert("5.00h","h",RpUnits::UNITS_ON)) == "5h"); |
---|
375 | std::cout << "convert(\"5.00h\",\"h\",UNITS_ON) passed" << std::endl; |
---|
376 | assert((RpUnits::convert("5.00h","h",RpUnits::UNITS_OFF)) == "5"); |
---|
377 | std::cout << "convert(\"5.00h\",\"h\",UNITS_OFF) passed" << std::endl; |
---|
378 | assert((RpUnits::convert("5.00d","h",RpUnits::UNITS_ON)) == "120h"); |
---|
379 | std::cout << "convert(\"5.00d\",\"h\",UNITS_ON) passed" << std::endl; |
---|
380 | assert((RpUnits::convert("5.00d","h",RpUnits::UNITS_OFF)) == "120"); |
---|
381 | std::cout << "convert(\"5.00d\",\"h\",UNITS_OFF) passed" << std::endl; |
---|
382 | |
---|
383 | assert((RpUnits::convert("5.00s","d",RpUnits::UNITS_ON)) == "5.78704e-05d"); |
---|
384 | std::cout << "convert(\"5.00s\",\"d\",UNITS_ON) passed" << std::endl; |
---|
385 | assert((RpUnits::convert("5.00s","d",RpUnits::UNITS_OFF)) == "5.78704e-05"); |
---|
386 | std::cout << "convert(\"5.00s\",\"d\",UNITS_OFF) passed" << std::endl; |
---|
387 | assert((RpUnits::convert("5.00min","d",RpUnits::UNITS_ON)) == "0.00347222d"); |
---|
388 | std::cout << "convert(\"5.00min\",\"d\",UNITS_ON) passed" << std::endl; |
---|
389 | assert((RpUnits::convert("5.00min","d",RpUnits::UNITS_OFF)) == "0.00347222"); |
---|
390 | std::cout << "convert(\"5.00min\",\"d\",UNITS_OFF) passed" << std::endl; |
---|
391 | assert((RpUnits::convert("5.00h","d",RpUnits::UNITS_ON)) == "0.208333d"); |
---|
392 | std::cout << "convert(\"5.00h\",\"d\",UNITS_ON) passed" << std::endl; |
---|
393 | assert((RpUnits::convert("5.00h","d",RpUnits::UNITS_OFF)) == "0.208333"); |
---|
394 | std::cout << "convert(\"5.00h\",\"d\",UNITS_OFF) passed" << std::endl; |
---|
395 | assert((RpUnits::convert("5.00d","d",RpUnits::UNITS_ON)) == "5d"); |
---|
396 | std::cout << "convert(\"5.00d\",\"d\",UNITS_ON) passed" << std::endl; |
---|
397 | assert((RpUnits::convert("5.00d","d",RpUnits::UNITS_OFF)) == "5"); |
---|
398 | std::cout << "convert(\"5.00d\",\"d\",UNITS_OFF) passed" << std::endl; |
---|
399 | |
---|
400 | |
---|
401 | |
---|
402 | assert((RpUnits::convert("5.00bar","Pa",RpUnits::UNITS_OFF)) == "500000"); |
---|
403 | std::cout << "convert(\"5.00bar\",\"Pa\",UNITS_OFF) passed" << std::endl; |
---|
404 | assert((RpUnits::convert("5.00bar","Pa",RpUnits::UNITS_ON)) == "500000Pa"); |
---|
405 | std::cout << "convert(\"5.00bar\",\"Pa\",UNITS_ON) passed" << std::endl; |
---|
406 | assert((RpUnits::convert("5.00bar","atm",RpUnits::UNITS_OFF)) == "4.9346"); |
---|
407 | std::cout << "convert(\"5.00bar\",\"atm\",UNITS_OFF) passed" << std::endl; |
---|
408 | assert((RpUnits::convert("5.00bar","atm",RpUnits::UNITS_ON)) == "4.9346atm"); |
---|
409 | std::cout << "convert(\"5.00bar\",\"atm\",UNITS_ON) passed" << std::endl; |
---|
410 | assert((RpUnits::convert("5.00bar","torr",RpUnits::UNITS_OFF)) == "3750.3"); |
---|
411 | std::cout << "convert(\"5.00bar\",\"torr\",UNITS_OFF) passed" << std::endl; |
---|
412 | assert((RpUnits::convert("5.00bar","torr",RpUnits::UNITS_ON)) == "3750.3torr"); |
---|
413 | std::cout << "convert(\"5.00bar\",\"torr\",UNITS_ON) passed" << std::endl; |
---|
414 | assert((RpUnits::convert("5.00bar","psi",RpUnits::UNITS_OFF)) == "72.52"); |
---|
415 | std::cout << "convert(\"5.00bar\",\"psi\",UNITS_OFF) passed" << std::endl; |
---|
416 | assert((RpUnits::convert("5.00bar","psi",RpUnits::UNITS_ON)) == "72.52psi"); |
---|
417 | std::cout << "convert(\"5.00bar\",\"psi\",UNITS_ON) passed" << std::endl; |
---|
418 | |
---|
419 | |
---|
420 | |
---|
421 | |
---|
422 | assert((RpUnits::convert("5.00atm","bar",RpUnits::UNITS_OFF)) == "5.06627"); |
---|
423 | std::cout << "convert(\"5.00atm\",\"bar\",UNITS_OFF) passed" << std::endl; |
---|
424 | assert((RpUnits::convert("5.00atm","bar",RpUnits::UNITS_ON)) == "5.06627bar"); |
---|
425 | std::cout << "convert(\"5.00atm\",\"bar\",UNITS_ON) passed" << std::endl; |
---|
426 | /* |
---|
427 | assert((RpUnits::convert("5.00atm","Pa",RpUnits::UNITS_OFF)) == "506625.12"); |
---|
428 | std::cout << "convert(\"5.00atm\",\"Pa\",UNITS_OFF) passed" << std::endl; |
---|
429 | assert((RpUnits::convert("5.00atm","Pa",RpUnits::UNITS_ON)) == "506625.12Pa"); |
---|
430 | std::cout << "convert(\"5.00atm\",\"Pa\",UNITS_ON) passed" << std::endl; |
---|
431 | */ |
---|
432 | assert((RpUnits::convert("5.00atm","torr",RpUnits::UNITS_OFF)) == "3800"); |
---|
433 | std::cout << "convert(\"5.00atm\",\"torr\",UNITS_OFF) passed" << std::endl; |
---|
434 | assert((RpUnits::convert("5.00atm","torr",RpUnits::UNITS_ON)) == "3800torr"); |
---|
435 | std::cout << "convert(\"5.00atm\",\"torr\",UNITS_ON) passed" << std::endl; |
---|
436 | |
---|
437 | |
---|
438 | |
---|
439 | |
---|
440 | assert((RpUnits::convert("5.00Pa","bar",RpUnits::UNITS_OFF)) == "5e-05"); |
---|
441 | std::cout << "convert(\"5.00Pa\",\"bar\",UNITS_OFF) passed" << std::endl; |
---|
442 | assert((RpUnits::convert("5.00Pa","bar",RpUnits::UNITS_ON)) == "5e-05bar"); |
---|
443 | std::cout << "convert(\"5.00Pa\",\"bar\",UNITS_ON) passed" << std::endl; |
---|
444 | assert((RpUnits::convert("5.00Pa","atm",RpUnits::UNITS_OFF)) == "4.9346e-05"); |
---|
445 | std::cout << "convert(\"5.00Pa\",\"atm\",UNITS_OFF) passed" << std::endl; |
---|
446 | assert((RpUnits::convert("5.00Pa","atm",RpUnits::UNITS_ON)) == "4.9346e-05atm"); |
---|
447 | std::cout << "convert(\"5.00Pa\",\"atm\",UNITS_ON) passed" << std::endl; |
---|
448 | assert((RpUnits::convert("5.00Pa","torr",RpUnits::UNITS_OFF)) == "0.037503"); |
---|
449 | std::cout << "convert(\"5.00Pa\",\"torr\",UNITS_OFF) passed" << std::endl; |
---|
450 | assert((RpUnits::convert("5.00Pa","torr",RpUnits::UNITS_ON)) == "0.037503torr"); |
---|
451 | std::cout << "convert(\"5.00Pa\",\"torr\",UNITS_ON) passed" << std::endl; |
---|
452 | assert((RpUnits::convert("5.00Pa","psi",RpUnits::UNITS_OFF)) == "0.0007252"); |
---|
453 | std::cout << "convert(\"5.00Pa\",\"psi\",UNITS_OFF) passed" << std::endl; |
---|
454 | assert((RpUnits::convert("5.00Pa","psi",RpUnits::UNITS_ON)) == "0.0007252psi"); |
---|
455 | std::cout << "convert(\"5.00Pa\",\"psi\",UNITS_ON) passed" << std::endl; |
---|
456 | |
---|
457 | |
---|
458 | |
---|
459 | |
---|
460 | assert((RpUnits::convert("5.00torr","bar",RpUnits::UNITS_OFF)) == "0.00666613"); |
---|
461 | std::cout << "convert(\"5.00torr\",\"bar\",UNITS_OFF) passed" << std::endl; |
---|
462 | assert((RpUnits::convert("5.00torr","bar",RpUnits::UNITS_ON)) == "0.00666613bar"); |
---|
463 | std::cout << "convert(\"5.00torr\",\"bar\",UNITS_ON) passed" << std::endl; |
---|
464 | assert((RpUnits::convert("5.00torr","Pa",RpUnits::UNITS_OFF)) == "666.613"); |
---|
465 | std::cout << "convert(\"5.00torr\",\"Pa\",UNITS_OFF) passed" << std::endl; |
---|
466 | assert((RpUnits::convert("5.00torr","Pa",RpUnits::UNITS_ON)) == "666.613Pa"); |
---|
467 | std::cout << "convert(\"5.00torr\",\"Pa\",UNITS_ON) passed" << std::endl; |
---|
468 | assert((RpUnits::convert("5.00torr","atm",RpUnits::UNITS_OFF)) == "0.006579"); |
---|
469 | std::cout << "convert(\"5.00torr\",\"atm\",UNITS_OFF) passed" << std::endl; |
---|
470 | assert((RpUnits::convert("5.00torr","atm",RpUnits::UNITS_ON)) == "0.006579atm"); |
---|
471 | std::cout << "convert(\"5.00torr\",\"atm\",UNITS_ON) passed" << std::endl; |
---|
472 | assert((RpUnits::convert("5.00torr","psi",RpUnits::UNITS_OFF)) == "0.096685"); |
---|
473 | std::cout << "convert(\"5.00torr\",\"psi\",UNITS_OFF) passed" << std::endl; |
---|
474 | assert((RpUnits::convert("5.00torr","psi",RpUnits::UNITS_ON)) == "0.096685psi"); |
---|
475 | std::cout << "convert(\"5.00torr\",\"psi\",UNITS_ON) passed" << std::endl; |
---|
476 | |
---|
477 | |
---|
478 | assert((RpUnits::convert("5.00psi","bar",RpUnits::UNITS_OFF)) == "0.344738"); |
---|
479 | std::cout << "convert(\"5.00psi\",\"bar\",UNITS_OFF) passed" << std::endl; |
---|
480 | assert((RpUnits::convert("5.00psi","bar",RpUnits::UNITS_ON)) == "0.344738bar"); |
---|
481 | std::cout << "convert(\"5.00psi\",\"bar\",UNITS_ON) passed" << std::endl; |
---|
482 | /* |
---|
483 | assert((RpUnits::convert("5.00psi","Pa",RpUnits::UNITS_OFF)) == "34473.8129155"); |
---|
484 | std::cout << "convert(\"5.00psi\",\"Pa\",UNITS_OFF) passed" << std::endl; |
---|
485 | assert((RpUnits::convert("5.00psi","Pa",RpUnits::UNITS_ON)) == "34473.8129155Pa"); |
---|
486 | std::cout << "convert(\"5.00psi\",\"Pa\",UNITS_ON) passed" << std::endl; |
---|
487 | */ |
---|
488 | assert((RpUnits::convert("5.00psi","torr",RpUnits::UNITS_OFF)) == "258.575"); |
---|
489 | std::cout << "convert(\"5.00psi\",\"torr\",UNITS_OFF) passed" << std::endl; |
---|
490 | assert((RpUnits::convert("5.00psi","torr",RpUnits::UNITS_ON)) == "258.575torr"); |
---|
491 | std::cout << "convert(\"5.00psi\",\"torr\",UNITS_ON) passed" << std::endl; |
---|
492 | |
---|
493 | |
---|
494 | |
---|
495 | |
---|
496 | assert((RpUnits::convert("5.00psi","kPa",RpUnits::UNITS_OFF)) == "34.4738"); |
---|
497 | std::cout << "convert(\"5.00psi\",\"kPa\",UNITS_OFF) passed" << std::endl; |
---|
498 | assert((RpUnits::convert("5.00psi","kPa",RpUnits::UNITS_ON)) == "34.4738kPa"); |
---|
499 | std::cout << "convert(\"5.00psi\",\"kPa\",UNITS_ON) passed" << std::endl; |
---|
500 | |
---|
501 | |
---|
502 | |
---|
503 | |
---|
504 | assert((RpUnits::convert("5.00torr","mmHg",RpUnits::UNITS_OFF)) == "5"); |
---|
505 | std::cout << "convert(\"5.00torr\",\"mmHg\",UNITS_OFF) passed" << std::endl; |
---|
506 | assert((RpUnits::convert("5.00torr","mmHg",RpUnits::UNITS_ON)) == "5mmHg"); |
---|
507 | std::cout << "convert(\"5.00torr\",\"mmHg\",UNITS_ON) passed" << std::endl; |
---|
508 | |
---|
509 | return 0; |
---|
510 | |
---|
511 | } |
---|