Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 6 additions & 6 deletions
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‎ renamed to ‎src/06-linked-list/circular-linked-list_.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,4 @@ class CircularLinkedList {
190190
}
191191
}
192192

193-
exportdefault CircularLinkedList;
193+
module.exports= CircularLinkedList;

‎src/06-linked-list/doubly-linked-list.js‎ renamed to ‎src/06-linked-list/doubly-linked-list_.js‎

Lines changed: 4 additions & 4 deletions
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-
privateelementToString(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-
exportdefault DoublyLinkedList;
220+
module.exports= DoublyLinkedList;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /