Add force setting to MinCovered
This commit is contained in:
parent
dc124ace20
commit
0abd50ac0c
2 changed files with 21 additions and 4 deletions
|
|
@ -45,4 +45,16 @@ describe("CoveredValues", () => {
|
|||
covered.add(6);
|
||||
expect(covered.min).toBe(6);
|
||||
});
|
||||
|
||||
test("should handle force setting min value", () => {
|
||||
const covered = new CoveredValues(5);
|
||||
covered.add(7);
|
||||
covered.add(8);
|
||||
covered.add(9);
|
||||
expect(covered.min).toBe(5);
|
||||
covered.min = 6;
|
||||
expect(covered.min).toBe(6);
|
||||
covered.add(10);
|
||||
expect(covered.min).toBe(10);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,6 +18,15 @@ export class CoveredValues {
|
|||
|
||||
public constructor(private minValue: number) {}
|
||||
|
||||
public get min(): number {
|
||||
return this.minValue;
|
||||
}
|
||||
|
||||
public set min(value: number) {
|
||||
this.minValue = Math.max(value, this.minValue);
|
||||
this.seenValues = this.seenValues.filter((v) => v > value);
|
||||
}
|
||||
|
||||
public add(value: number): void {
|
||||
if (value < this.minValue) {
|
||||
return;
|
||||
|
|
@ -44,8 +53,4 @@ export class CoveredValues {
|
|||
this.minValue++;
|
||||
}
|
||||
}
|
||||
|
||||
public get min(): number {
|
||||
return this.minValue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue