Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ofc fix #701

Merged
merged 10 commits into from
Dec 7, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public Instant getInstant() {

@Override
public UsageMethod getUsageMethod(State state) {
return state.getInstant().equals(instant) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED;
if (state.isPreventive()) {
return state.getInstant().equals(instant) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED;
} else {
return state.getInstant().equals(instant) && state.equals(this.angleCnec.getState()) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public Instant getInstant() {

@Override
public UsageMethod getUsageMethod(State state) {
return state.getInstant().equals(instant) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED;
if (state.isPreventive()) {
return state.getInstant().equals(instant) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED;
} else {
return state.getInstant().equals(instant) && state.equals(this.flowCnec.getState()) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public void setUp() {
angleCnec = Mockito.mock(AngleCnec.class);
preventiveState = Mockito.mock(State.class);
Mockito.when(preventiveState.getInstant()).thenReturn(Instant.PREVENTIVE);
Mockito.when(preventiveState.isPreventive()).thenReturn(true);
curativeState = Mockito.mock(State.class);
Mockito.when(curativeState.getInstant()).thenReturn(Instant.CURATIVE);
Mockito.when(curativeState.isPreventive()).thenReturn(false);
}

@Test
Expand Down Expand Up @@ -66,4 +68,22 @@ public void testEquals() {
assertNotEquals(onAngleConstraint1, onAngleConstraint2);
assertNotEquals(onAngleConstraint1.hashCode(), onAngleConstraint2.hashCode());
}

@Test
public void testGetUsageMethod() {
State curativeState2 = Mockito.mock(State.class);
Mockito.when(curativeState2.getInstant()).thenReturn(Instant.CURATIVE);
Mockito.when(curativeState2.isPreventive()).thenReturn(false);

OnAngleConstraint onAngleConstraint = new OnAngleConstraintImpl(Instant.PREVENTIVE, angleCnec);
assertEquals(UsageMethod.TO_BE_EVALUATED, onAngleConstraint.getUsageMethod(preventiveState));
assertEquals(UsageMethod.UNDEFINED, onAngleConstraint.getUsageMethod(curativeState));
assertEquals(UsageMethod.UNDEFINED, onAngleConstraint.getUsageMethod(curativeState2));

Mockito.when(angleCnec.getState()).thenReturn(curativeState);
onAngleConstraint = new OnAngleConstraintImpl(Instant.CURATIVE, angleCnec);
assertEquals(UsageMethod.UNDEFINED, onAngleConstraint.getUsageMethod(preventiveState));
assertEquals(UsageMethod.TO_BE_EVALUATED, onAngleConstraint.getUsageMethod(curativeState));
assertEquals(UsageMethod.UNDEFINED, onAngleConstraint.getUsageMethod(curativeState2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public void setUp() {
flowCnec = Mockito.mock(FlowCnec.class);
preventiveState = Mockito.mock(State.class);
Mockito.when(preventiveState.getInstant()).thenReturn(Instant.PREVENTIVE);
Mockito.when(preventiveState.isPreventive()).thenReturn(true);
curativeState = Mockito.mock(State.class);
Mockito.when(curativeState.getInstant()).thenReturn(Instant.CURATIVE);
Mockito.when(curativeState.isPreventive()).thenReturn(false);
}

@Test
Expand Down Expand Up @@ -66,4 +68,22 @@ public void testEquals() {
assertNotEquals(onFlowConstraint1, onFlowConstraint2);
assertNotEquals(onFlowConstraint1.hashCode(), onFlowConstraint2.hashCode());
}

@Test
public void testGetUsageMethod() {
State curativeState2 = Mockito.mock(State.class);
Mockito.when(curativeState2.getInstant()).thenReturn(Instant.CURATIVE);
Mockito.when(curativeState2.isPreventive()).thenReturn(false);

OnFlowConstraint onFlowConstraint = new OnFlowConstraintImpl(Instant.PREVENTIVE, flowCnec);
assertEquals(UsageMethod.TO_BE_EVALUATED, onFlowConstraint.getUsageMethod(preventiveState));
assertEquals(UsageMethod.UNDEFINED, onFlowConstraint.getUsageMethod(curativeState));
assertEquals(UsageMethod.UNDEFINED, onFlowConstraint.getUsageMethod(curativeState2));

Mockito.when(flowCnec.getState()).thenReturn(curativeState);
onFlowConstraint = new OnFlowConstraintImpl(Instant.CURATIVE, flowCnec);
assertEquals(UsageMethod.UNDEFINED, onFlowConstraint.getUsageMethod(preventiveState));
assertEquals(UsageMethod.TO_BE_EVALUATED, onFlowConstraint.getUsageMethod(curativeState));
assertEquals(UsageMethod.UNDEFINED, onFlowConstraint.getUsageMethod(curativeState2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ public void testIsRangeActionAvailableInState() {
assertFalse(CastorFullOptimization.isRangeActionAvailableInState(ra5, state1, crac));
assertTrue(CastorFullOptimization.isRangeActionAvailableInState(ra5, state2, crac));

// ra6 is available in preventive and in state1 and in state2
// ra6 is available in preventive and in state1
assertTrue(CastorFullOptimization.isRangeActionAvailableInState(ra6, crac.getPreventiveState(), crac));
assertTrue(CastorFullOptimization.isRangeActionAvailableInState(ra6, state1, crac));
assertTrue(CastorFullOptimization.isRangeActionAvailableInState(ra6, state2, crac));
assertFalse(CastorFullOptimization.isRangeActionAvailableInState(ra6, state2, crac));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ public void testGetLargestCnecThreshold() {

@Test
public void testIsOnFlowConstraintAvailable() {
State optimizedState = Mockito.mock(State.class);
when(optimizedState.getInstant()).thenReturn(Instant.CURATIVE);
State optimizedState = crac.getState("Contingency FR1 FR3", Instant.CURATIVE);

FlowCnec flowCnec = crac.getFlowCnec("cnec1stateCurativeContingency1");
FlowResult flowResult = mock(FlowResult.class);
Expand Down Expand Up @@ -217,7 +216,7 @@ public void testIsOnFlowConstraintAvailable() {
assertTrue(RaoUtil.isOnFlowConstraintAvailable(onFlowConstraint, optimizedState, flowResult));
assertTrue(RaoUtil.isRemedialActionAvailable(na2, optimizedState, flowResult, crac.getFlowCnecs(), network));

when(optimizedState.getInstant()).thenReturn(Instant.PREVENTIVE);
optimizedState = crac.getPreventiveState();
assertFalse(RaoUtil.isRemedialActionAvailable(na1, optimizedState, flowResult, crac.getFlowCnecs(), network));
assertFalse(RaoUtil.isOnFlowConstraintAvailable(onFlowConstraint, optimizedState, flowResult));
assertFalse(RaoUtil.isRemedialActionAvailable(na2, optimizedState, flowResult, crac.getFlowCnecs(), network));
Expand Down