Skip to content

Commit

Permalink
Added ParameterIdent.equals() and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdp committed Sep 11, 2023
1 parent b3ddec9 commit 049e366
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
13 changes: 12 additions & 1 deletion frontend/src/framework/EnsembleParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
}
}

Expand Down
19 changes: 19 additions & 0 deletions frontend/tests/unit-tests/EnsembleParameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 049e366

Please sign in to comment.