|
/** |
|
* Basic class |
|
*/ |
|
function Assert() {} |
|
|
|
/** |
|
* Compose the string to see if the test succeded or failed |
|
* |
|
* @return {string|Error} Message with the corresponding |
|
*/ |
|
Assert.basicCheck = (condition,message)=>(condition ? '๐' : '๐') + ' ๏ผ ' + message; |
|
|
|
/** |
|
* Print the message in the correct way |
|
*/ |
|
Assert.print = function(condition, message, error) { |
|
var res = this.basicCheck(condition, message); |
|
console.log(res + (condition? '' : '\n ' + error)); |
|
} |
|
|
|
/** |
|
* Checks if the condition is true, prints and returns true if so |
|
* |
|
* @param {boolean} condition to be tested |
|
* @param {string} message describe the assert |
|
* @return {boolean} wheter the assert succeded or failed |
|
*/ |
|
Assert.true = function(condition, message) { |
|
var error = 'condition doesn\'t match'; |
|
this.print(condition, message, error) |
|
return condition; |
|
} |
|
|
|
/** |
|
* Checks if the condition is false, prints and returns true if so |
|
* |
|
* @param {boolean} condition to be tested |
|
* @param {string} message describe the assert |
|
* @return {boolean} wheter the assert succeded or failed |
|
*/ |
|
Assert.false = function(condition, message) { |
|
return this.true(!condition, message); |
|
} |
|
|
|
/** |
|
* Assert function to implement a couple of tests |
|
* |
|
* @param {Object} first object to be tested |
|
* @param {Object} second object to be tested |
|
* @return {boolean} wheter the assert succeded or failed |
|
*/ |
|
Assert.equals = function(first, second, message) { |
|
var condition = first == second; |
|
var error = 'provided "' + first + '" not equals expected "' + second + '"'; |
|
this.print(condition, message, error); |
|
return condition; |
|
} |
|
|
|
Assert.true(true, 'This is truthful'); |
|
Assert.true(false, 'This is truthful'); |
|
Assert.false(false, 'This is a lie'); |
|
Assert.false(true, 'This is a lie'); |
|
Assert.equals(typeof 'hola', 'string', 'This variable contains a message'); |
|
Assert.equals(typeof 3, 'string', 'This variable contains a message'); |