Created
March 13, 2018 02:59
-
-
Save Owen-Mak/569dd52440e48192a5edab013f0228e4 to your computer and use it in GitHub Desktop.
Test cases for reverse function in Array objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2018 Owen Mak. All rights reserved. | |
// This code is governed by the BSD license found in the LICENSE file. | |
/*--- | |
info: | | |
The elements of the array are rearranged so as to reverse their order. | |
The object is returned as the result of the call | |
esid: sec-array.prototype.reverse | |
es6id: 22.1.3.20_A1_T2 | |
description: Checking this algorithm, elements are objects and primitives | |
... | |
includes: [testTypedArray.js, compareArray.js] | |
---*/ | |
var x = [1,2,3,4]; | |
var y = [4,3,2,1]; | |
var reverse = x.reverse(); | |
//Check #1 | |
//ensure return type of array after reverse remains as object | |
assert.sameValue(typeof(reverse), "object", "typeof(x.reverse()) === 'object'"); | |
//Check #2 | |
//returns same object | |
assert.sameValue(reverse, x, "returns the same object"); | |
//Check #3 | |
assert.sameValue(reverse[0], 4, "reverse[0] === 4"); | |
assert.sameValue(reverse[1], 3, "reverse[1] === 3"); | |
assert.sameValue(reverse[2], 2, "reverse[2] === 2"); | |
assert.sameValue(reverse[3], 1, "reverse[3] === 1"); | |
//Check #4 | |
//using compareArray function from typedArray to compare the arrays | |
assert(compareArray(reverse, [4, 3, 2, 1])); | |
assert(compareArray(reverse, y)); | |
//Check#5 | |
//check for non-numeric values | |
var x = [1,2,3,4]; | |
x.foo = "foo"; | |
y.foo = "foo"; | |
var reverse = x.reverse(); | |
assert.sameValue(reverse.foo, "foo", "reverse.foo === 'foo'"); | |
assert (compareArray(reverse, y)); | |
//Check #6 | |
//Check for string lengths | |
assert.sameValue(x.length, 4, "length is 4"); | |
assert.sameValue(x.length, reverse.length, "length is preserved after reverse"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment