2017-07-14 17:37:24 +02:00
|
|
|
// Copyright (C) 2017 Ecma International. All rights reserved.
|
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
/*---
|
|
|
|
description: |
|
|
|
|
Compare the contents of two arrays
|
2019-09-25 02:22:26 +02:00
|
|
|
defines: [compareArray]
|
2017-07-14 17:37:24 +02:00
|
|
|
---*/
|
2014-07-19 00:22:37 +02:00
|
|
|
|
2019-09-18 18:39:12 +02:00
|
|
|
// @ts-check
|
|
|
|
|
2019-08-24 12:24:33 +02:00
|
|
|
function isSameValue(a, b) {
|
|
|
|
if (a === 0 && b === 0) return 1 / a === 1 / b;
|
|
|
|
if (a !== a && b !== b) return true;
|
|
|
|
|
|
|
|
return a === b;
|
|
|
|
}
|
|
|
|
|
2019-09-18 18:39:12 +02:00
|
|
|
/**
|
|
|
|
* @template T
|
|
|
|
* @param {T[]} a
|
|
|
|
* @param {T[]} b
|
|
|
|
*/
|
2015-03-04 16:30:59 +01:00
|
|
|
function compareArray(a, b) {
|
|
|
|
if (b.length !== a.length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < a.length; i++) {
|
2019-08-24 12:24:33 +02:00
|
|
|
if (!isSameValue(b[i], a[i])) {
|
2015-03-04 16:30:59 +01:00
|
|
|
return false;
|
2014-07-19 00:22:37 +02:00
|
|
|
}
|
2015-03-04 16:30:59 +01:00
|
|
|
}
|
|
|
|
return true;
|
2014-07-19 00:22:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 18:39:12 +02:00
|
|
|
/**
|
|
|
|
* @template T
|
|
|
|
* @param {T[]} actual
|
|
|
|
* @param {T[]} expected
|
|
|
|
* @param {string} [message]
|
|
|
|
*/
|
2017-04-25 16:06:15 +02:00
|
|
|
assert.compareArray = function(actual, expected, message) {
|
2017-04-26 14:05:31 +02:00
|
|
|
assert(compareArray(actual, expected),
|
2019-09-18 18:39:12 +02:00
|
|
|
'Expected ' + assert._formatValue(actual) + ' and ' + assert._formatValue(expected) + ' to have the same contents. ' + message);
|
2017-07-14 17:37:24 +02:00
|
|
|
};
|