// Runnable self-check: `node --no-warnings src/utils/deviceFloor.check.ts`. // Covers the budget maths only — the RAM reading itself needs the device. import assert from 'node:assert'; import { canBurst, floorRaster, FLOOR_EXPORT_PIXELS, isFloorDevice, maxExportPixels, } from './deviceFloor.ts'; // Tier boundaries: unknown (0, the platform refused) is never a floor device, // and the 4 GB mid-range keeps the full path. assert.strictEqual(isFloorDevice(0), false, 'unknown RAM must keep full quality'); assert.strictEqual(isFloorDevice(1024), true, 'Redmi Go / Nokia 1 / J2 Core'); assert.strictEqual(isFloorDevice(2048), true, 'Go programme ceiling'); assert.strictEqual(isFloorDevice(3072), false); assert.strictEqual(isFloorDevice(12288), false, '12S Ultra'); // Caps follow the tier. assert.strictEqual(maxExportPixels(0), Infinity); assert.strictEqual(maxExportPixels(12288), Infinity); assert.strictEqual(maxExportPixels(1024), FLOOR_EXPORT_PIXELS); assert.strictEqual(canBurst(1024), false); assert.strictEqual(canBurst(0), true); // The floor device's own 3264x2448 (8 MP) capture, and the 12S Ultra's 3000x4000. const go = floorRaster(3264, 2448, FLOOR_EXPORT_PIXELS); assert.ok(go.width < 3264, 'floor capture is resampled'); assert.ok(go.width * go.height <= FLOOR_EXPORT_PIXELS, 'stays inside the cap'); assert.ok(go.width * go.height > FLOOR_EXPORT_PIXELS * 0.9, 'and does not overshoot it'); // Aspect is preserved to within a pixel on both orientations. assert.ok(Math.abs(go.width / go.height - 3264 / 2448) < 0.002, '4:3 kept'); const tall = floorRaster(3000, 4000, 4_000_000); assert.ok(Math.abs(tall.width / tall.height - 3000 / 4000) < 0.002, '3:4 kept'); // Untouched when it already fits, and never zero-sized on a degenerate raster. assert.deepStrictEqual(floorRaster(2000, 1500, FLOOR_EXPORT_PIXELS), { width: 2000, height: 1500 }); assert.deepStrictEqual(floorRaster(1, 1, FLOOR_EXPORT_PIXELS), { width: 1, height: 1 }); assert.deepStrictEqual(floorRaster(0, 0, 100), { width: 0, height: 0 }); console.log('deviceFloor.check: 17 assertions passed');