From ee6d2e30c3f3d734b2b872cd2bbc405c1b939024 Mon Sep 17 00:00:00 2001 From: Olivier Perrin Date: Thu, 19 Oct 2023 14:55:02 +0200 Subject: [PATCH] Add unit test Signed-off-by: Olivier Perrin --- .../output/ReactiveSlackOutputTest.java | 47 +++++++++++++++++++ .../reactiveopf_results_reactive_slacks.csv | 3 ++ 2 files changed, 50 insertions(+) create mode 100644 open-reac/src/test/java/com/powsybl/openreac/parameters/output/ReactiveSlackOutputTest.java create mode 100644 open-reac/src/test/resources/mock_outputs/reactiveopf_results_reactive_slacks.csv diff --git a/open-reac/src/test/java/com/powsybl/openreac/parameters/output/ReactiveSlackOutputTest.java b/open-reac/src/test/java/com/powsybl/openreac/parameters/output/ReactiveSlackOutputTest.java new file mode 100644 index 00000000..9ddf7b22 --- /dev/null +++ b/open-reac/src/test/java/com/powsybl/openreac/parameters/output/ReactiveSlackOutputTest.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2023, 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.openreac.parameters.output; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * @author Olivier Perrin {@literal } + */ +class ReactiveSlackOutputTest { + + @Test + void readTest() throws IOException { + ReactiveSlackOutput output = new ReactiveSlackOutput(); + try (InputStream input = getClass().getResourceAsStream("/mock_outputs/reactiveopf_results_reactive_slacks.csv"); + InputStreamReader in = new InputStreamReader(input); + BufferedReader reader = new BufferedReader(in)) { + + output.read(reader, null); + assertEquals(2, output.getSlacks().size()); + ReactiveSlackOutput.ReactiveSlack slack1 = output.getSlacks().get(0); + ReactiveSlackOutput.ReactiveSlack slack2 = output.getSlacks().get(1); + Assertions.assertAll( + () -> assertEquals(1.6, slack1.getSlack(), 0.01), + () -> assertEquals("slack1", slack1.getBusId()), + () -> assertEquals("voltageLevel1", slack1.getVoltageLevelId()), + () -> assertEquals(Double.NaN, slack2.getSlack()), + () -> assertEquals("slack2", slack2.getBusId()), + () -> assertEquals("voltageLevel2", slack2.getVoltageLevelId()) + ); + } + } + +} diff --git a/open-reac/src/test/resources/mock_outputs/reactiveopf_results_reactive_slacks.csv b/open-reac/src/test/resources/mock_outputs/reactiveopf_results_reactive_slacks.csv new file mode 100644 index 00000000..9eb06f5f --- /dev/null +++ b/open-reac/src/test/resources/mock_outputs/reactiveopf_results_reactive_slacks.csv @@ -0,0 +1,3 @@ +col1;col2;col3;col4;col5;col6; +'a1';'b1';5.3;6.9;'slack1';'voltageLevel1'; +'a2';'b2';1.2;-99999;'slack2';'voltageLevel2'; \ No newline at end of file