import { it, assert, assertEq } from '../test.js' import RingBuffer from '/src/ring-buffer.js' const enqueue = (buf, xs) => { if (Array.isArray(xs)) { return xs.forEach(x => enqueue(buf, x)) } buf.enqueue(xs) } export default [ it('should enqueue and dequeue items', () => { const buf = RingBuffer(5) enqueue(buf, [0, 1, 2, 3, 4]) const result = buf.valueOf() assertEq(result, [0, 1, 2, 3, 4]) }), it('should wrap on overflow', () => { const buf = RingBuffer(5) enqueue(buf, [0, 1, 2, 3, 4, 5]) const result = buf.valueOf() assertEq(result, [1, 2, 3, 4, 5]) }), it('should be empty on clear', () => { const buf = RingBuffer(5) enqueue(buf, [0, 1, 2, 3, 4]) buf.clear() assert(buf.isEmpty(), 'buffer is not empty') assertEq(buf.size(), 0, 'buffer size is greater than 0') }) ]