From 049e3663dfde05df5dee0fcb28095a302a710db7 Mon Sep 17 00:00:00 2001 From: Sigurd Pettersen Date: Mon, 11 Sep 2023 10:40:20 +0200 Subject: [PATCH] Added ParameterIdent.equals() and unit tests --- frontend/src/framework/EnsembleParameters.ts | 13 ++++++++++++- .../unit-tests/EnsembleParameters.test.ts | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/frontend/src/framework/EnsembleParameters.ts b/frontend/src/framework/EnsembleParameters.ts index 6d868f905..6cd5c41e3 100644 --- a/frontend/src/framework/EnsembleParameters.ts +++ b/frontend/src/framework/EnsembleParameters.ts @@ -59,6 +59,17 @@ export class ParameterIdent { return this.name; } } + + equals(otherIdent: ParameterIdent | null): boolean { + if (!otherIdent) { + return false; + } + if (otherIdent === this) { + return true; + } + + return this.name === otherIdent.name && this.groupName === otherIdent.groupName; + } } export class EnsembleParameters { @@ -72,7 +83,7 @@ export class EnsembleParameters { const identArr: ParameterIdent[] = []; for (const par of this._parameterArr) { if (requiredParamType == null || par.type === requiredParamType) { - identArr.push({ name: par.name, groupName: par.groupName }); + identArr.push(new ParameterIdent(par.name, par.groupName)); } } diff --git a/frontend/tests/unit-tests/EnsembleParameters.test.ts b/frontend/tests/unit-tests/EnsembleParameters.test.ts index 0e16fd033..fb4c89b4d 100644 --- a/frontend/tests/unit-tests/EnsembleParameters.test.ts +++ b/frontend/tests/unit-tests/EnsembleParameters.test.ts @@ -97,3 +97,22 @@ describe("EnsembleParameters tests", () => { } }); }); + + +describe("ParameterIdent tests", () => { + test("Conversion to/from string", () => { + const ident = ParameterIdent.fromNameAndGroup("aName", "aGroup"); + const identStr = ident.toString(); + expect(ParameterIdent.fromString(identStr)).toEqual(ident); + }); + + test("Check for equality", () => { + const identA = new ParameterIdent("aName", "aGroup"); + const identB = new ParameterIdent("aName", "aGroup"); + const identC = new ParameterIdent("anotherName", "anotherGroup"); + expect(identA.equals(identA)).toBe(true); + expect(identA.equals(identB)).toBe(true); + expect(identA.equals(identC)).toBe(false); + expect(identA.equals(null)).toBe(false); + }); +});