From 81459fa2dfa5a1f29eb84bf8562b9d3ff9d9a38b Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Tue, 7 Sep 2021 16:48:32 +0300 Subject: [PATCH] fix: more accurate types --- src/odometer/Odometer.ts | 13 +++++++------ src/odometer/OdometerStats.ts | 7 ++++--- src/odometer/__tests__/Odometer.test.ts | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 src/odometer/__tests__/Odometer.test.ts diff --git a/src/odometer/Odometer.ts b/src/odometer/Odometer.ts index 4548f3b..e6302c0 100644 --- a/src/odometer/Odometer.ts +++ b/src/odometer/Odometer.ts @@ -1,16 +1,17 @@ +import { Replacement } from '../multireplacer'; import { Intermediate } from '../utils'; import { getEditingDistance } from './utils/getEditingDistance'; import { OdometerStats } from './OdometerStats'; -export class Odometer { +export class Odometer { public getDifference( - aSet: Intermediate[], - bSet: Intermediate[], - ): OdometerStats { + aSet: Intermediate>[], + bSet: Intermediate>[], + ): OdometerStats { let minimalDistance = Number.POSITIVE_INFINITY; - let aBest: Intermediate | null = null; - let bBest: Intermediate | null = null; + let aBest: Intermediate> | null = null; + let bBest: Intermediate> | null = null; for (const aRaw of aSet) { const a = aRaw.value.toLowerCase(); diff --git a/src/odometer/OdometerStats.ts b/src/odometer/OdometerStats.ts index 47f542a..6f66636 100644 --- a/src/odometer/OdometerStats.ts +++ b/src/odometer/OdometerStats.ts @@ -1,7 +1,8 @@ +import { Replacement } from '../multireplacer'; import { Intermediate } from '../utils'; -export type OdometerStats = { - a: Intermediate | null; - b: Intermediate | null; +export type OdometerStats = { + a: Intermediate> | null; + b: Intermediate> | null; distance: number; }; diff --git a/src/odometer/__tests__/Odometer.test.ts b/src/odometer/__tests__/Odometer.test.ts new file mode 100644 index 0000000..e7078fa --- /dev/null +++ b/src/odometer/__tests__/Odometer.test.ts @@ -0,0 +1,21 @@ +import { Odometer } from '../Odometer'; +import { Intermediate } from '../../utils'; +import { Replacement } from '../../multireplacer'; + +describe('Odometer', () => { + test('integration', () => { + const odometer = new Odometer(); + + const [a1, a2, b1, b2] = ['morje', 'måre', 'mare', 'miare'].map( + (s) => new Intermediate>(s, null), + ); + + const result = odometer.getDifference([a1, a2], [b1, b2]); + + expect(result).toEqual({ + a: a2, + b: b1, + distance: 0.125, + }); + }); +});