Created
March 15, 2018 15:56
-
-
Save KignorChan/e82a9a597e2a02115238227e911ff1b5 to your computer and use it in GitHub Desktop.
Array.prototype.reverse test
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 (C) 2016 Qiliang Chen. All rights reserved. | |
// This code is governed by the BSD license found in the LICENSE file. | |
/*--- | |
description: Array.prototype.reverse is to reverse the array. This tester will test | |
if this function work correctly. This will try both numbers and strings. | |
This tester will create two array: Array of strings named "sample", and Array of integer named "sample2" | |
Then they will call reverse built-in function. | |
At last, the reversed array will be compared with expected datas. | |
info: > | |
esid: sec-array.prototype.reverse | |
---*/ | |
var sample=[]; | |
sample[0] = "No way!"; | |
sample[1] = "Ok, here it is"; | |
sample[2] = "Hello world!"; | |
sample[3] = ""; | |
sample[4] = "This is a string"; | |
sample[5] = "An apple a day keeps doctors away!"; | |
sample.reverse(); | |
//assert.compare(sample, ["An apple a day keeps doctors away!","This is a string", | |
// "", "Hello world!", "Ok, here it is", "No way!"]); | |
assert.sameValue(sample[0], "An apple a day keeps doctors away!"); | |
assert.sameValue(sample[1], "This is a string"); | |
assert.sameValue(sample[2], ""); | |
assert.sameValue(sample[3], "Hello world!"); | |
assert.sameValue(sample[4], "Ok, here it is"); | |
assert.sameValue(sample[5], "No way!"); | |
var sample2 = []; | |
sample2[0] = 5; | |
sample2[1] = 2; | |
sample2[2] = 7; | |
sample2[3] = 9; | |
sample2.reverse(); | |
assert.sameValue(sample2[0], 9); | |
assert.sameValue(sample2[1], 7); | |
assert.sameValue(sample2[2], 2); | |
assert.sameValue(sample2[3], 5); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment