/** * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import LinkedIndex from '../linked-index' describe('linked-index', () => { it('initial state', () => { const index = LinkedIndex(2); expect(index.head).toBe(0); expect(index.has(0)).toBe(true); expect(index.has(1)).toBe(true); }); it('singleton', () => { const index = LinkedIndex(1); expect(index.head).toBe(0); expect(index.has(0)).toBe(true); index.remove(0); expect(index.head).toBe(-1); expect(index.has(0)).toBe(false); }); it('remove 0', () => { const index = LinkedIndex(2); index.remove(0); expect(index.head).toBe(1); expect(index.has(0)).toBe(false); expect(index.has(1)).toBe(true); }); it('remove 1', () => { const index = LinkedIndex(2); index.remove(1); expect(index.head).toBe(0); expect(index.has(0)).toBe(true); expect(index.has(1)).toBe(false); }); it('remove 01', () => { const index = LinkedIndex(2); index.remove(0); index.remove(1); expect(index.head).toBe(-1); expect(index.has(0)).toBe(false); expect(index.has(1)).toBe(false); }); });