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

Add unit tests to test the breaking changes in README.md examples #6

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@



PowSyBl repository versions for the 1.3.0 powsybl-starter release correspond to the ones of
[powsybl-dependencies 1.3.0](https://github.com/powsybl/powsybl-dependencies/releases/tag/v1.3.0).
PowSyBl repository versions for the 2.0.0 powsybl-starter release correspond to the ones of
[powsybl-dependencies 2.0.0](https://github.com/powsybl/powsybl-dependencies/releases/tag/v2.0.0).



Expand All @@ -15,7 +15,7 @@ To start using PowSyBl components in a Maven project, you just have to include o
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-starter</artifactId>
<version>1.3.0</version>
<version>2.0.0</version>
</dependency>
```

Expand Down Expand Up @@ -50,7 +50,7 @@ LoadFlow.run(network, parameters);
Load a PSS/E raw file, run an AC load flow and generate a single line diagram for voltage level 'VL8':

```java
Network network = Importers.loadNetwork("IEEE_118_bus.raw");
Network network = Network.read("IEEE_118_bus.raw");
LoadFlow.run(network);
SingleLineDiagram.draw(network, "VL8", "vl8.svg");
```
Expand All @@ -60,7 +60,7 @@ SingleLineDiagram.draw(network, "VL8", "vl8.svg");
Load a UCTE file, run an AC load flow and generate a full network diagram:

```java
Network network = Importers.loadNetwork("simple-eu.uct");
Network network = Network.read("simple-eu.uct");
LoadFlow.run(network);
new NetworkAreaDiagram(network).draw(Paths.get("simple-eu.svg"));
```
Expand All @@ -70,7 +70,7 @@ new NetworkAreaDiagram(network).draw(Paths.get("simple-eu.svg"));
Load a UCTE file, run an AC security analysis with all N-1 line contingencies:

```java
Network network = Importers.loadNetwork("simple-eu.uct");
Network network = Network.read("simple-eu.uct");
List<Contingency> contingencies = network.getLineStream().map(l -> Contingency.line(l.getId())).collect(Collectors.toList());
SecurityAnalysisResult result = SecurityAnalysis.run(network, contingencies).getResult();
```
Expand All @@ -80,8 +80,8 @@ SecurityAnalysisResult result = SecurityAnalysis.run(network, contingencies).get
Load 2 CGMES files, merge both networks and run a load flow on merged network:

```java
Network networkBe = Importers.loadNetwork("CGMES_v2_4_15_MicroGridTestConfiguration_BC_BE_v2.zip");
Network networkNl = Importers.loadNetwork("CGMES_v2_4_15_MicroGridTestConfiguration_BC_NL_v2.zip");
Network networkBe = Network.read("CGMES_v2_4_15_MicroGridTestConfiguration_BC_BE_v2.zip");
Network networkNl = Network.read("CGMES_v2_4_15_MicroGridTestConfiguration_BC_NL_v2.zip");
networkBe.merge(networkNl);
LoadFlow.run(networkBe);
```
Expand All @@ -91,7 +91,7 @@ LoadFlow.run(networkBe);
Load a UCTE file and run a DC sensivity analysis of all generators active power injection on all branches active power flow for the pre-contingency state and for all N-1 line post-contingency states.

```java
Network network = Importers.loadNetwork("simple-eu.uct");
Network network = Network.read("simple-eu.uct");
List<SensitivityFactor> factors = new ArrayList<>();
for (Generator g : network.getGenerators()) {
for (Line l : network.getLines()) {
Expand Down
14 changes: 11 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-parent</artifactId>
<version>8</version>
<version>9</version>
<relativePath/>
</parent>

<artifactId>powsybl-starter</artifactId>
<version>1.4.0-SNAPSHOT</version>
<version>2.0.0</version>

<name>PowSyBl Starter POM</name>
<description>A starter POM to help creating a PowSyBl based application faster</description>
Expand All @@ -42,7 +42,8 @@
</developers>

<properties>
<powsybl-dependencies.version>1.3.0</powsybl-dependencies.version>
<powsybl-dependencies.version>2.0.0</powsybl-dependencies.version>
<junit-jupiter.version>5.9.0</junit-jupiter.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -143,5 +144,12 @@
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
88 changes: 88 additions & 0 deletions src/test/java/com/powsybl/starter/ReadmeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.powsybl.starter;

import com.powsybl.contingency.Contingency;
import com.powsybl.contingency.ContingencyContext;
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Line;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.nad.NetworkAreaDiagram;
import com.powsybl.security.SecurityAnalysis;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.sensitivity.*;
import com.powsybl.sld.SingleLineDiagram;
import org.junit.jupiter.api.Test;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

class ReadmeTest {

@Test
void testExample1() {
Network network = IeeeCdfNetworkFactory.create14();
LoadFlowResult result = LoadFlow.run(network);
System.out.println(result.getComponentResults().get(0).getStatus());
network.getBusView().getBusStream().forEach(bus -> System.out.println(bus.getId() + " " + bus.getV()));
}

@Test
void testExample2() {
Network network = IeeeCdfNetworkFactory.create14();
LoadFlowParameters parameters = new LoadFlowParameters()
.setDc(true);
LoadFlow.run(network, parameters);
}

@Test
void testExample3() {
Network network = Network.read("IEEE_118_bus.raw", getClass().getResourceAsStream("/IEEE_118_bus.raw"));
LoadFlow.run(network);
SingleLineDiagram.draw(network, "VL7", "vl8.svg");
}

@Test
void testExample4() {
Network network = Network.read("simple-eu.uct", getClass().getResourceAsStream("/simple-eu.uct"));
LoadFlow.run(network);
new NetworkAreaDiagram(network).draw(Paths.get("simple-eu.svg"));
}

@Test
void testExample5() {
Network network = Network.read("simple-eu.uct", getClass().getResourceAsStream("/simple-eu.uct"));
List<Contingency> contingencies = network.getLineStream().map(l -> Contingency.line(l.getId())).collect(Collectors.toList());
SecurityAnalysisResult result = SecurityAnalysis.run(network, contingencies).getResult();
}

@Test
void testExample6() {
Network networkBe = Network.read("src/test/resources/CGMES_v2_4_15_MicroGridTestConfiguration_BC_BE_v2.zip");
Network networkNl = Network.read("src/test/resources/CGMES_v2_4_15_MicroGridTestConfiguration_BC_NL_v2.zip");
networkNl.merge(networkBe);
LoadFlow.run(networkBe);
}

@Test
void testExample7() {
Network network = Network.read("simple-eu.uct", getClass().getResourceAsStream("/simple-eu.uct"));
List<SensitivityFactor> factors = new ArrayList<>();
for (Generator g : network.getGenerators()) {
for (Line l : network.getLines()) {
factors.add(new SensitivityFactor(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, l.getId(),
SensitivityVariableType.INJECTION_ACTIVE_POWER, g.getId(),
false, ContingencyContext.all()));
}
}
List<Contingency> contingencies = network.getLineStream().map(l -> Contingency.line(l.getId())).collect(Collectors.toList());
SensitivityAnalysisParameters parameters = new SensitivityAnalysisParameters();
parameters.getLoadFlowParameters().setDc(true);
SensitivityAnalysisResult result = SensitivityAnalysis.run(network, factors, contingencies, parameters);
}

}
Binary file not shown.
Binary file not shown.
Loading