Files
rk-frontend/src/lib/ioAddressSort.test.ts
T
2026-11-05 15:17:01 +01:00

21 lines
999 B
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
// @ts-ignore Direkte Ausführung mit Node Type-Stripping.
import { compareIoAddresses } from './ioAddressSort.ts';
test('sorts numerically by EA type, address byte and bit', () => {
const rows = [
{ adrType: 'AnalogOutput', adrByte: 0 },
{ adrType: 'DigitalInput', adrByte: 10, adrBit: 0 },
{ adrType: 'DigitalInput', adrByte: 2, adrBit: 7 },
{ adrType: 'AnalogInput', adrByte: 20 },
{ adrType: 'DigitalOutput', adrByte: 0, adrBit: 0 },
{ adrType: 'DigitalInput', adrByte: 2, adrBit: 0 },
{ adrType: 'AnalogInput', adrByte: 4 },
];
assert.deepEqual(rows.sort(compareIoAddresses).map(row => [row.adrType, row.adrByte, row.adrBit]), [
['DigitalInput', 2, 0], ['DigitalInput', 2, 7], ['DigitalInput', 10, 0],
['DigitalOutput', 0, 0], ['AnalogInput', 4, undefined], ['AnalogInput', 20, undefined], ['AnalogOutput', 0, undefined],
]);
});