Skip to content

Commit

Permalink
fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
clarani committed Jul 10, 2024
1 parent 4e67a78 commit 92c4baa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
15 changes: 10 additions & 5 deletions front/src/modules/powerRestriction/helpers/__tests__/sampleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,17 @@ export const formattedPowerRestrictionRanges: Omit<SimulationPowerRestrictionRan
export const powerRestrictionRanges: Omit<SimulationPowerRestrictionRange, 'handled'>[] = [
{
start: 0,
stop: 1000,
stop: 1,
code: 'code1',
},
{
start: 2000,
stop: 3000,
start: 2,
stop: 3,
code: 'code2',
},
{
start: 3000,
stop: 4000,
start: 3,
stop: 4,
code: 'code1',
},
];
Expand All @@ -476,6 +476,11 @@ export const voltageRangesForPowerRestrictions: RangedValue[] = [
end: 2000,
value: '1500V',
},
{
begin: 2000,
end: 3000,
value: '',
},
{
begin: 3000,
end: 4000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,24 @@ export const addHandledToPowerRestrictions = (

// find all the voltage ranges which overlap the powerRestrictionRange
voltageRanges.forEach((voltageRange) => {
const voltageBeginIsInRange =
powerRestrictionBeginInMm <= voltageRange.begin &&
voltageRange.begin <= powerRestrictionEndInMm;
const voltageEndIsInRange =
powerRestrictionBeginInMm <= voltageRange.end &&
voltageRange.end <= powerRestrictionEndInMm;
const restrictionBeginIsInRange =
voltageRange.begin <= powerRestrictionBeginInMm &&
powerRestrictionBeginInMm < voltageRange.end;
const restrictionEndIsInRange =
voltageRange.begin < powerRestrictionEndInMm && powerRestrictionEndInMm <= voltageRange.end;

if (voltageBeginIsInRange || voltageEndIsInRange) {
if (restrictionBeginIsInRange || restrictionEndIsInRange) {
const powerRestrictionForVoltage = powerRestrictionsByMode[voltageRange.value];
const isHandled =
powerRestrictionForVoltage &&
!!powerRestrictionForVoltage &&
powerRestrictionForVoltage.includes(powerRestrictionRange.code);

// add the restriction corresponding to the voltage range
restrictionsWithHandled.push({
start: voltageBeginIsInRange ? mmToM(voltageRange.begin) : powerRestrictionRange.start,
stop: voltageEndIsInRange ? mmToM(voltageRange.end) : powerRestrictionRange.stop,
start: restrictionBeginIsInRange
? powerRestrictionRange.start
: mmToM(voltageRange.begin),
stop: restrictionEndIsInRange ? powerRestrictionRange.stop : mmToM(voltageRange.end),
code: powerRestrictionRange.code,
handled: isHandled,
});
Expand Down

0 comments on commit 92c4baa

Please sign in to comment.