diff options
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/TypedArray/sort_small.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/sort_small.js b/js/src/tests/non262/TypedArray/sort_small.js new file mode 100644 index 0000000000..22f9dc69a6 --- /dev/null +++ b/js/src/tests/non262/TypedArray/sort_small.js @@ -0,0 +1,38 @@ +const testCases = { + // Pre-sorted test data, it's important that these arrays remain in ascending order. + [Int8Array.name]: [[-128, 127]], + [Int16Array.name]: [[-32768, -999, 1942, 32767]], + [Int32Array.name]: [[-2147483648, -320000, -244000, 2147483647]], + [Uint8Array.name]: [[255]], + [Uint16Array.name]: [[0, 65535, 65535]], + [Uint32Array.name]: [[0, 987632, 4294967295]], + [Uint8ClampedArray.name]: [[255]], + + // Test the behavior in the default comparator as described in 22.2.3.26. + // The spec boils down to, -0s come before +0s, and NaNs always come last. + // Float Arrays are used because all other types convert -0 and NaN to +0. + [Float32Array.name]: [ + [-2147483647, -2147483646.99, -0, 0, 2147483646.99, NaN], + [1/undefined, NaN, Number.NaN] + ], + [Float64Array.name]: [ + [-2147483646.99, -0, 0, 4147483646.99, NaN], + [1/undefined, NaN, Number.NaN] + ], +}; + +// Sort every possible permutation of an arrays +function sortAllPermutations(dataType, testData) { + let reference = new dataType(testData); + for (let permutation of Permutations(testData)) + assertDeepEq((new dataType(permutation)).sort(), reference); +} + +for (let constructor of sharedTypedArrayConstructors) { + for (let data of testCases[constructor.name]) { + sortAllPermutations(constructor, data); + } +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |