Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created September 10, 2011 05:13
Show Gist options
  • Save ishiduca/1207960 to your computer and use it in GitHub Desktop.
Save ishiduca/1207960 to your computer and use it in GitHub Desktop.
Function.test(thisObject, argsArray, forecast) の実装
// 関数の返す結果が想定した結果と同等かをチェックする 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