Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit edb379a

Browse files
committed
--fix: code coverage to 100%
1 parent 0329d44 commit edb379a

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

‎src/_Problems_/binary-tree-to-binary-search-tree/binary-tree-to-binary-search-tree.test.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ const BinaryTree = require('../../_DataStructures_/Trees/BinaryTree');
44
describe('Binary tree to binary search tree', () => {
55
let tree;
66

7-
describe('Create Binary Tree', () => {
8-
tree = new BinaryTree([10, 30, 15, 20, null, null, 5]);
7+
it('Should return `null` if root is null', () => {
8+
tree = new BinaryTree([1]);
9+
tree.root = null;
10+
expect(binaryTreeToBST(tree)).toEqual(null);
911
});
1012

1113
it('Should converted binary tree to binary search tree', () => {
14+
tree = new BinaryTree([10, 30, 15, 20, null, null, 5]);
1215
const bTree = binaryTreeToBST(tree);
1316
expect(storeInorder(bTree)).toEqual([5, 10, 15, 20, 30]);
1417
});

‎src/_Problems_/next-greater-element/index.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ function nextGreaterElement(arr) {
2020
for (let i = arr.length - 1; i >= 0; i -= 1) {
2121
if (s1.peek()) {
2222
let top = s1.peek();
23-
while (top <= arr[i]) {
24-
// if the stack is empty, break the while loop
25-
if (!s1.peek()) break;
23+
while (top && top <= arr[i]) {
2624
// pop the elements
2725
s1.pop();
2826
// get the new top
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
const { nextGreaterElement } = require('.');
22

33
describe('Next greater element', () => {
4-
it('returns next greater elements collection', () => {
5-
const input = [4, 6, 3, 2, 8, 1]
6-
const greaterElements = [6,8, 8, 8, -1, -1]
4+
it('Should returns next greater elements collection', () => {
5+
const input = [4, 11,6, 3, 2, 8, 1];
6+
const greaterElements = [11,-1,8, 8, 8, -1, -1];
77

88
expect(nextGreaterElement(input)).toEqual(greaterElements);
99
});
1010

11-
it('returns and empty collection for an empty array', () => {
11+
it('Should returns and empty collection for an empty array', () => {
1212
expect(nextGreaterElement([])).toEqual([]);
1313
});
1414

15-
it('returns an array with -1 if the input has only one element', () => {
15+
it('Should returns an array with -1 if the input has only one element', () => {
1616
expect(nextGreaterElement([0])).toEqual([-1]);
1717
});
1818

19-
it('returns a collection of -1 if there is no greater element', () => {
20-
const input = [90, 40, 15, 7, -1, -10]
21-
const greaterElements = [-1, -1, -1, -1, -1, -1]
19+
it('Should returns a collection of -1 if there is no greater element', () => {
20+
const input = [90, 40, 15, 7, -1, -10];
21+
const greaterElements = [-1, -1, -1, -1, -1, -1];
2222

2323
expect(nextGreaterElement(input)).toEqual(greaterElements);
2424
});
2525

26-
it('uses -1 if the numbers are the same', () => {
27-
const input = [90, 90]
28-
const greaterElements = [-1, -1]
26+
it('Should uses -1 if the numbers are the same', () => {
27+
const input = [90, 90];
28+
const greaterElements = [-1, -1];
2929

3030
expect(nextGreaterElement(input)).toEqual(greaterElements);
3131
});
3232

33-
it('throws an error if the input is not an array', () => {
33+
it('Should throws an error if the input is not an array', () => {
3434
expect(() => {
35-
nextGreaterElement('xunda')
35+
nextGreaterElement('xunda');
3636
}).toThrowError('Invalid Argument');
3737
});
3838
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /