Files
ocr_scanner/test/spec.test.js
T

57 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { KNOWN, emptySpec, normalizeToken, fingerprint, isUsable } from '../src/spec.js';
test('KNOWN enthaelt die erwarteten Wertelisten', () => {
assert.ok(KNOWN.capacityGb.includes(64));
assert.ok(KNOWN.speed.includes('PC4-2400'));
assert.ok(KNOWN.formFactor.includes('LRDIMM'));
assert.ok(KNOWN.rank.includes('4DRx4'));
});
test('emptySpec liefert alle Felder als null', () => {
assert.deepEqual(emptySpec(), {
capacityGb: null,
formFactor: null,
rank: null,
speed: null,
partNumber: null,
dateCode: null,
});
});
test('normalizeToken macht gross, trimmt und vereinheitlicht Bindestriche', () => {
assert.equal(normalizeToken(' pc42400 '), 'PC4-2400');
assert.equal(normalizeToken('4drx4'), '4DRX4');
assert.equal(normalizeToken(''), '');
assert.equal(normalizeToken(null), '');
});
test('fingerprint setzt die Felder in fester Reihenfolge zusammen', () => {
const spec = {
capacityGb: 64,
formFactor: 'LRDIMM',
rank: '4DRx4',
speed: 'PC4-2400',
partNumber: 'M386A8K40BM1-CRC4Y',
dateCode: '1908',
};
assert.equal(fingerprint(spec), 'LRDIMM|64|4DRX4|PC4-2400|M386A8K40BM1-CRC4Y');
});
test('fingerprint laesst den Datumscode aussen vor', () => {
const a = { capacityGb: 64, formFactor: 'LRDIMM', rank: '4DRx4', speed: 'PC4-2400', partNumber: 'X', dateCode: '1908' };
const b = { ...a, dateCode: '2013' };
assert.equal(fingerprint(a), fingerprint(b));
});
test('fingerprint markiert fehlende Felder mit einem Fragezeichen', () => {
const spec = { ...emptySpec(), capacityGb: 32 };
assert.equal(fingerprint(spec), '?|32|?|?|?');
});
test('isUsable verlangt eine Kapazitaet', () => {
assert.equal(isUsable({ ...emptySpec(), capacityGb: 64 }), true);
assert.equal(isUsable(emptySpec()), false);
});