mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 07:01:18 +08:00
Add missing LinkedList tests (#151)
Co-authored-by: Oleksii Trekhleb <trehleb@gmail.com>
This commit is contained in:
parent
38b2b977cd
commit
07c21083d6
@ -218,6 +218,29 @@ describe('LinkedList', () => {
|
||||
expect(linkedList.find({ value: 2, customValue: 'test5' })).toBeNull();
|
||||
});
|
||||
|
||||
it('should find preferring callback over compare function', () => {
|
||||
const greaterThan = (value, compareTo) => (value > compareTo ? 0 : 1);
|
||||
|
||||
const linkedList = new LinkedList(greaterThan);
|
||||
linkedList.fromArray([1, 2, 3, 4, 5]);
|
||||
|
||||
let node = linkedList.find({ value: 3 });
|
||||
expect(node.value).toBe(4);
|
||||
|
||||
node = linkedList.find({ callback: value => value < 3 });
|
||||
expect(node.value).toBe(1);
|
||||
});
|
||||
|
||||
it('should convert to array', () => {
|
||||
const linkedList = new LinkedList();
|
||||
|
||||
linkedList.append(1);
|
||||
linkedList.append(2);
|
||||
linkedList.append(3);
|
||||
|
||||
expect(linkedList.toArray().join(',')).toBe('1,2,3');
|
||||
});
|
||||
|
||||
it('should reverse linked list', () => {
|
||||
const linkedList = new LinkedList();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user