mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
Compare commits
3 Commits
ba0e21cfb8
...
5a74d4a4c7
Author | SHA1 | Date | |
---|---|---|---|
|
5a74d4a4c7 | ||
|
e0de4bb37e | ||
|
9caf9ebaaa |
@ -1,4 +1,5 @@
|
||||
import LinkedList from '../LinkedList';
|
||||
import LinkedListNode from '../LinkedListNode';
|
||||
|
||||
describe('LinkedList', () => {
|
||||
it('should create empty linked list', () => {
|
||||
@ -207,6 +208,23 @@ describe('LinkedList', () => {
|
||||
expect(linkedList.toString()).toBe('1,1,2,3,3,3,4,5');
|
||||
});
|
||||
|
||||
it('should return a linked list node array', () => {
|
||||
const linkedList = new LinkedList();
|
||||
|
||||
expect(linkedList.head).toBeNull();
|
||||
expect(linkedList.tail).toBeNull();
|
||||
|
||||
linkedList.append(1);
|
||||
linkedList.append(2);
|
||||
|
||||
expect(linkedList.toArray().length).toBe(2);
|
||||
|
||||
const linkedListNode2 = new LinkedListNode(2);
|
||||
const linkedListNode1 = new LinkedListNode(1, linkedListNode2);
|
||||
|
||||
expect(linkedList.toArray()).toEqual([linkedListNode1, linkedListNode2]);
|
||||
});
|
||||
|
||||
it('should find node by means of custom compare function', () => {
|
||||
const comparatorFunction = (a, b) => {
|
||||
if (a.customValue === b.customValue) {
|
||||
|
Loading…
Reference in New Issue
Block a user