This commit is contained in:
David Medina 2024-07-15 09:44:09 +10:00 committed by GitHub
commit ba0e21cfb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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) {