Skip to content

Commit 07c2108

Browse files
mlegtrekhleb
andauthored
Add missing LinkedList tests (trekhleb#151)
Co-authored-by: Oleksii Trekhleb <[email protected]>
1 parent 38b2b97 commit 07c2108

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/data-structures/linked-list/__test__/LinkedList.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,29 @@ describe('LinkedList', () => {
218218
expect(linkedList.find({ value: 2, customValue: 'test5' })).toBeNull();
219219
});
220220

221+
it('should find preferring callback over compare function', () => {
222+
const greaterThan = (value, compareTo) => (value > compareTo ? 0 : 1);
223+
224+
const linkedList = new LinkedList(greaterThan);
225+
linkedList.fromArray([1, 2, 3, 4, 5]);
226+
227+
let node = linkedList.find({ value: 3 });
228+
expect(node.value).toBe(4);
229+
230+
node = linkedList.find({ callback: value => value < 3 });
231+
expect(node.value).toBe(1);
232+
});
233+
234+
it('should convert to array', () => {
235+
const linkedList = new LinkedList();
236+
237+
linkedList.append(1);
238+
linkedList.append(2);
239+
linkedList.append(3);
240+
241+
expect(linkedList.toArray().join(',')).toBe('1,2,3');
242+
});
243+
221244
it('should reverse linked list', () => {
222245
const linkedList = new LinkedList();
223246

0 commit comments

Comments
 (0)