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