-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
arrays-test.js
130 lines (100 loc) · 3.77 KB
/
arrays-test.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*global describe, it */
const expect = require('chai').expect
const fs = require('fs')
const jsdom = require('mocha-jsdom')
const path = require('path')
describe('arrays', () => {
jsdom({
src: fs.readFileSync(path.resolve(__dirname, '..', 'arrays.js'), 'utf-8')
})
describe('chocolateBars', () => {
it('is an array containing "snickers", "hundred grand", "kitkat", and "skittles"', () => {
expect(chocolateBars).to.eql['snickers', 'hundred grand', 'kitkat', 'skittles']
})
})
describe('addElementToBeginningOfArray(array, element)', () => {
it('adds an element to the beginning of an array', () => {
expect(addElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1])
})
it('does not alter the original array', () => {
const array = [1]
addElementToBeginningOfArray(array, 'foo')
expect(array).to.eql([1])
})
})
describe('destructivelyAddElementToBeginningOfArray(array, element)', () => {
it('adds an element to the beginning of an array', () => {
expect(destructivelyAddElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1])
})
it('alters the original array', () => {
const array = [1]
destructivelyAddElementToBeginningOfArray(array, 'foo')
expect(array).to.eql(['foo', 1])
})
})
describe('addElementToEndOfArray(array, element)', () => {
it('adds an element to the end of an array', () => {
expect(addElementToEndOfArray([1], 'foo')).to.eql([1, 'foo'])
})
it('does not alter the original array', () => {
const array = [1]
addElementToEndOfArray(array, 'foo')
expect(array).to.eql([1])
})
})
describe('destructivelyAddElementToEndOfArray(array, element)', () => {
it('adds an element to the end of an array', () => {
expect(destructivelyAddElementToEndOfArray([1], 'foo')).to.eql([1, 'foo'])
})
it('alters the original array', () => {
const array = [1]
destructivelyAddElementToEndOfArray(array, 'foo')
expect(array).to.eql([1, 'foo'])
})
})
describe('accessElementInArray(array, index)', () => {
it('accesses the element in array at the given index', () => {
expect(accessElementInArray([1, 2, 3], 2)).to.equal(3)
})
})
describe('destructivelyRemoveElementFromBeginningOfArray(array)', ()=>{
it('returns the array with the first element removed', () => {
expect(destructivelyRemoveElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3])
})
it('alters the original array', ()=>{
const array = [1, 2, 3];
destructivelyRemoveElementFromBeginningOfArray(array);
expect(array).to.eql([2, 3]);
})
})
describe('removeElementFromBeginningOfArray(array)', () => {
it('removes the first element from the array', () => {
expect(removeElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3])
})
it('does not alter the original array', () => {
const array = [1, 2, 3];
removeElementFromBeginningOfArray(array);
expect(array).to.eql([1, 2, 3]);
})
})
describe('destructivelyRemoveElementFromEndOfArray(array)', () => {
it('returns the array with the last element removed', () => {
expect(destructivelyRemoveElementFromEndOfArray([1, 2, 3])).to.eql([1, 2])
})
it('alters the original array', ()=>{
const array = [1, 2, 3];
destructivelyRemoveElementFromEndOfArray(array);
expect(array).to.eql([1, 2]);
})
})
describe('removeElementFromEndOfArray(array)', () => {
it('removes the last element from the array', () => {
expect(removeElementFromEndOfArray([1, 2, 3])).to.eql([1, 2])
})
it('does not alter the original array', () => {
const array = [1, 2, 3];
removeElementFromEndOfArray(array);
expect(array).to.eql([1, 2, 3]);
})
})
})