1
0
Fork 0

type-safe comparisons

This commit is contained in:
Jan Steemann 2015-01-13 01:31:39 +01:00
parent b54dfae96f
commit f9cfbbee4e
1 changed files with 9 additions and 9 deletions

View File

@ -24,11 +24,11 @@ var jsUnity = exports.jsUnity = (function () {
}
function hash(v) {
if (v instanceof Object && v != null) {
if (v instanceof Object && v !== null) {
var arr = [];
var sorted = Object.keys(v).sort();
var sorted = Object.keys(v).sort(), n = sorted.length;
for (var i = 0; i < sorted.length; i++) {
for (var i = 0; i < n; i++) {
var p = sorted[i];
if (v.hasOwnProperty(p)) {
arr.push(p);
@ -95,7 +95,7 @@ var jsUnity = exports.jsUnity = (function () {
assertEqual: function (expected, actual, message) {
counter++;
if (hash(expected) != hash(actual)) {
if (hash(expected) !== hash(actual)) {
var err = new Error();
throw fmt("?: (?) is not equal to (?)\n(?)",
message || "assertEqual", actual, expected, err.stack);
@ -104,7 +104,7 @@ var jsUnity = exports.jsUnity = (function () {
assertNotEqual: function (expected, actual, message) {
counter++;
if (hash(expected) == hash(actual)) {
if (hash(expected) === hash(actual)) {
var err = new Error();
throw fmt("?: (?) is equal to (?)\n(?)",
message || "assertNotEqual", actual, expected, err.stack);