testCommunitiesSplitWhatLinksLittle

tcmts.share.test.testCommunitiesSplitWhatLinksLittle · #x724et7y · function

two groups that reference each other within more than across are two communities

import { communities } from "#codebase/tcmts/share";
import assert from "node:assert/strict";

export const testCommunitiesSplitWhatLinksLittle = () => {
  const links: [number, number, number][] = [];
  for (const base of [0, 5])
    for (let a = 0; a < 5; a++) for (let b = a + 1; b < 5; b++) links.push([base + a, base + b, 1]);
  links.push([4, 5, 1]);
  const found = communities(10, links)
    .map((c) => c.sort((a, b) => a - b))
    .sort((a, b) => a[0]! - b[0]!);
  assert.deepEqual(found, [
    [0, 1, 2, 3, 4],
    [5, 6, 7, 8, 9],
  ]);
}

uses