From dcec645f051cedb3e607cc93c0a6b8f748b1759e Mon Sep 17 00:00:00 2001 From: Revone Date: Sun, 20 Aug 2023 00:53:18 +0800 Subject: [PATCH] Integration test for SinglyLinkedList and DoublyLinkedList completed --- .../linked-list/doubly-linked-list.ts | 178 +++++++++++++++++- .../linked-list/singly-linked-list.ts | 165 ++++++++++++++-- .../linked-list/doubly-linked-list.test.ts | 12 +- .../linked-list/singly-linked-list.test.ts | 6 +- 4 files changed, 333 insertions(+), 28 deletions(-) diff --git a/src/data-structures/linked-list/doubly-linked-list.ts b/src/data-structures/linked-list/doubly-linked-list.ts index 0ec3b45..72435c6 100644 --- a/src/data-structures/linked-list/doubly-linked-list.ts +++ b/src/data-structures/linked-list/doubly-linked-list.ts @@ -5,8 +5,13 @@ * @copyright Copyright (c) 2022 Tyler Zeng * @license MIT License */ -export class DoublyLinkedListNode { +export class DoublyLinkedListNode { + /** + * The constructor function initializes the value, next, and previous properties of an object. + * @param {T} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it + * is defined as a generic type "T". + */ constructor(val: T) { this._val = val; this._next = null; @@ -46,6 +51,9 @@ export class DoublyLinkedListNode { export class DoublyLinkedList { + /** + * The constructor initializes the linked list with an empty head, tail, and length. + */ constructor() { this._head = null; this._tail = null; @@ -82,10 +90,28 @@ export class DoublyLinkedList { this._length = value; } + /** + * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the + * given array. + * @param {T[]} data - The `data` parameter is an array of elements of type `T`. + * @returns The `fromArray` function returns a DoublyLinkedList object. + */ + static fromArray(data: T[]) { + const doublyLinkedList = new DoublyLinkedList(); + for (const item of data) { + doublyLinkedList.push(item); + } + return doublyLinkedList; + } + getLength(): number { return this._length; } + /** + * The push function adds a new node with the given value to the end of the doubly linked list. + * @param {T} val - The value to be added to the linked list. + */ push(val: T): void { const newNode = new DoublyLinkedListNode(val); if (!this.head) { @@ -99,6 +125,11 @@ export class DoublyLinkedList { this.length++; } + /** + * The `pop()` function removes and returns the value of the last node in a doubly linked list. + * @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the + * list is empty, it returns null. + */ pop(): T | null { if (!this.tail) return null; const removedNode = this.tail; @@ -113,6 +144,11 @@ export class DoublyLinkedList { return removedNode.val; } + /** + * The `shift()` function removes and returns the value of the first node in a doubly linked list. + * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked + * list. + */ shift(): T | null { if (!this.head) return null; const removedNode = this.head; @@ -127,6 +163,11 @@ export class DoublyLinkedList { return removedNode.val; } + /** + * The unshift function adds a new node with the given value to the beginning of a doubly linked list. + * @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the + * doubly linked list. + */ unshift(val: T): void { const newNode = new DoublyLinkedListNode(val); if (!this.head) { @@ -140,7 +181,14 @@ export class DoublyLinkedList { this.length++; } - get(index: number): T | null { + /** + * The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds. + * @param {number} index - The index parameter is a number that represents the position of the element we want to + * retrieve from the list. + * @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds + * or the linked list is empty, it will return null. + */ + getAt(index: number): T | null { if (index < 0 || index >= this.length) return null; let current = this.head; for (let i = 0; i < index; i++) { @@ -149,6 +197,14 @@ export class DoublyLinkedList { return current!.val; } + /** + * The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of + * range. + * @param {number} index - The `index` parameter is a number that represents the position of the node we want to + * retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access. + * @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode` object if the index is within the + * valid range of the linked list, otherwise it returns `null`. + */ getNodeAt(index: number): DoublyLinkedListNode | null { if (index < 0 || index >= this.length) return null; let current = this.head; @@ -158,7 +214,14 @@ export class DoublyLinkedList { return current; } - findNodeByValue(val: T): DoublyLinkedListNode | null { + /** + * The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the + * node if found, otherwise it returns null. + * @param {T} val - The `val` parameter is the value that we want to search for in the doubly linked list. + * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode` if a node with the specified value `val` + * is found in the linked list. If no such node is found, it returns `null`. + */ + findNode(val: T): DoublyLinkedListNode | null { let current = this.head; while (current) { @@ -171,6 +234,15 @@ export class DoublyLinkedList { return null; } + /** + * The `insert` function inserts a value at a specified index in a doubly linked list. + * @param {number} index - The index parameter represents the position at which the new value should be inserted in the + * DoublyLinkedList. It is of type number. + * @param {T} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the + * specified index. + * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false` + * if the index is out of bounds. + */ insert(index: number, val: T): boolean { if (index < 0 || index > this.length) return false; if (index === 0) { @@ -193,6 +265,13 @@ export class DoublyLinkedList { return true; } + /** + * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element. + * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the + * data structure. It is of type number. + * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of + * bounds. + */ deleteAt(index: number): T | null { if (index < 0 || index >= this.length) return null; if (index === 0) return this.shift(); @@ -207,6 +286,12 @@ export class DoublyLinkedList { return removedNode!.val; } + /** + * The `delete` function removes a node with a specific value from a doubly linked list. + * @param {T} val - The `val` parameter represents the value that you want to delete from the linked list. + * @returns The `delete` method returns a boolean value. It returns `true` if the value `val` is found and deleted from + * the linked list, and `false` if the value is not found in the linked list. + */ delete(val: T): boolean { let current = this.head; while (current) { @@ -229,6 +314,10 @@ export class DoublyLinkedList { return false; } + /** + * The `toArray` function converts a linked list into an array. + * @returns The `toArray()` method is returning an array of type `T[]`. + */ toArray(): T[] { const array: T[] = []; let current = this.head; @@ -239,12 +328,22 @@ export class DoublyLinkedList { return array; } + /** + * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively. + */ clear(): void { this._head = null; this._tail = null; this._length = 0; } + /** + * The `find` function iterates through a linked list and returns the first element that satisfies a given condition. + * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This + * function is used to determine whether a particular value in the linked list satisfies a certain condition. + * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by + * the callback function. If no element satisfies the condition, it returns `null`. + */ find(callback: (val: T) => boolean): T | null { let current = this.head; while (current) { @@ -256,6 +355,13 @@ export class DoublyLinkedList { return null; } + /** + * The function returns the index of the first occurrence of a given value in a linked list. + * @param {T} val - The parameter `val` is of type `T`, which means it can be any data type. It represents the value + * that we are searching for in the linked list. + * @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked + * list. If the value is not found, it returns -1. + */ indexOf(val: T): number { let index = 0; let current = this.head; @@ -269,6 +375,14 @@ export class DoublyLinkedList { return -1; } + /** + * The `findLast` function iterates through a linked list from the last node to the first node and returns the last + * value that satisfies the given callback function, or null if no value satisfies the callback. + * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This + * function is used to determine whether a given value satisfies a certain condition. + * @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by + * the callback function. If no value satisfies the condition, it returns `null`. + */ findLast(callback: (val: T) => boolean): T | null { let current = this.tail; while (current) { @@ -280,6 +394,10 @@ export class DoublyLinkedList { return null; } + /** + * The `toArrayReverse` function converts a doubly linked list into an array in reverse order. + * @returns The `toArrayReverse()` function returns an array of type `T[]`. + */ toArrayReverse(): T[] { const array: T[] = []; let current = this.tail; @@ -290,6 +408,9 @@ export class DoublyLinkedList { return array; } + /** + * The `reverse` function reverses the order of the elements in a doubly linked list. + */ reverse(): void { let current = this.head; [this.head, this.tail] = [this.tail, this.head]; @@ -300,6 +421,12 @@ export class DoublyLinkedList { } } + /** + * The `forEach` function iterates over each element in a linked list and applies a callback function to each element. + * @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument + * represents the value of the current node in the linked list, and the index argument represents the index of the + * current node in the linked list. + */ forEach(callback: (val: T, index: number) => void): void { let current = this.head; let index = 0; @@ -310,6 +437,14 @@ export class DoublyLinkedList { } } + /** + * The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new + * DoublyLinkedList with the transformed values. + * @param callback - The callback parameter is a function that takes a value of type T (the type of values stored in + * the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped + * DoublyLinkedList). + * @returns The `map` function is returning a new instance of `DoublyLinkedList` that contains the mapped values. + */ map(callback: (val: T) => U): DoublyLinkedList { const mappedList = new DoublyLinkedList(); let current = this.head; @@ -320,6 +455,13 @@ export class DoublyLinkedList { return mappedList; } + /** + * The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the + * elements that satisfy the given callback function. + * @param callback - The `callback` parameter is a function that takes a value of type `T` and returns a boolean value. + * It is used to determine whether a value should be included in the filtered list or not. + * @returns The filtered list, which is an instance of the DoublyLinkedList class. + */ filter(callback: (val: T) => boolean): DoublyLinkedList { const filteredList = new DoublyLinkedList(); let current = this.head; @@ -332,6 +474,16 @@ export class DoublyLinkedList { return filteredList; } + /** + * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a + * single value. + * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is + * used to perform a specific operation on each element of the linked list. + * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting + * point for the reduction operation. + * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the + * elements in the linked list. + */ reduce(callback: (accumulator: U, val: T) => U, initialValue: U): U { let accumulator = initialValue; let current = this.head; @@ -342,8 +494,16 @@ export class DoublyLinkedList { return accumulator; } + /** + * The function inserts a new value after an existing value in a doubly linked list. + * @param {T} existingValue - The existing value is the value of the node after which we want to insert the new value. + * @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert after + * the existing node. + * @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the + * existing value is not found in the linked list. + */ insertAfter(existingValue: T, newValue: T): boolean { - const existingNode = this.findNodeByValue(existingValue); + const existingNode = this.findNode(existingValue); if (existingNode) { const newNode = new DoublyLinkedListNode(newValue); @@ -363,8 +523,16 @@ export class DoublyLinkedList { return false; } + /** + * The `insertBefore` function inserts a new value before an existing value in a doubly linked list. + * @param {T} existingValue - The existing value is the value of the node that you want to insert the new value before. + * @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert before + * the existing node. + * @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the + * existing value is not found in the linked list. + */ insertBefore(existingValue: T, newValue: T): boolean { - const existingNode = this.findNodeByValue(existingValue); + const existingNode = this.findNode(existingValue); if (existingNode) { const newNode = new DoublyLinkedListNode(newValue); diff --git a/src/data-structures/linked-list/singly-linked-list.ts b/src/data-structures/linked-list/singly-linked-list.ts index 2d5760c..1595df0 100644 --- a/src/data-structures/linked-list/singly-linked-list.ts +++ b/src/data-structures/linked-list/singly-linked-list.ts @@ -5,8 +5,13 @@ * @copyright Copyright (c) 2022 Tyler Zeng * @license MIT License */ -export class SinglyLinkedListNode { +export class SinglyLinkedListNode { + /** + * The constructor function initializes an instance of a class with a given value and sets the next property to null. + * @param {T} val - The "val" parameter is of type T, which means it can be any data type. It represents the value that + * will be stored in the node of a linked list. + */ constructor(val: T) { this._val = val; this._next = null; @@ -35,6 +40,9 @@ export class SinglyLinkedListNode { export class SinglyLinkedList { + /** + * The constructor initializes the linked list with an empty head, tail, and length. + */ constructor() { this._head = null; this._tail = null; @@ -71,10 +79,29 @@ export class SinglyLinkedList { this._length = value; } + /** + * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given + * array. + * @param {T[]} data - The `data` parameter is an array of elements of type `T`. + * @returns The `fromArray` function returns a `SinglyLinkedList` object. + */ + static fromArray(data: T[]) { + const singlyLinkedList = new SinglyLinkedList(); + for (const item of data) { + singlyLinkedList.push(item); + } + return singlyLinkedList; + } + getLength(): number { return this._length; } + /** + * The `push` function adds a new node with the given data to the end of a singly linked list. + * @param {T} data - The "data" parameter represents the value that you want to add to the linked list. It can be of + * any type (T) as specified in the generic type declaration of the class or function. + */ push(data: T): void { const newNode = new SinglyLinkedListNode(data); if (!this.head) { @@ -87,6 +114,12 @@ export class SinglyLinkedList { this.length++; } + /** + * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail + * pointers accordingly. + * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If + * the linked list is empty, it returns `null`. + */ pop(): T | null { if (!this.head) return null; if (this.head === this.tail) { @@ -108,6 +141,10 @@ export class SinglyLinkedList { return val; } + /** + * The `shift()` function removes and returns the value of the first node in a linked list. + * @returns The value of the node that is being removed from the beginning of the linked list. + */ shift(): T | null { if (!this.head) return null; const removedNode = this.head; @@ -116,6 +153,11 @@ export class SinglyLinkedList { return removedNode.val; } + /** + * The unshift function adds a new node with the given value to the beginning of a singly linked list. + * @param {T} val - The parameter "val" represents the value of the new node that will be added to the beginning of the + * linked list. + */ unshift(val: T): void { const newNode = new SinglyLinkedListNode(val); if (!this.head) { @@ -128,7 +170,14 @@ export class SinglyLinkedList { this.length++; } - get(index: number): T | null { + /** + * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range. + * @param {number} index - The index parameter is a number that represents the position of the element we want to + * retrieve from the list. + * @returns The method `getAt(index: number): T | null` returns the value at the specified index in the linked list, or + * `null` if the index is out of bounds. + */ + getAt(index: number): T | null { if (index < 0 || index >= this.length) return null; let current = this.head; for (let i = 0; i < index; i++) { @@ -137,18 +186,48 @@ export class SinglyLinkedList { return current!.val; } + /** + * The function `getNodeAt` returns the node at a given index in a singly linked list. + * @param {number} index - The `index` parameter is a number that represents the position of the node we want to + * retrieve from the linked list. It indicates the zero-based index of the node we want to access. + * @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode` object if the node at the + * specified index exists, or `null` if the index is out of bounds. + */ + getNodeAt(index: number): SinglyLinkedListNode | null { + let current = this.head; + for (let i = 0; i < index; i++) { + current = current!.next; + } + return current; + } + + /** + * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element. + * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the + * data structure. It is of type number. + * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of + * bounds. + */ deleteAt(index: number): T | null { if (index < 0 || index >= this.length) return null; if (index === 0) return this.shift(); if (index === this.length - 1) return this.pop(); - let prevNode = this.getNodeAt(index - 1); + const prevNode = this.getNodeAt(index - 1); const removedNode = prevNode!.next; prevNode!.next = removedNode!.next; this.length--; return removedNode!.val; } + /** + * The `delete` function removes a specified value from a linked list and returns true if the value was found and + * removed, otherwise it returns false. + * @param {T} value - The value parameter represents the value of the node that needs to be deleted from the linked + * list. + * @returns The `delete` method returns a boolean value. It returns `true` if the value was successfully deleted from + * the linked list, and `false` if the value was not found in the linked list. + */ delete(value: T): boolean { let current = this.head; let prev = null; @@ -176,14 +255,15 @@ export class SinglyLinkedList { return false; } - getNodeAt(index: number): SinglyLinkedListNode | null { - let current = this.head; - for (let i = 0; i < index; i++) { - current = current!.next; - } - return current; - } - + /** + * The `insert` function inserts a value at a specified index in a singly linked list. + * @param {number} index - The index parameter represents the position at which the new value should be inserted in the + * linked list. It is of type number. + * @param {T} val - The `val` parameter represents the value that you want to insert into the linked list at the + * specified index. + * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false` + * if the index is out of bounds. + */ insert(index: number, val: T): boolean { if (index < 0 || index > this.length) return false; if (index === 0) { @@ -203,16 +283,28 @@ export class SinglyLinkedList { return true; } + /** + * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating + * whether it is empty or not. + * @returns A boolean value indicating whether the length of the object is equal to 0. + */ isEmpty(): boolean { return this.length === 0; } + /** + * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively. + */ clear(): void { this._head = null; this._tail = null; this._length = 0; } + /** + * The `toArray` function converts a linked list into an array. + * @returns The `toArray()` method is returning an array of type `T[]`. + */ toArray(): T[] { const array: T[] = []; let current = this.head; @@ -223,6 +315,10 @@ export class SinglyLinkedList { return array; } + /** + * The `reverse` function reverses the order of the nodes in a singly linked list. + * @returns The reverse() method does not return anything. It has a return type of void. + */ reverse(): void { if (!this.head || this.head === this.tail) return; @@ -240,6 +336,13 @@ export class SinglyLinkedList { [this.head, this.tail] = [this.tail!, this.head!]; } + /** + * The `find` function iterates through a linked list and returns the first element that satisfies a given condition. + * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This + * function is used to determine whether a particular value in the linked list satisfies a certain condition. + * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by + * the callback function. If no element satisfies the condition, it returns `null`. + */ find(callback: (val: T) => boolean): T | null { let current = this.head; while (current) { @@ -251,7 +354,12 @@ export class SinglyLinkedList { return null; } - + /** + * The `indexOf` function returns the index of the first occurrence of a given value in a linked list. + * @param {T} value - The value parameter is the value that you want to find the index of in the linked list. + * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the + * value is not found, it returns -1. + */ indexOf(value: T): number { let index = 0; let current = this.head; @@ -267,7 +375,14 @@ export class SinglyLinkedList { return -1; } - findNodeByValue(value: T): SinglyLinkedListNode | null { + /** + * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns + * null. + * @param {T} value - The value parameter is the value that we want to search for in the linked list. + * @returns a `SinglyLinkedListNode` if a node with the specified value is found in the linked list. If no node with + * the specified value is found, the function returns `null`. + */ + findNode(value: T): SinglyLinkedListNode | null { let current = this.head; while (current) { @@ -280,6 +395,15 @@ export class SinglyLinkedList { return null; } + /** + * The `insertBefore` function inserts a new value before an existing value in a singly linked list. + * @param {T} existingValue - The existing value is the value that already exists in the linked list and before which + * we want to insert a new value. + * @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list. + * @returns The `insertBefore` function returns a boolean value. It returns `true` if the `newValue` is successfully + * inserted before the first occurrence of `existingValue` in the linked list. It returns `false` if the + * `existingValue` is not found in the linked list. + */ insertBefore(existingValue: T, newValue: T): boolean { if (!this.head) { return false; @@ -305,8 +429,16 @@ export class SinglyLinkedList { return false; } + /** + * The function inserts a new value after an existing value in a singly linked list. + * @param {T} existingValue - The existing value is the value of the node after which we want to insert the new value. + * @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list + * after the node with the `existingValue`. + * @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the + * existing value is not found in the linked list. + */ insertAfter(existingValue: T, newValue: T): boolean { - const existingNode = this.findNodeByValue(existingValue); + const existingNode = this.findNode(existingValue); if (existingNode) { const newNode = new SinglyLinkedListNode(newValue); @@ -322,6 +454,11 @@ export class SinglyLinkedList { return false; } + /** + * The function counts the number of occurrences of a given value in a linked list. + * @param {T} value - The value parameter is the value that you want to count the occurrences of in the linked list. + * @returns The count of occurrences of the given value in the linked list. + */ countOccurrences(value: T): number { let count = 0; let current = this.head; diff --git a/tests/unit/data-structures/linked-list/doubly-linked-list.test.ts b/tests/unit/data-structures/linked-list/doubly-linked-list.test.ts index ebdf20a..8a0b052 100644 --- a/tests/unit/data-structures/linked-list/doubly-linked-list.test.ts +++ b/tests/unit/data-structures/linked-list/doubly-linked-list.test.ts @@ -41,19 +41,19 @@ describe('DoublyLinkedList Operation Test', () => { // Inserting at the beginning list.insert(0, 0); expect(list.length).toBe(4); - expect(list.get(0)).toBe(0); - expect(list.get(1)).toBe(1); + expect(list.getAt(0)).toBe(0); + expect(list.getAt(1)).toBe(1); // Inserting in the middle list.insert(2, 1.5); expect(list.length).toBe(5); - expect(list.get(2)).toBe(1.5); - expect(list.get(3)).toBe(2); + expect(list.getAt(2)).toBe(1.5); + expect(list.getAt(3)).toBe(2); // Inserting at the end list.insert(5, 4); expect(list.length).toBe(6); - expect(list.get(5)).toBe(4); + expect(list.getAt(5)).toBe(4); expect(list.tail!.val).toBe(4); }); @@ -326,7 +326,7 @@ describe('DoublyLinkedList Operation Test', () => { const insertSuccess = objectList.insertBefore(obj2, newObj); expect(insertSuccess).toBe(true); - const findNode = objectList.findNodeByValue(newObj); // Use newObj instead of obj2 + const findNode = objectList.findNode(newObj); // Use newObj instead of obj2 expect(findNode?.val).toEqual(newObj); const deleted = objectList.delete(newObj); // Use newObj instead of obj2 diff --git a/tests/unit/data-structures/linked-list/singly-linked-list.test.ts b/tests/unit/data-structures/linked-list/singly-linked-list.test.ts index 90ea116..a46917d 100644 --- a/tests/unit/data-structures/linked-list/singly-linked-list.test.ts +++ b/tests/unit/data-structures/linked-list/singly-linked-list.test.ts @@ -59,13 +59,13 @@ describe('SinglyLinkedList Operation Test', () => { list.push(1); list.push(2); list.push(3); - const element = list.get(1); + const element = list.getAt(1); expect(element).toBe(2); }); it('should return undefined for an out-of-bounds index', () => { list.push(1); - const element = list.get(1); + const element = list.getAt(1); expect(element).toBeNull(); }); }); @@ -363,7 +363,7 @@ describe('SinglyLinkedList Operation Test', () => { const insertSuccess = objectList.insertBefore(obj2, newObj); expect(insertSuccess).toBe(true); - const findNode = objectList.findNodeByValue(newObj); // Use newObj instead of obj2 + const findNode = objectList.findNode(newObj); // Use newObj instead of obj2 expect(findNode?.val).toEqual(newObj); const deleted = objectList.delete(newObj); // Use newObj instead of obj2