forked from knaxus/problem-solving-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext-greater-element.test.js
38 lines (29 loc) · 1.12 KB
/
next-greater-element.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
const { nextGreaterElement } = require('.');
describe('Next greater element', () => {
it('returns next greater elements collection', () => {
const input = [4, 6, 3, 2, 8, 1]
const greaterElements = [6, 8, 8, 8, -1, -1]
expect(nextGreaterElement(input)).toEqual(greaterElements);
});
it('returns and empty collection for an empty array', () => {
expect(nextGreaterElement([])).toEqual([]);
});
it('returns an array with -1 if the input has only one element', () => {
expect(nextGreaterElement([0])).toEqual([-1]);
});
it('returns a collection of -1 if there is no greater element', () => {
const input = [90, 40, 15, 7, -1, -10]
const greaterElements = [-1, -1, -1, -1, -1, -1]
expect(nextGreaterElement(input)).toEqual(greaterElements);
});
it('uses -1 if the numbers are the same', () => {
const input = [90, 90]
const greaterElements = [-1, -1]
expect(nextGreaterElement(input)).toEqual(greaterElements);
});
it('throws an error if the input is not an array', () => {
expect(() => {
nextGreaterElement('xunda')
}).toThrowError('Invalid Argument');
});
});