Created
September 10, 2011 05:13
-
-
Save ishiduca/1207960 to your computer and use it in GitHub Desktop.
Function.test(thisObject, argsArray, forecast) の実装
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 関数の返す結果が想定した結果と同等かをチェックする test メソッド | |
// Func.test(thisObj, argsArray, forecast); | |
if (! Function.prototype.test) { | |
Function.prototype.test = function (that, args, forecast) { | |
var result = this.apply(that, args); | |
result = JSON.stringify(result); | |
forecast = JSON.stringify(forecast); | |
// return (result === forecast) ? true : false; 本当はこっち | |
console.log( | |
(result === forecast) | |
? [ 'success:', result ].join('\t') | |
: [ '!failed:', result, forecast ].join('\t') | |
); | |
}; | |
}; | |
function add (a, b) { | |
return (a + b); | |
} | |
var yuki = { | |
loves : 'Nao' | |
}; | |
var tomo = { | |
love : function () { | |
return this.loves; | |
}, | |
loves : 'Yuki', | |
}; | |
// * TEST * // | |
add.test(null, [2, 3], 5); | |
var whoLovesWho = tomo.love; | |
whoLovesWho.test(tomo, [], 'Yuki'); | |
whoLovesWho.test(yuki, [], 'Nao'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment