import { describe, expect, it } from 'vitest'; import { getWorkgroupCounts } from './get-workgroup-counts'; const makeDevice = (maxComputeWorkgroupsPerDimension: number): GPUDevice => ({ limits: { maxComputeWorkgroupsPerDimension, }, }) as GPUDevice; describe('getWorkgroupCounts', () => { it('returns at least one workgroup for positive invocation counts', () => { expect(getWorkgroupCounts(makeDevice(65_535), 1, 64)).toEqual([1, 1, 1]); expect(getWorkgroupCounts(makeDevice(65_535), 65, 64)).toEqual([2, 1, 1]); }); it('rejects zero and non-finite dispatch inputs', () => { const device = makeDevice(65_535); expect(() => getWorkgroupCounts(device, 0, 64)).toThrow(/positive finite/); expect(() => getWorkgroupCounts(device, -1, 64)).toThrow(/positive finite/); expect(() => getWorkgroupCounts(device, Number.POSITIVE_INFINITY, 64)).toThrow( /positive finite/ ); expect(() => getWorkgroupCounts(device, 1, 0)).toThrow(/positive finite/); }); it('rejects invocation counts that exceed device workgroup limits', () => { expect(() => getWorkgroupCounts(makeDevice(2), 9, 1)).toThrow( 'Cannot have this many invocations' ); }); });