forked from fingerecho/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqunit-assert-deep-value-equal.js
More file actions
59 lines (50 loc) · 1.61 KB
/
qunit-assert-deep-value-equal.js
File metadata and controls
59 lines (50 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(function(factory) {
// NOTE:
// All techniques except for the "browser globals" fallback will extend the
// provided QUnit object but return the isolated API methods
// For AMD: Register as an anonymous AMD module with a named dependency on "qunit".
if (typeof define === "function" && define.amd) {
define(["qunit"], factory);
}
// For Node.js
else if (typeof module !== "undefined" && module && module.exports && typeof require === "function") {
module.exports = factory(require("qunitjs"));
}
// For CommonJS with `exports`, but without `module.exports`, like Rhino
else if (typeof exports !== "undefined" && exports && typeof require === "function") {
var qunit = require("qunitjs");
qunit.extend(exports, factory(qunit));
}
// For browser globals
else {
factory(QUnit);
}
}(function(QUnit) {
// convert typed possibly multidimensional array to untyped
function toDeepUntypedArray(a) {
if (a.constructor == Float32Array) {
return Array.from(a);
}
for (var i=0; i < a.length; i++) {
a[i] = toDeepUntypedArray(a[i])
}
return a;
}
/**
* deep/multidimensional typed/untyped array diff check
*
* @example assert.deepValueEqual([[1,2,3],[1,2,3]], [new Float32Array([1,2,3]), new Float32Array([1,2,3])]);
*
* @param Number actual
* @param Number expected
* @param String message (optional)
*/
function deepValueEqual(actual, expected, message) {
QUnit.assert.deepEqual(toDeepUntypedArray(actual), toDeepUntypedArray(expected), message);
}
var api = {
deepValueEqual: deepValueEqual
};
QUnit.extend(QUnit.assert, api);
return api;
}));