Assert
Description
Main assertion class with static methods that you call in unit test functions to assert that some conditions hold true.
API overview
Constructor
Assert
()
Constants
Constants
| CALL_STACK_SKIP: Number |
static
Defines how many calls are skipped from the top of the stack, to avoid from internal Assert calls showing up in every result |
| FLOAT_EPSILON: Number |
static
This should be the smallest difference between two floats |
| RESULT_SUCCESS: AssertResult |
static
Successful assert results aren't saved individually as you usually aren't interested in detailed specifics of successfully ran assertions |
Functions
Public functions
| compare ( expected: Object , actual: Object , msg: String = null ): Void |
static Assertion passes if the expected value equals the actual value |
| compareNumber ( expected: Number , actual: Number , msg: String = null , maxRelativeDifference: Number = ): Void |
static Assertion passes if the expected number equals the actual number within the tolerance of maxRelativeDifference |
| contains ( needle: Object , haystack: Object , msg: String = null ): Void |
static Assertion passes if the needle is contained within the haystack |
| equal ( a: Object , b: Object , msg: String = null ): Void |
static Assertion passes if the two Objects pass the equality test |
| equalNumber ( a: Number , b: Number , msg: String = null , maxRelativeDifference: Number = ): Void |
static Assertion passes if the first number equals the second number within the tolerance of maxRelativeDifference |
| fail ( msg: String = null ): Void |
static Unconditional assertion failure, useful for custom branching paths, when you just want to log a failure without any additional logic |
| greater ( a: Object , b: Object , msg: String = null ): Void |
static Assertion passes if the first value is greater than the second value |
| greaterOrEqual ( a: Object , b: Object , msg: String = null ): Void |
static Assertion passes if the first value is greater than or equal to the second value |
| instanceOf ( o: Object , type: Type , msg: String = null ): Void |
static Assertion passes if the provided Object is an instance of the provided Type |
| isFalse ( o: Object , msg: String = null ): Void |
static Assertion passes if the provided Object equals false |
| isNotNaN ( n: Number , msg: String = null ): Void |
static Assertion passes if the provided Number is not NaN (is a valid Number) |
| isNotNull ( o: Object , msg: String = null ): Void |
static Assertion passes if the provided Object does not equal null |
| isNull ( o: Object , msg: String = null ): Void |
static Assertion passes if the provided Object equals null |
| isTrue ( o: Object , msg: String = null ): Void |
static Assertion passes if the provided Object equals true |
| less ( a: Object , b: Object , msg: String = null ): Void |
static Assertion passes if the first value is less than the second value |
| lessOrEqual ( a: Object , b: Object , msg: String = null ): Void |
static Assertion passes if the first value is less than or equal to the second value |
| notEqual ( a: Object , b: Object , msg: String = null ): Void |
static Assertion passes if the two Objects do not pass the equality test |
| notEqualNumber ( a: Number , b: Number , msg: String = null , maxRelativeDifference: Number = ): Void |
static Assertion passes if the first number does not equal the second number within the tolerance of maxRelativeDifference |
| notInstanceOf ( o: Object , type: Type , msg: String = null ): Void |
static Assertion passes if the provided Object is not an instance of the provided type |
| popResults (): Vector.<AssertResult> |
static Return all the results since the last time this function was called |
Constructor
Assert ()
Constants
CALL_STACK_SKIP: Number
static
Defines how many calls are skipped from the top of the stack, to avoid from internal Assert calls showing up in every result.
FLOAT_EPSILON: Number
static
This should be the smallest difference between two floats. Loom uses doubles, so this could potentially be even smaller.
RESULT_SUCCESS: AssertResult
static
Successful assert results aren't saved individually as you usually aren't interested in detailed specifics of successfully ran assertions. This object is inserted as a placeholder for all successful assertions.
Functions
compare ( expected: Object , actual: Object , msg: String = null ): Void
static
Assertion passes if the expected value equals the actual value. Functionally equivalent to equal, but with added semantics and terminology.
Parameters
| expected: Object | The expected value, which is usually some sort of a constant. |
| actual: Object | The actual value, which is usually what you want to verify. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
compareNumber ( expected: Number , actual: Number , msg: String = null , maxRelativeDifference: Number = ): Void
static
Assertion passes if the expected number equals the actual number within the tolerance of maxRelativeDifference.
It should be greater than 0, but a small number (near the epsilon of floats). By default it is twice the float epsilon i.e. 2.192092896e-7.
Parameters
| expected: Number | The expected number, which is usually a constant. |
| actual: Number | The actual number, which is usually a result you want to verify. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
| maxRelativeDifference: Number = | The maximum relative difference between the numbers that still counts as being equal. |
contains ( needle: Object , haystack: Object , msg: String = null ): Void
static
Assertion passes if the needle is contained within the haystack.
If haystack is a Vector, the assertion passes if needle is contained within the Vector.
Parameters
| needle: Object | The needle has to be a String if the haystack is a String. If the haystack is a Vector, the needle can be an Object. |
| haystack: Object | If haystack is a String, the assertion passes if needle is a substring contained in haystack. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
equal ( a: Object , b: Object , msg: String = null ): Void
static
Assertion passes if the two Objects pass the equality test. See compare if you want to compare an expected value to an actual one.
Parameters
| a: Object | First object to compare. |
| b: Object | Second object to compare with the first one. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
equalNumber ( a: Number , b: Number , msg: String = null , maxRelativeDifference: Number = ): Void
static
Assertion passes if the first number equals the second number within the tolerance of maxRelativeDifference.
It should be greater than 0, but a small number (near the epsilon of floats). By default it is twice the float epsilon i.e. 2.192092896e-7.
Parameters
| a: Number | The first number. |
| b: Number | The second number. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
| maxRelativeDifference: Number = | The maximum relative difference between the numbers that still counts as being equal. |
fail ( msg: String = null ): Void
static
Unconditional assertion failure, useful for custom branching paths, when you just want to log a failure without any additional logic.
Parameters
| msg: String = null | A custom message to attach to the result. |
getFullTypeName
(): String
Inherited from Object
native
Gets the fully qualified type name of the Object. The fully qualified type name includes the package of the type.
Returns
| String | fully qualified type name of the Object. |
getType
(): Type
Inherited from Object
native
Gets the Type that describes the Object.
Returns
| Type | The Type that describes the object. |
getTypeName
(): String
Inherited from Object
native
Gets the type name of the Object.
Returns
| String | type name of the Object. |
greater ( a: Object , b: Object , msg: String = null ): Void
static
Assertion passes if the first value is greater than the second value.
Parameters
| a: Object | The first value, e.g. a Number or a String. This should be greater than the second value. |
| b: Object | The second value, e.g. a Number or a String. This should be less than the first value. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
greaterOrEqual ( a: Object , b: Object , msg: String = null ): Void
static
Assertion passes if the first value is greater than or equal to the second value.
Parameters
| a: Object | The first value, e.g. a Number or a String. This should be greater than or equal to the second value. |
| b: Object | The second value, e.g. a Number or a String. This should be less than or equal to the first value. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
instanceOf ( o: Object , type: Type , msg: String = null ): Void
static
Assertion passes if the provided Object is an instance of the provided Type.
Parameters
| o: Object | The instance to check. |
| type: Type | The type to check the instance against. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
isFalse ( o: Object , msg: String = null ): Void
static
Assertion passes if the provided Object equals false.
Parameters
| o: Object | The Object to compare to false. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
isNotNaN ( n: Number , msg: String = null ): Void
static
Assertion passes if the provided Number is not NaN (is a valid Number). NaN equality is tested using self-equality i.e. n == n, which is only true for non-NaN values.
Parameters
| n: Number | The Number to test. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
isNotNull ( o: Object , msg: String = null ): Void
static
Assertion passes if the provided Object does not equal null.
Parameters
| o: Object | The Object to compare to null. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
isNull ( o: Object , msg: String = null ): Void
static
Assertion passes if the provided Object equals null.
Parameters
| o: Object | The Object to compare to null. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
isTrue ( o: Object , msg: String = null ): Void
static
Assertion passes if the provided Object equals true.
Parameters
| o: Object | The Object to compare to true. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
less ( a: Object , b: Object , msg: String = null ): Void
static
Assertion passes if the first value is less than the second value.
Parameters
| a: Object | The first value, e.g. a Number or a String. This should be less than the second value. |
| b: Object | The second value, e.g. a Number or a String. This should be greater than the first value. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
lessOrEqual ( a: Object , b: Object , msg: String = null ): Void
static
Assertion passes if the first value is less than or equal to the second value.
Parameters
| a: Object | The first value, e.g. a Number or a String. This should be less than or equal to the second value. |
| b: Object | The second value, e.g. a Number or a String. This should be greater than or equal to the first value. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
notEqual ( a: Object , b: Object , msg: String = null ): Void
static
Assertion passes if the two Objects do not pass the equality test.
Parameters
| a: Object | First object to compare. |
| b: Object | Second object to compare. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
notEqualNumber ( a: Number , b: Number , msg: String = null , maxRelativeDifference: Number = ): Void
static
Assertion passes if the first number does not equal the second number within the tolerance of maxRelativeDifference.
It should be greater than 0, but a small number (near the epsilon of floats). By default it is twice the float epsilon i.e. 2.192092896e-7.
Parameters
| a: Number | The first number. |
| b: Number | The second number. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
| maxRelativeDifference: Number = | The maximum relative difference between the numbers that still counts as being equal. |
notInstanceOf ( o: Object , type: Type , msg: String = null ): Void
static
Assertion passes if the provided Object is not an instance of the provided type.
Parameters
| o: Object | The instance to check. |
| type: Type | The type to check the instance against. |
| msg: String = null | Optional custom message providing more information in the event of assertion failure. |
popResults (): Vector.<AssertResult>
static
Return all the results since the last time this function was called.
Returns
| Vector | All the assertion results since the last popResults call. |