import { test } from 'node:test';
import assert from 'node:assert/strict';
import { compareRoomsEqual } from './utils';

// compareRoomsEqual(a, b): length mismatch short-circuits to false, otherwise an
// order-sensitive element-by-element equality. The React hook in the same file
// (useBindRoomsWithMembershipsAtom) is not covered.

test('two empty arrays are equal', () => {
  assert.equal(compareRoomsEqual([], []), true);
});

test('identical arrays are equal', () => {
  assert.equal(compareRoomsEqual(['a', 'b', 'c'], ['a', 'b', 'c']), true);
});

test('different lengths are not equal', () => {
  assert.equal(compareRoomsEqual(['a', 'b'], ['a', 'b', 'c']), false);
  assert.equal(compareRoomsEqual(['a'], []), false);
});

test('same elements in a different order are not equal (order-sensitive)', () => {
  assert.equal(compareRoomsEqual(['a', 'b'], ['b', 'a']), false);
});

test('a single differing element makes them unequal', () => {
  assert.equal(compareRoomsEqual(['a', 'b', 'c'], ['a', 'x', 'c']), false);
});

test('reference equality is not required, only value equality', () => {
  const a = ['a', 'b'];
  const b = ['a', 'b'];
  assert.notEqual(a, b);
  assert.equal(compareRoomsEqual(a, b), true);
});
