forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: Refactor Code and Add test case (TheAlgorithms#845)
- Loading branch information
1 parent
2ae00a9
commit 4aac366
Showing
2 changed files
with
67 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Queue } from '../Queue' | ||
|
||
describe('Queue', () => { | ||
it('Check enqueue/dequeue', () => { | ||
const queue = new Queue() | ||
queue.enqueue(1) | ||
queue.enqueue(2) | ||
queue.enqueue(8) | ||
queue.enqueue(9) | ||
|
||
expect(queue.dequeue()).toBe(1) | ||
expect(queue.dequeue()).toBe(2) | ||
}) | ||
|
||
it('Check length', () => { | ||
const queue = new Queue() | ||
|
||
queue.enqueue(1) | ||
queue.enqueue(2) | ||
queue.enqueue(8) | ||
queue.enqueue(9) | ||
|
||
expect(queue.length()).toBe(4) | ||
}) | ||
|
||
it('Check peek', () => { | ||
const queue = new Queue() | ||
|
||
queue.enqueue(1) | ||
queue.enqueue(2) | ||
queue.enqueue(8) | ||
queue.enqueue(9) | ||
|
||
expect(queue.peek()).toBe(1) | ||
}) | ||
|
||
it('Check empty', () => { | ||
const queue = new Queue() | ||
expect(queue.empty()).toBeTruthy() | ||
|
||
queue.enqueue(1) | ||
queue.enqueue(2) | ||
queue.enqueue(8) | ||
queue.enqueue(9) | ||
|
||
expect(queue.empty()).toBeFalsy() | ||
}) | ||
}) |