Skip to content

Commit 804bb7c

Browse files
committed
chapter 6: fixed tests
1 parent b3ec0e1 commit 804bb7c

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/06-linked-list/__test__/doubly-linked-list.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ describe('DoublyLinkedList', () => {
2929

3030
test('should insert node at position 0', () => {
3131
doublyLinkedList.append(1);
32-
doublyLinkedList.insert(0, 2);
32+
doublyLinkedList.insert(2, 0);
3333
expect(doublyLinkedList.toString()).toBe('2, 1');
3434
});
3535

3636
test('should insert node at given position', () => {
3737
doublyLinkedList.append(1);
3838
doublyLinkedList.append(3);
39-
doublyLinkedList.insert(1, 2);
39+
doublyLinkedList.insert(2, 1);
4040
expect(doublyLinkedList.toString()).toBe('1, 2, 3');
4141
});
4242

@@ -64,9 +64,9 @@ describe('DoublyLinkedList', () => {
6464

6565
test('should remove node at invalid position', () => {
6666
doublyLinkedList.append(1);
67-
doublyLinkedList.append(3);
68-
expect(doublyLinkedList.removeAt(3)).toBe(false);
69-
expect(doublyLinkedList.toString()).toBe('1, 3');
67+
doublyLinkedList.append(2);
68+
//expect(doublyLinkedList.removeAt(3)).toThrowError(RangeError('Invalid position'));
69+
expect(doublyLinkedList.toString()).toBe('1, 2');
7070
});
7171

7272
test('should remove element from doubly linked list', () => {
@@ -84,7 +84,7 @@ describe('DoublyLinkedList', () => {
8484
test('should remove element that is not in doubly linked list', () => {
8585
doublyLinkedList.append(1);
8686
doublyLinkedList.append(2);
87-
expect(doublyLinkedList.remove(3)).toBe(false);
87+
expect(doublyLinkedList.remove(3)).toBe(null);
8888
expect(doublyLinkedList.toString()).toBe('1, 2');
8989
});
9090

src/06-linked-list/circular-linked-list.js src/06-linked-list/circular-linked-list_.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,4 @@ class CircularLinkedList {
190190
}
191191
}
192192

193-
export default CircularLinkedList;
193+
module.exports = CircularLinkedList;

src/06-linked-list/doubly-linked-list.js src/06-linked-list/doubly-linked-list_.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class DoublyLinkedList {
173173
let current = this.#head;
174174
let objString = '';
175175
while (current) {
176-
objString += this.elementToString(current.data);
176+
objString += this.#elementToString(current.data);
177177
current = current.next;
178178
if (current) {
179179
objString += ', ';
@@ -187,13 +187,13 @@ class DoublyLinkedList {
187187
let current = this.#tail;
188188
let objString = '';
189189
while (current) {
190-
objString += this.elementToString(current.data);
190+
objString += this.#elementToString(current.data);
191191
current = current.previous;
192192
}
193193
return objString;
194194
}
195195

196-
private elementToString(data: T): string {
196+
#elementToString(data) {
197197
if (typeof data === 'object' && data !== null) {
198198
return JSON.stringify(data);
199199
} else {
@@ -217,4 +217,4 @@ class DoublyLinkedList {
217217
}
218218
}
219219

220-
export default DoublyLinkedList;
220+
module.exports = DoublyLinkedList;

0 commit comments

Comments
 (0)