Skip to content

Commit

Permalink
fix(test): refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amejiarosario committed Oct 28, 2020
1 parent 8cd126d commit 571834a
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions book/interview-questions/daily-temperatures.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ describe('Stack: Daily Temperatures', () => {
expect(dailyTemperatures([30, 28, 50, 40, 30])).toEqual([2, 1, 0, 0, 0]);
});

it('should work', () => {
it('should work 2', () => {
expect(dailyTemperatures([73, 74, 75, 71, 69, 72, 76, 73])).toEqual([1, 1, 4, 2, 1, 1, 0, 0]);
});

it('should work', () => {
it('should work 3', () => {
expect(dailyTemperatures([89, 62, 70, 58, 47, 47, 46, 76, 100, 70])).toEqual([8, 1, 5, 4, 3, 2, 1, 1, 0, 0]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ll = (nums) => Array.from(new LinkedList(nums, Node));
expect(toString(fn(l3[0]))).toEqual('{ 21(,) -> 23(21,) -> 36(23,) -> 37(36,) }');
});

fit('works with flat 2 levels and reminder', () => {
it('works with flat 2 levels and reminder', () => {
// 1--- 2--- 3
// |
// 36--37
Expand Down
2 changes: 1 addition & 1 deletion book/interview-questions/linkedlist-same-data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Linked List: has same data', () => {
expect(hasSameData(l1, l2)).toEqual(true);
});

it('should work with different data', () => {
it('should work with different data separated', () => {
const l1 = new LinkedList(['he', 'll', 'o']).first;
const l2 = new LinkedList(['ho', 'la']).first;
expect(hasSameData(l1, l2)).toEqual(false);
Expand Down
4 changes: 2 additions & 2 deletions book/interview-questions/max-subarray.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const largeArray = require('./max-subarray.data');
describe('Max Subarray Sum', () => {
[maxSubArray, maxSubArrayBrute1, maxSubArrayBrute2].forEach((fn) => {
describe(`with ${fn.name}`, () => {
it('should work with small arrays', () => {
it('should work with large arrays', () => {
expect(fn([-2, 1, -3, 4, -1, 2, 1, -5, 4])).toEqual(6);
});

it('should work with small arrays', () => {
expect(fn([1, -3, 10, -5])).toEqual(10);
});

it('should work with large arrays', () => {
it('should work with humongous arrays', () => {
expect(fn(largeArray)).toEqual(4853);
});
});
Expand Down
2 changes: 1 addition & 1 deletion book/interview-questions/merge-intervals.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { merge } = require('./merge-intervals');
expect(actual).toEqual(expected);
});

it('should work with other case', () => {
it('should work with other case with large numbers', () => {
const actual = fn([[10, 99], [20, 50], [9, 11], [98, 100]]);
const expected = [[9, 100]];
expect(actual).toEqual(expected);
Expand Down
2 changes: 1 addition & 1 deletion book/interview-questions/merge-lists.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Linked List: Merge Lists', () => {
expect(asString(actual)).toEqual(expected);
});

it('should handle empty list 1', () => {
it('should handle empty list 2', () => {
const l1 = new LinkedList([2, 3, 4]).first;
const l2 = new LinkedList().first;
const actual = mergeTwoLists(l1, l2);
Expand Down
4 changes: 2 additions & 2 deletions book/interview-questions/most-common-words-ii.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const { mostCommonWords, mostCommonWordsBrute } = require('./most-common-words-i
)).toEqual(['keys']);
});

it('should work', () => {
it('should work 2', () => {
expect(fn(
'Look at it! What is it? It does look like my code from 1 year ago',
2,
)).toEqual(['it', 'look']);
});

it('should work', () => {
it('should work all puntuations', () => {
expect(fn(
'a; a,b, a\'s c a!; b,b, c.',
4,
Expand Down
2 changes: 1 addition & 1 deletion book/interview-questions/network-delay-time.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions book/interview-questions/sort-colors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ const { sortColors, sortColorsCompact } = require('./sort-colors');
expect(actual).toEqual(expected);
});

it('should work with small case', () => {
it('should work with small case1', () => {
const actual = [2, 1, 2];
fn(actual);
const expected = [1, 2, 2];
expect(actual).toEqual(expected);
});

it('should work with small case', () => {
it('should work with small case2', () => {
const actual = [1, 0, 2];
fn(actual);
const expected = [0, 1, 2];
expect(actual).toEqual(expected);
});

it('should work with small case', () => {
it('should work with small case3', () => {
const actual = [2, 0, 1];
fn(actual);
const expected = [0, 1, 2];
Expand Down
2 changes: 1 addition & 1 deletion src/data-structures/custom/lru-cache.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('LRU Cache', () => {
expect(c).toBeDefined();
});

it('should initialize', () => {
it('should initialize with capacity', () => {
c = new LRUCache(7);
expect(c.capacity).toEqual(7);
});
Expand Down
4 changes: 2 additions & 2 deletions src/data-structures/graphs/graph.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ describe('Graph', () => {
expect(graph.areConnected('you', 'barbara')).toBe(true);
});

it('should return true if two nodes are connected', () => {
it('should return true if two nodes are connected to itself', () => {
expect(graph.areConnected('you', 'you')).toBe(true);
});

it('should return true if two nodes are connected', () => {
it('should return true if two nodes are connected to other', () => {
expect(graph.areConnected('you', 'John')).toBe(false);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/data-structures/graphs/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Node (Graph)', () => {
expect(node.isAdjacent(b)).toBe(true);
});

it('should return true if they are adjacent', () => {
it('should return true if they are adjacent on c', () => {
const c = new Node('c');
expect(node.isAdjacent(c)).toBe(false);
});
Expand Down
6 changes: 3 additions & 3 deletions src/data-structures/heaps/median-heap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Median Heap', () => {
expect(medianHeap.size).toEqual(1);
});

it('should work', () => {
it('should work with 2 additions', () => {
expect(medianHeap.add(1)).toEqual(undefined);
expect(medianHeap.add(1)).toEqual(undefined);
expect(medianHeap.size).toEqual(2);
Expand All @@ -30,7 +30,7 @@ describe('Median Heap', () => {
expect(medianHeap.findMedian()).toEqual(10);
});

it('should work', () => {
it('should work with even numbers', () => {
const values = [5, 15, 1, 3];
const medians = values.map((v) => {
medianHeap.add(v);
Expand All @@ -39,7 +39,7 @@ describe('Median Heap', () => {
expect(medians).toEqual([5, 10, 5, 4]);
});

it('should work', () => {
it('should work with odd numbers', () => {
const values = [2, 4, 7, 1, 5, 3];
const medians = values.map((v) => {
medianHeap.add(v);
Expand Down
6 changes: 3 additions & 3 deletions src/data-structures/linked-lists/linked-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ describe('LinkedList Test', () => {
});

describe('#addFirst', () => {
it('add element to the head/root of the list', () => {
it('add 1 element to the head/root of the list', () => {
linkedList.addFirst('a');
expect(linkedList.first.value).toBe('a');
expect(linkedList.last.value).toBe('a');
});

it('add element to the head/root of the list', () => {
it('add 2 elements to the head/root of the list', () => {
linkedList.addFirst('a');
linkedList.addFirst('b');
expect(linkedList.first.value).toBe('b');
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('LinkedList Test', () => {
expect(linkedList.length).toBe(1);
});

it('should remove last element', () => {
it('should remove first element', () => {
expect(linkedList.length).toBe(2);
expect(linkedList.removeByPosition(0)).toBe(0);
expect(linkedList.length).toBe(1);
Expand Down
2 changes: 1 addition & 1 deletion src/data-structures/trees/binary-search-tree.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Binary Search Tree', () => {
expect(parent).toMatchObject({ value: 5 });
});

it('should find future parent of a node that doesnt exist yet', () => {
it('should find future parent of a node that doesnt exist yet with -1', () => {
bst.add(5);
bst.add(1);
const { found, parent } = bst.findNodeAndParent(-1);
Expand Down
4 changes: 2 additions & 2 deletions src/data-structures/trees/binary-tree-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ describe('Binary Tree Node', () => {
expect(p.uncle).toBe(null);
});

it('true if is parent left child', () => {
it('true if is parent left child for sibling', () => {
expect(s.isParentLeftChild).toBe(true);
expect(s.isParentRightChild).toBe(false);
});

it('true if is parent left child', () => {
it('true if is parent left child for child', () => {
expect(c.isParentLeftChild).toBe(false);
expect(c.isParentRightChild).toBe(true);
});
Expand Down

0 comments on commit 571834a

Please sign in to comment.