From 24cfba1015e150d8a3041731e1e9966347d728d3 Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Fri, 27 Jan 2023 16:38:57 +0100 Subject: [PATCH 1/4] get nb voltage levels Signed-off-by: Franck LECUYER --- .../main/java/com/powsybl/nad/NetworkAreaDiagram.java | 6 ++++++ .../powsybl/nad/build/iidm/VoltageLevelFilter.java | 4 ++++ .../nad/layout/LayoutWithInitialPositionsTest.java | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java index 4785be058..e4bbb2452 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java @@ -150,4 +150,10 @@ public String drawToString(SvgParameters svgParameters) { throw new UncheckedIOException(e); } } + + public int getNbVoltageLevels() { + return voltageLevelFilter instanceof VoltageLevelFilter + ? ((VoltageLevelFilter) voltageLevelFilter).getNbVoltageLevels() + : network.getVoltageLevelCount(); + } } diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java b/network-area-diagram/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java index a261200a3..4f40d0dee 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java @@ -29,6 +29,10 @@ public VoltageLevelFilter(Set voltageLevels) { this.voltageLevels = voltageLevels; } + public int getNbVoltageLevels() { + return voltageLevels != null ? voltageLevels.size() : 0; + } + @Override public boolean test(VoltageLevel voltageLevel) { return voltageLevels.contains(voltageLevel); diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java index 0aa61e6ec..2d11a6b77 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java @@ -59,6 +59,17 @@ public void testDiamond() { checkLayoutWithInitialPositions(LayoutNetworkFactory.createDiamond()); } + @Test + public void testNbVoltageLevels() { + Network network = LayoutNetworkFactory.createDiamond(); + + assertEquals(1, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 0)).getNbVoltageLevels()); + assertEquals(4, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 3)).getNbVoltageLevels()); + assertEquals(7, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 5)).getNbVoltageLevels()); + assertEquals(1, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 0)).getNbVoltageLevels()); + assertEquals(15, new NetworkAreaDiagram(network, VoltageLevelFilter.NO_FILTER).getNbVoltageLevels()); + } + private void checkLayoutWithInitialPositions(Network network) { Predicate filter = vl -> vl.getNominalV() >= 100; From 161ca3e11e93279718aa4dfd09bb9e03452521d0 Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Fri, 27 Jan 2023 17:02:54 +0100 Subject: [PATCH 2/4] improve coverage Signed-off-by: Franck LECUYER --- .../com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java index 2d11a6b77..c54b71fd9 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java @@ -63,6 +63,7 @@ public void testDiamond() { public void testNbVoltageLevels() { Network network = LayoutNetworkFactory.createDiamond(); + assertEquals(0, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", -1)).getNbVoltageLevels()); assertEquals(1, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 0)).getNbVoltageLevels()); assertEquals(4, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 3)).getNbVoltageLevels()); assertEquals(7, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 5)).getNbVoltageLevels()); From 99cf632553b9d9b7ad1f9c1fd294951f8e69c769 Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Fri, 27 Jan 2023 17:08:48 +0100 Subject: [PATCH 3/4] improve coverage Signed-off-by: Franck LECUYER --- .../java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java | 2 +- .../com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java b/network-area-diagram/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java index 4f40d0dee..685ec72c5 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java @@ -30,7 +30,7 @@ public VoltageLevelFilter(Set voltageLevels) { } public int getNbVoltageLevels() { - return voltageLevels != null ? voltageLevels.size() : 0; + return voltageLevels.size(); } @Override diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java index c54b71fd9..2d11a6b77 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java @@ -63,7 +63,6 @@ public void testDiamond() { public void testNbVoltageLevels() { Network network = LayoutNetworkFactory.createDiamond(); - assertEquals(0, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", -1)).getNbVoltageLevels()); assertEquals(1, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 0)).getNbVoltageLevels()); assertEquals(4, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 3)).getNbVoltageLevels()); assertEquals(7, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 5)).getNbVoltageLevels()); From ef90807e220fddee30357a924488f19293561c84 Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 31 Jan 2023 12:16:37 +0100 Subject: [PATCH 4/4] Remove method from NetworkAreaDiagram Signed-off-by: Florian Dupuy --- .../main/java/com/powsybl/nad/NetworkAreaDiagram.java | 6 ------ .../nad/layout/LayoutWithInitialPositionsTest.java | 9 ++++----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java index e4bbb2452..4785be058 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java @@ -150,10 +150,4 @@ public String drawToString(SvgParameters svgParameters) { throw new UncheckedIOException(e); } } - - public int getNbVoltageLevels() { - return voltageLevelFilter instanceof VoltageLevelFilter - ? ((VoltageLevelFilter) voltageLevelFilter).getNbVoltageLevels() - : network.getVoltageLevelCount(); - } } diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java index 2d11a6b77..d76d89530 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java @@ -63,11 +63,10 @@ public void testDiamond() { public void testNbVoltageLevels() { Network network = LayoutNetworkFactory.createDiamond(); - assertEquals(1, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 0)).getNbVoltageLevels()); - assertEquals(4, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 3)).getNbVoltageLevels()); - assertEquals(7, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 5)).getNbVoltageLevels()); - assertEquals(1, new NetworkAreaDiagram(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 0)).getNbVoltageLevels()); - assertEquals(15, new NetworkAreaDiagram(network, VoltageLevelFilter.NO_FILTER).getNbVoltageLevels()); + assertEquals(1, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 0).getNbVoltageLevels()); + assertEquals(4, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 3).getNbVoltageLevels()); + assertEquals(7, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 5).getNbVoltageLevels()); + assertEquals(1, VoltageLevelFilter.createVoltageLevelDepthFilter(network, "A 400", 0).getNbVoltageLevels()); } private void checkLayoutWithInitialPositions(Network network) {