Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
Latest commit
43 lines (34 loc) · 1.15 KB
/
Copy pathtest.js
File metadata and controls
43 lines (34 loc) · 1.15 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
constassert=require("assert")
constreverse=require(".")
describe("reverse()",()=>{
it("should reverse a standard array of numbers",()=>{
constinput=[1,2,3]
constexpected=[3,2,1]
assert.deepStrictEqual(reverse(input),expected)
})
it("should work with an array of strings",()=>{
constinput=["a","b","c","d"]
constexpected=["d","c","b","a"]
assert.deepStrictEqual(reverse(input),expected)
})
it("should return a single-element array unchanged",()=>{
constinput=[100]
assert.deepStrictEqual(reverse(input),input)
})
it("should throw an error when the input is not an array",()=>{
assert.throws(()=>{
reverse("not an array")
},/Expectsanarray/)
})
it("should return empty array unchanged",()=>{
assert.deepStrictEqual(reverse([]),[])
})
it("should handle a 15k length array",()=>{
constsize=15000
constinput=Array.from({length: size},(_,i)=>i)
constexpected=[...input].reverse()
constresult=reverse(input)
assert.strictEqual(result.length,size)
assert.deepStrictEqual(result,expected)
})
})