Skip to content

Commit

Permalink
adds some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CBiasuzzi committed Feb 2, 2018
1 parent 1cd14f7 commit d1c0fc1
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 5 deletions.
Expand Up @@ -191,8 +191,7 @@ public static boolean isInMainCc(Branch branch, boolean noswitch) {
* while Eurostag regulations to the cable-cable voltage
*/
public static float getHvdcLineDcVoltage(HvdcLine line) {
Objects.nonNull(line);
Objects.requireNonNull(line);
return line.getNominalV() * 2.0f;

}
}
Expand Up @@ -39,10 +39,11 @@ public void tearDown() throws Exception {
fileSystem.close();
}

private EurostagEchExportConfig getConfigFromFile(FileSystem fileSystem, boolean specificCompatibility) {
private EurostagEchExportConfig getConfigFromFile(FileSystem fileSystem, boolean specificCompatibility, boolean mainCcOnly) {
InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem);
MapModuleConfig moduleConfig = platformConfig.createModuleConfig("eurostag-ech-export");
moduleConfig.setStringProperty("svcAsFixedInjectionInLF", "false");
moduleConfig.setStringProperty("exportMainCCOnly", Boolean.toString(mainCcOnly));

moduleConfig = platformConfig.createModuleConfig("load-flow-default-parameters");
moduleConfig.setStringProperty("specificCompatibility", Boolean.toString(specificCompatibility));
Expand All @@ -59,15 +60,26 @@ public void testConfig() throws IOException {

@Test
public void testConfigFromFile() throws IOException {
EurostagEchExportConfig config = getConfigFromFile(fileSystem, false);
EurostagEchExportConfig config = getConfigFromFile(fileSystem, false, false);
assertEquals(false, config.isSvcAsFixedInjectionInLF());
}

@Test
public void testConfigSpecificCompatibility() throws IOException {
EurostagEchExportConfig config = getConfigFromFile(fileSystem, true);
EurostagEchExportConfig config = getConfigFromFile(fileSystem, true, false);
assertEquals(true, config.isSvcAsFixedInjectionInLF());
}

@Test
public void testConfigExportNoMainCC() throws IOException {
EurostagEchExportConfig config = getConfigFromFile(fileSystem, true, false);
assertEquals(false, config.isExportMainCCOnly());
}

@Test
public void testConfigExportMainCC() throws IOException {
EurostagEchExportConfig config = getConfigFromFile(fileSystem, true, true);
assertEquals(true, config.isExportMainCCOnly());
}

}
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2018, 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/.
*/
package eu.itesla_project.iidm.eurostag.export;

import com.google.common.collect.Lists;
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.commons.config.InMemoryPlatformConfig;
import com.powsybl.commons.config.MapModuleConfig;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.HvdcTestNetwork;
import org.junit.Before;
import org.junit.Test;

import java.nio.file.FileSystem;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


/**
* @author Christian Biasuzzi <christian.biasuzzi@techrain.it>
*/
public class EchUtilsTest {


private final float delta = 0.0f;
private Network network;
private Network networkHvdc;

@Before
public void setUp() throws Exception {
network = EurostagTutorialExample1Factory.create();
networkHvdc = HvdcTestNetwork.createVsc();
}

private EurostagEchExportConfig getConfig(boolean noSwitch, boolean exportMainCCOnly) {
FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem);
MapModuleConfig moduleConfig = platformConfig.createModuleConfig("eurostag-ech-export");
moduleConfig.setStringProperty("noSwitch", Boolean.toString(noSwitch));
moduleConfig.setStringProperty("exportMainCCOnly", Boolean.toString(exportMainCCOnly));
return EurostagEchExportConfig.load(platformConfig);
}

private EurostagEchExportConfig getConfig(boolean noSwitch) {
return getConfig(noSwitch, false);
}

@Test
public void testGetHvdcLineDcVoltage() {
networkHvdc.getHvdcLineStream().forEach(line -> assertEquals(line.getNominalV() * 2.0f, EchUtil.getHvdcLineDcVoltage(line), delta));
}

@Test
public void testGetHvdcLineDcVoltageNull() {
try {
EchUtil.getHvdcLineDcVoltage(null);
fail("Expected not null parameter");
} catch (NullPointerException e) {
}

}

@Test
public void testIsImMainCcBus() {
Lists.newArrayList(true, false).stream().forEach(exportMainCCOnly -> {
EchUtil.getBuses(networkHvdc, getConfig(false, exportMainCCOnly)).forEach(bus -> {
assertEquals(EchUtil.isInMainCc(bus), true);
});
});
}

@Test
public void testIsImMainCcGen() {
Lists.newArrayList(true, false).stream().forEach(exportMainCCOnly -> {
network.getGeneratorStream().forEach(gen -> {
assertEquals(EchUtil.isInMainCc(gen, exportMainCCOnly), true);
});
});
}

@Test
public void testIsImMainCcLine() {
Lists.newArrayList(true, false).stream().forEach(exportMainCCOnly -> {
network.getLines().forEach(line -> {
assertEquals(EchUtil.isInMainCc(line, exportMainCCOnly), true);
});
});
}

}
Expand Up @@ -7,6 +7,7 @@
package eu.itesla_project.iidm.eurostag.export;

