import {describe, test, assert} from 'vitest';
import {BucketQueue} from '../../src/math/bucketQueue.js';

/**
 * Tests for the 'math/bucketQueue.js' file.
 */
/** @module tests/math */

describe('math', () => {

  /**
   * Tests for {@link BucketQueue}.
   *
   * @function module:tests/math~bucketqueue-class
   */
  test('BucketQueue class', () => {
    const queue00 = new BucketQueue();
    // isEmpty
    assert.equal(queue00.isEmpty(), true, 'create isEmpty');

    const itemEquals = function (rhs) {
      return rhs && rhs.a === this.a && rhs.b === this.b;
    };
    const item00 = {
      a: 0,
      b: 0,
      equals: itemEquals
    };

    // push
    queue00.push(item00);
    assert.equal(queue00.isEmpty(), false, 'push isEmpty');

    // pop
    const resItem02 = queue00.pop();
    assert.equal(queue00.isEmpty(), true, 'pop isEmpty');
    assert.ok(resItem02.equals(item00), 'pop item');

    // remove
    const item01 = {
      a: 0,
      b: 1,
      equals: itemEquals
    };
    queue00.push(item00);
    queue00.push(item01);
    assert.equal(queue00.remove(item00), true, 'remove');
    assert.equal(queue00.isEmpty(), false, 'remove isEmpty');
  });

});