mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
Merge e0de4bb37e
into ca3d16dcce
This commit is contained in:
commit
ba0e21cfb8
@ -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