Jamoma API  0.6.0.a19
TTUnitTest.h
1 /*
2  * TTUnitTest
3  * Copyright © 2011, Timothy Place and Trond Lossius
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #ifndef __TT_UNITTEST_H__
10 #define __TT_UNITTEST_H__
11 
12 #include "TTFoundationAPI.h"
13 
14 
15 /** Determine if two 32-bit floats are equal in value, but tolerant of floating-point precision.
16  @group unittest
17  @param aFloat The first float to test
18  @param bFloat The second float to test
19  @expectedResult The expected result when comparing the two floats a and b. Defaults to TRUE
20  @maxUnitsInTheLastPlace Error tolerance when comparing the numbers. Defaults to 10
21  @return Returns true if a == b, otherwise returns false. */
22 TTBoolean TTFOUNDATION_EXPORT TTTestFloatEquivalence(TTFloat32 aFloat, TTFloat32 bFloat, TTBoolean expectedResult = true, TTFloat32 epsilon = 0.000001);
23 
24 
25 /** Determine if two 32-bit floats are equal in value, but tolerant of floating-point precision.
26  @group unittest
27  @param aFloat The first float to test
28  @param bFloat The second float to test
29  @expectedResult The expected result when comparing the two floats a and b. Defaults to TRUE
30  @maxUnitsInTheLastPlace Error tolerance when comparing the numbers. Defaults to 10
31  @return Returns true if a == b, otherwise returns false. */
32 TTBoolean TTFOUNDATION_EXPORT TTTestFloatEquivalence(TTFloat64 aFloat, TTFloat64 bFloat, TTBoolean expectedResult = true, TTFloat64 epsilon = 0.0000000000001);
33 
34 
35 /** Determine if two arrays of 32-bit floats are equal in value, but tolerant of floating-point precision.
36  @group unittest
37  @param aFloat The first float to test
38  @param bFloat The second float to test
39  @expectedResult The expected result when comparing the two floats a and b. Defaults to TRUE
40  @maxUnitsInTheLastPlace Error tolerance when comparing the numbers. Defaults to 10
41  @return Returns true if a == b, otherwise returns false. */
42 TTBoolean TTFOUNDATION_EXPORT TTTestFloat32ArrayEquivalence(TTValue &aFloat, TTValue &bFloat, TTBoolean expectedResult = true, TTFloat32 epsilon = 0.000001);
43 
44 /** Determine if two arrays of 64-bit floats are equal in value, but tolerant of floating-point precision.
45  @group unittest
46  @param aFloat The first float to test
47  @param bFloat The second float to test
48  @expectedResult The expected result when comparing the two floats a and b. Defaults to TRUE
49  @maxUnitsInTheLastPlace Error tolerance when comparing the numbers. Defaults to 10
50  @return Returns true if a == b, otherwise returns false. */
51 TTBoolean TTFOUNDATION_EXPORT TTTestFloat64ArrayEquivalence(TTValue &aFloat, TTValue &bFloat, TTBoolean expectedResult = true, TTFloat64 epsilon = 0.0000000000001);
52 
53 
54 /** Post a message to the console.
55  Adequate indenting is provided for free, as are newlines at the end.
56  At some point we may want to additionally log these messages in other ways (e.g. to a database).
57  @group unittest
58  @param msg The string to post
59 */
60 void TTFOUNDATION_EXPORT TTTestLog(const char *msg, ...);
61 
62 
63 /** Log the outcome of a proceedure that should result as true.
64  Test assertions are not like normal C++ assertions -- test assertions are not designed to crash when they fail.
65  @group unittest
66  @param aTestName A name you wish to give the assertion. Should be as descriptive as possible.
67  @param aTestResult You should pass 'true' if the assertion passes, or 'false' if it failed.
68  @param testAssertionCount The address of a variable you incrementing when making a test assertion.
69  @param errorCount The address of a variable you incrementing when test assertions fail.
70  @return Returns true if a == b, otherwise returns false. */
71 
72 /** Declare a result to be expected.
73  A failed expectation will be flagged as an error in the IDE (Xcode or VS).
74 
75  @ingroup testing
76  @param name The name of the expectation for logging purposes.
77  @param actual The result received.
78  @param expected The result expected.
79  @return Returns a 1 if the expection failed, 0 if it passes.
80  */
81 #define TTTestAssertion(aTestName, aTestResult, testAssertionCount, errorCount) \
82  TTTestAssertionResult((aTestName),(aTestResult),(testAssertionCount), (errorCount), __FILE__, __LINE__)
83 
84 void TTFOUNDATION_EXPORT TTTestAssertionResult(const char* aTestName, TTBoolean aTestResult, int& testAssertionCount, int& errorCount, const char* filename = "", int linenumber = 0);
85 
86 
87 /** Wrap up the test results to pass back to whoever called this test.
88  @group unittest
89  @param testAssertionCount The number of assertions made during the test.
90  @param errorCount The number of assertions that failed during the test.
91  @param returnedTestInfo The argument passed to the test function, which will be filled-in with a dictionary upon return.
92  @return An error code if the test failed.
93  */
94 TTErr TTFOUNDATION_EXPORT TTTestFinish(int testAssertionCount, int errorCount, TTValue& returnedTestInfo);
95 
96 
97 #endif // __TT_UNITTEST_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
float TTFloat32
32 bit floating point number
Definition: TTBase.h:187
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