import com.google.common.io.CharStreams;
import com.powsybl.iidm.network.test.HvdcTestNetwork;
import eu.itesla_project.eurostag.network.EsgGeneralParameters;
import eu.itesla_project.eurostag.network.EsgSpecialParameters;
import com.powsybl.iidm.network.Network;
Expand Down Expand Up @@ -55,4 +56,22 @@ public void testSVC() throws IOException {
EsgSpecialParameters specialParameters = new EsgSpecialParameters();
test(network, "/eurostag-svc-test.ech", LocalDate.parse("2016-01-01"), specialParameters);
}

@Test
public void testHVDC() throws IOException {
Network network = HvdcTestNetwork.createVsc();
network.getVoltageLevelStream().findFirst().orElse(null)
.newGenerator().setId("G1")
.setConnectableBus("B1")
.setBus("B1")
.setVoltageRegulatorOn(true)
.setTargetP(100.0F)
.setTargetV(400.0F)
.setMinP(50.0F)
.setMaxP(150.0F)
.add();
EsgSpecialParameters specialParameters = new EsgSpecialParameters();
test(network, "/eurostag-hvdc-test.ech", LocalDate.parse("2016-01-01"), specialParameters);
}

}
41 changes: 41 additions & 0 deletions eurostag-ech-export/src/test/resources/eurostag-hvdc-test.ech
@@ -0,0 +1,41 @@
HEADER 01/01/16 5.1

B

9 1 0 0 1 1 20 0.005 4 100. 1 1

SP INPVPQ 2
SP THMAX 0.100000
SP EMAXF 0.100000
SP ZMIN 0.000200
SP RAMIN 0.800000
SP RAMAX 1.200000
SP TOLPLO 0.001000

GC hvdctest/InitialState

AA FA
AA FR
DA DC

1FAFAKENOD1 380. 1. 0. 0. 0.
1FAFAKENOD2 380. 1. 0. 0. 0.
1FRB1 400. 1. 0. 0. 0.
5 B1 0.
1FRVL2_0 400. 1. 0. 0. 0.
1FRVL2_1 400. 1. 0. 0. 0.

6 VL2_0 VL2_1 1 0. 0.

G G1 Y B1 50. 100. 150. -2147483 21474836 V 400. B1 1. 0. 0.

DC N DC_C1 DC 800. 1.
DC N DC_C2 DC 800. 1.

DC L DC_C1 DC_C2 1 1.

DC V C1 DC_C1 GROUND B1 P Q 0. 16. 280. 800. -50. 1.
DC V -300. 300. 0. 10. 0. 0. 0.
DC V C2 DC_C2 GROUND VL2_1 V Q 0. 16. -280. 800. 123. 1.
DC V -300. 300. 0. 10. 0. 0. 0.

0 comments on commit d1c0fc1

Please sign in to comment.