Add missing LinkedList tests (#151)

Co-authored-by: Oleksii Trekhleb <trehleb@gmail.com>
This commit is contained in:
Oleg Maslov 2020-12-17 11:36:00 +03:00 committed by GitHub
parent 38b2b977cd
commit 07c21083d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();