diff --git a/src/Plate/utils.test.tsx b/src/Plate/utils.test.tsx index e6579a4d..6a7eefe9 100644 --- a/src/Plate/utils.test.tsx +++ b/src/Plate/utils.test.tsx @@ -10,6 +10,7 @@ import { columnForPosition, convertPositionFromColumnToRowFlow, convertPositionFromRowToColumnFlow, + coordinateSystemSize, ensureCoordinatesInRange, rowForPosition, } from './utils'; @@ -176,6 +177,13 @@ const COORDINATE_SYSTEM_2_BY_2 = { columns: [1, 2], } as const satisfies CoordinateSystem; +describe('coordinateSystemSize', () => { + it('returns the total number of positions in a coordinate system', () => { + expect(coordinateSystemSize(COORDINATE_SYSTEM_2_BY_2)).toBe(4); + expect(coordinateSystemSize(COORDINATE_SYSTEM_12X8)).toBe(96); + }); +}); + describe('allCoordinateSystemPositions', () => { it('returns an array of all positions in a coordinate systems', () => { expect(allCoordinateSystemPositions(COORDINATE_SYSTEM_2_BY_2)).toEqual([ diff --git a/src/Plate/utils.ts b/src/Plate/utils.ts index e50cfedf..08292a59 100644 --- a/src/Plate/utils.ts +++ b/src/Plate/utils.ts @@ -164,13 +164,16 @@ export function assertUniquePositions( } } +export function coordinateSystemSize( + coordinateSystem: CoordinateSystem, +): number { + return coordinateSystem.rows.length * coordinateSystem.columns.length; +} + export function allCoordinateSystemPositions( coordinateSystem: CoordinateSystem, ): Array { - return range( - 1, - coordinateSystem.rows.length * coordinateSystem.columns.length + 1, - ); + return range(1, coordinateSystemSize(coordinateSystem) + 1); } export function allCoordinateSystemCoordinates<