Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
  • Loading branch information
jeandemanged committed Nov 15, 2024
1 parent 7ce32a1 commit 6c4e5aa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ private static boolean isValidContingencyTypeForIdentifiable(IdentifiableType id
if (elementType == ContingencyElementType.TWO_WINDINGS_TRANSFORMER && identifiableType == IdentifiableType.TWO_WINDINGS_TRANSFORMER) {
return true;
}
if (elementType == ContingencyElementType.TIE_LINE && identifiableType == IdentifiableType.TIE_LINE) {
return true;
}
if (elementType == ContingencyElementType.BRANCH && (identifiableType == IdentifiableType.LINE || identifiableType == IdentifiableType.TWO_WINDINGS_TRANSFORMER || identifiableType == IdentifiableType.TIE_LINE)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package com.powsybl.metrix.integration;

import com.google.common.collect.ImmutableList;
import com.powsybl.contingency.*;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.serde.NetworkSerDe;
Expand All @@ -20,6 +19,7 @@
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;

import static com.powsybl.metrix.mapping.LogDslLoader.LogType.WARNING;
Expand All @@ -28,7 +28,7 @@
/**
* @author Marianne Funfrock {@literal <marianne.funfrock at rte-france.com>}
*/
public class MetrixContingencyAnalysisTest {
class MetrixContingencyAnalysisTest {

private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("lang.MetrixAnalysis");

Expand Down Expand Up @@ -74,7 +74,7 @@ private void metrixDslDataContingencyAnalysisTest(MetrixDslData metrixDslData, S
}

private void loadContingencyTest(Contingency contingency, String expected) throws IOException {
ContingenciesProvider provider = network -> ImmutableList.of(contingency);
ContingenciesProvider provider = net -> List.of(contingency);

StringWriter writer = new StringWriter();
try (BufferedWriter bufferedWriter = new BufferedWriter(writer)) {
Expand Down Expand Up @@ -129,31 +129,31 @@ void loadContingencyWithWrongTypeForIdentifiableTest() throws IOException {
@Test
void metrixDslDataLoadContingencyAnalysisTest() throws IOException {
MetrixDslData metrixDslData = new MetrixDslData();
metrixDslData.addCurativeLoad("loadId", 10, ImmutableList.of("ctyForLoadId"));
metrixDslData.addCurativeLoad("loadId", 10, List.of("ctyForLoadId"));
String expected = getWarningInvalidMetrixDslDataContingency(" - loadId", "load", "ctyForLoadId");
metrixDslDataContingencyAnalysisTest(metrixDslData, expected);
}

@Test
void metrixDslDataPhaseTapChangerContingencyAnalysisTest() throws IOException {
MetrixDslData metrixDslData = new MetrixDslData();
metrixDslData.addPtc("phaseTapChangerId", MetrixPtcControlType.OPTIMIZED_ANGLE_CONTROL, ImmutableList.of("ctyForPhaseTapChangerId"));
metrixDslData.addPtc("phaseTapChangerId", MetrixPtcControlType.OPTIMIZED_ANGLE_CONTROL, List.of("ctyForPhaseTapChangerId"));
String expected = getWarningInvalidMetrixDslDataContingency(" - phaseTapChangerId", "phaseTapChanger", "ctyForPhaseTapChangerId");
metrixDslDataContingencyAnalysisTest(metrixDslData, expected);
}

@Test
void metrixDslDataGeneratorContingencyAnalysisTest() throws IOException {
MetrixDslData metrixDslData = new MetrixDslData();
metrixDslData.addGeneratorForRedispatching("generatorId", ImmutableList.of("ctyForGeneratorId"));
metrixDslData.addGeneratorForRedispatching("generatorId", List.of("ctyForGeneratorId"));
String expected = getWarningInvalidMetrixDslDataContingency(" - generatorId", "generator", "ctyForGeneratorId");
metrixDslDataContingencyAnalysisTest(metrixDslData, expected);
}

@Test
void metrixDslDataHvdcLineContingencyAnalysisTest() throws IOException {
MetrixDslData metrixDslData = new MetrixDslData();
metrixDslData.addHvdc("hvdcLineId", MetrixHvdcControlType.OPTIMIZED, ImmutableList.of("ctyForHvdcLineId"));
metrixDslData.addHvdc("hvdcLineId", MetrixHvdcControlType.OPTIMIZED, List.of("ctyForHvdcLineId"));
String expected = getWarningInvalidMetrixDslDataContingency(" - hvdcLineId", "hvdcLine", "ctyForHvdcLineId");
metrixDslDataContingencyAnalysisTest(metrixDslData, expected);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/*
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.metrix.integration;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.contingency.BranchContingency;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.contingency.Contingency;
import com.powsybl.contingency.*;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import com.powsybl.iidm.serde.ExportOptions;
Expand All @@ -17,7 +22,6 @@
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -63,15 +67,15 @@ void testNetworkElementsLists() {

// Contingencies
Contingency a = new Contingency("a", Collections.singletonList(new BranchContingency("LINE_S2S3")));
Contingency b = new Contingency("b", Arrays.asList(
Contingency b = new Contingency("b", List.of(
new BranchContingency("LINE_S2S3"),
new BranchContingency("LINE_S3S4")));

// Create a contingency provider
ContingenciesProvider contingenciesProvider = networkLocal -> {
a.addExtension(Probability.class, new Probability(0.002d, null));
b.addExtension(Probability.class, new Probability(null, "variable_ts1"));
return Arrays.asList(a, b);
return List.of(a, b);
};

// Initialize the MetrixNetwork
Expand Down Expand Up @@ -119,15 +123,19 @@ void testNetworkBusBreakerElementsLists() {

// Contingencies
Contingency a = new Contingency("a", Collections.singletonList(new BranchContingency("LINE_S2S3")));
Contingency b = new Contingency("b", Arrays.asList(
Contingency b = new Contingency("b", List.of(
new BranchContingency("LINE_S2S3"),
new BranchContingency("LINE_S3S4")));
Contingency c = new Contingency("c", Collections.singletonList(new DanglingLineContingency("DL")));
Contingency d = new Contingency("d", Collections.singletonList(new TieLineContingency("TL")));

// Create a contingency provider
ContingenciesProvider contingenciesProvider = networkLocal -> {
a.addExtension(Probability.class, new Probability(0.002d, null));
b.addExtension(Probability.class, new Probability(null, "variable_ts1"));
return Arrays.asList(a, b);
b.addExtension(Probability.class, new Probability(0.002d, null));
c.addExtension(Probability.class, new Probability(0.002d, null));
d.addExtension(Probability.class, new Probability(0.002d, null));
return List.of(a, b, c, d);
};

// Initialize the MetrixNetwork
Expand All @@ -146,7 +154,7 @@ void testNetworkBusBreakerElementsLists() {
assertThat(metrixNetwork.getTieLineList()).containsExactlyInAnyOrderElementsOf(network.getTieLines());
assertThat(metrixNetwork.getHvdcLineList()).containsExactlyInAnyOrderElementsOf(network.getHvdcLines());
assertThat(metrixNetwork.getBusList()).containsExactlyInAnyOrderElementsOf(network.getBusBreakerView().getBuses());
assertThat(metrixNetwork.getContingencyList()).containsExactlyInAnyOrderElementsOf(List.of(a, b));
assertThat(metrixNetwork.getContingencyList()).containsExactlyInAnyOrderElementsOf(List.of(a, b, c, d));
}

private Network createBusBreakerNetwork(Set<String> mappedSwitches) {
Expand Down

0 comments on commit 6c4e5aa

Please sign in to comment.