-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase code coverage + cleaning code
Signed-off-by: Thomas ADAM <[email protected]>
- Loading branch information
Showing
13 changed files
with
95 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestPathFinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* 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.sld.iidm; | ||
|
||
import com.powsybl.sld.layout.pathfinding.*; | ||
import com.powsybl.sld.model.coordinate.Point; | ||
import org.junit.jupiter.api.*; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Thomas Adam {@literal <tadam at neverhack.com>} | ||
*/ | ||
class TestPathFinding extends AbstractTestCaseIidm { | ||
|
||
private Grid pathFinderGrid = null; | ||
private final PathFinder pathfinder = new DijkstraPathFinder(); | ||
|
||
@BeforeEach | ||
public void setUp() throws IOException { | ||
pathFinderGrid = new Grid(12, 12); | ||
} | ||
|
||
@Test | ||
void testNoSmoothPath() { | ||
final List<Point> expectedSnakeline = new ArrayList<>(); | ||
pathFinderGrid.setAvailability(0, 0, true); | ||
expectedSnakeline.add(new Point(0, 0)); | ||
for (int i = 0; i < 12 - 1; i++) { | ||
pathFinderGrid.setAvailability(i + 1, i, true); | ||
expectedSnakeline.add(new Point(i + 1, i)); | ||
pathFinderGrid.setAvailability(i + 1, i + 1, true); | ||
expectedSnakeline.add(new Point(i + 1, i + 1)); | ||
} | ||
List<Point> snakeline = pathfinder.toSnakeLine(pathfinder.findShortestPath(pathFinderGrid, | ||
0, 0, | ||
11, 11)); | ||
assertEquals(expectedSnakeline.size(), snakeline.size()); | ||
for (int i = 0; i < expectedSnakeline.size(); i++) { | ||
assertEquals(expectedSnakeline.get(i).toString(), snakeline.get(i).toString()); | ||
} | ||
} | ||
|
||
@Test | ||
void testSmoothPath() { | ||
final List<Point> expectedSnakeline = new ArrayList<>(); | ||
// Make available left & right borders | ||
for (int y = 0; y < 12; y++) { | ||
pathFinderGrid.setAvailability(0, y, true); | ||
expectedSnakeline.add(new Point(0, y)); | ||
pathFinderGrid.setAvailability(11, y, true); | ||
} | ||
// Make available up & down borders | ||
for (int x = 1; x < 12; x++) { | ||
pathFinderGrid.setAvailability(x, 0, true); | ||
pathFinderGrid.setAvailability(x, 11, true); | ||
expectedSnakeline.add(new Point(x, 11)); | ||
} | ||
List<Point> snakeline = pathfinder.toSnakeLine(pathfinder.findShortestPath(pathFinderGrid, | ||
0, 0, | ||
11, 11)); | ||
assertEquals(expectedSnakeline.size(), snakeline.size()); | ||
for (int i = 0; i < expectedSnakeline.size(); i++) { | ||
assertEquals(expectedSnakeline.get(i).toString(), snakeline.get(i).toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters