Skip to content

Commit

Permalink
Enable checkstyle for test files (jgrapht#823) (jgrapht#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
besza authored Oct 20, 2020
1 parent a4be820 commit 743283a
Show file tree
Hide file tree
Showing 31 changed files with 659 additions and 548 deletions.
5 changes: 5 additions & 0 deletions etc/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<suppressions>
<!-- Ignore header checks for package-info.java files -->
<suppress files="package-info\.java" checks="Header"/>

<!-- Suppression of Javadoc related checks for test files -->
<suppress files="[/\\]src[/\\]test[/\\].*" checks="JavadocMethod"/>
<suppress files="[/\\]src[/\\]test[/\\].*" checks="JavadocType"/>
<suppress files="[/\\]src[/\\]test[/\\].*" checks="JavadocPackage"/>
</suppressions>
8 changes: 3 additions & 5 deletions etc/jgrapht_checks.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="BeforeExecutionExclusionFileFilter">
Expand All @@ -27,9 +27,7 @@
</module>

<module name="TreeWalker">
<module name="JavadocMethod">
<property name="scope" value="public" />
</module>
<!-- Defining scope as protected means public and protected scopes are checked. -->
<module name="JavadocMethod">
<property name="scope" value="protected" />
</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public class TransitiveReductionTest
{

// @formatter:off
static final int[][] matrix = new int[][] {
static final int[][] MATRIX = new int[][] {
{0, 1, 1, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 1, 1},
{0, 0, 0, 0, 1},
{0, 1, 0, 0, 0}
};

static final int[][] expected_transitively_reduced_matrix = new int[][] {
static final int[][] EXPECTED_TRANSITIVELY_REDUCED_MATRIX = new int[][] {
{0, 0, 1, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 1, 0},
Expand All @@ -63,13 +63,13 @@ public void testInternals()

// System.out.println(Arrays.deepToString(matrix) + " original matrix");

final int n = matrix.length;
final int n = MATRIX.length;

// calc path matrix
int[][] path_matrix = new int[n][n];
{
{
System.arraycopy(matrix, 0, path_matrix, 0, matrix.length);
System.arraycopy(MATRIX, 0, path_matrix, 0, MATRIX.length);

final BitSet[] pathMatrixAsBitSetArray = asBitSetArray(path_matrix);

Expand Down Expand Up @@ -103,7 +103,7 @@ public void testInternals()

Assert
.assertArrayEquals(
expected_transitively_reduced_matrix, transitively_reduced_matrix);
EXPECTED_TRANSITIVELY_REDUCED_MATRIX, transitively_reduced_matrix);
}
}

Expand Down Expand Up @@ -249,7 +249,7 @@ public void testReduceFarAway()
@Test
public void testReduceCanonicalGraph()
{
Graph<Integer, DefaultEdge> graph = fromMatrixToDirectedGraph(matrix);
Graph<Integer, DefaultEdge> graph = fromMatrixToDirectedGraph(MATRIX);

// a few spot tests to verify the graph looks like it should
assertFalse(graph.containsEdge(0, 0));
Expand All @@ -274,7 +274,7 @@ public void testReduceCanonicalGraph()

// the full verification; less readable, but somewhat more complete :)
int[][] actual_transitively_reduced_matrix = fromDirectedGraphToMatrix(graph);
assertArrayEquals(expected_transitively_reduced_matrix, actual_transitively_reduced_matrix);
assertArrayEquals(EXPECTED_TRANSITIVELY_REDUCED_MATRIX, actual_transitively_reduced_matrix);
}

static private Graph<Integer, DefaultEdge> fromMatrixToDirectedGraph(final int[][] matrix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Tests for the Clique Minimal Separator Decomposition.
*
* @author Florian Buenzli <[email protected]>
* @author Florian Buenzli {@literal <[email protected]>}
*/
public class CliqueMinimalSeparatorDecompositionTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class TreeDynamicConnectivityTest
{
private static final Random rng = new Random(17L);
private static final Random RANDOM = new Random(17L);

@Test
public void testTreeDynamicConnectivity_addNode_removeNode()
Expand Down Expand Up @@ -134,7 +134,7 @@ private Graph<Integer, DefaultEdge> generateTree(int nodeNum, int start)
false);

BarabasiAlbertForestGenerator<Integer, DefaultEdge> gen =
new BarabasiAlbertForestGenerator<>(1, nodeNum, rng);
new BarabasiAlbertForestGenerator<>(1, nodeNum, RANDOM);
gen.generateGraph(tree);
return tree;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
*
* JGraphT : a free Java graph-theory library
*
* This program and the accompanying materials are dual-licensed under
* either
* See the CONTRIBUTORS.md file distributed with this work for additional
* information regarding copyright ownership.
*
* (a) the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation, or (at your option) any
* later version.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the
* GNU Lesser General Public License v2.1 or later
* which is available at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html.
*
* or (per the licensee's choosing)
*
* (b) the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation.
* SPDX-License-Identifier: EPL-2.0 OR LGPL-2.1-or-later
*/
package org.jgrapht.alg.cycle;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2018-2020, by Andre Immig and Contributors.
*
* JGraphT : a free Java graph-theory library
*
* See the CONTRIBUTORS.md file distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the
* GNU Lesser General Public License v2.1 or later
* which is available at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html.
*
* SPDX-License-Identifier: EPL-2.0 OR LGPL-2.1-or-later
*/
package org.jgrapht.alg.densesubgraph;

import org.jgrapht.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2018-2020, by Andre Immig and Contributors.
*
* JGraphT : a free Java graph-theory library
*
* See the CONTRIBUTORS.md file distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the
* GNU Lesser General Public License v2.1 or later
* which is available at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html.
*
* SPDX-License-Identifier: EPL-2.0 OR LGPL-2.1-or-later
*/
package org.jgrapht.alg.densesubgraph;

import org.jgrapht.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2018-2020, by Andre Immig and Contributors.
*
* JGraphT : a free Java graph-theory library
*
* See the CONTRIBUTORS.md file distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the
* GNU Lesser General Public License v2.1 or later
* which is available at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html.
*
* SPDX-License-Identifier: EPL-2.0 OR LGPL-2.1-or-later
*/
package org.jgrapht.alg.densesubgraph;

import org.jgrapht.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2018-2020, by Andre Immig and Contributors.
*
* JGraphT : a free Java graph-theory library
*
* See the CONTRIBUTORS.md file distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the
* GNU Lesser General Public License v2.1 or later
* which is available at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html.
*
* SPDX-License-Identifier: EPL-2.0 OR LGPL-2.1-or-later
*/
package org.jgrapht.alg.densesubgraph;

import org.jgrapht.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* (C) Copyright 2016-2020, by Dimitrios Michail and Contributors.
*
* JGraphT : a free Java graph-theory library
*
* See the CONTRIBUTORS.md file distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the
* GNU Lesser General Public License v2.1 or later
* which is available at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html.
*
* SPDX-License-Identifier: EPL-2.0 OR LGPL-2.1-or-later
*/
package org.jgrapht.alg.matching;

import org.jgrapht.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public class BidirectionalAStarShortestPathTest
extends
BaseHeuristicSearchTest
{
private static final String s = "s";
private static final String t = "t";
private static final String y = "y";
private static final String x = "x";
private static final String z = "z";
private static final String S = "S";
private static final String T = "T";
private static final String Y = "Y";
private static final String X = "X";
private static final String Z = "Z";

@Test
public void testEmptyGraph()
{
Graph<String, DefaultWeightedEdge> graph =
new DirectedWeightedPseudograph<>(DefaultWeightedEdge.class);
graph.addVertex(s);
new BidirectionalAStarShortestPath<>(graph, (sourceVertex, targetVertex) -> 0).getPaths(s);
graph.addVertex(S);
new BidirectionalAStarShortestPath<>(graph, (sourceVertex, targetVertex) -> 0).getPaths(S);
}

@Test
Expand All @@ -58,53 +58,53 @@ public void testSimpleGraph()
Graph<String, DefaultWeightedEdge> graph = getSimpleGraph();
AStarAdmissibleHeuristic<String> heuristic = getSimpleGraphHeuristic();
assertEquals(
Arrays.asList(s, y, z),
new BidirectionalAStarShortestPath<>(graph, heuristic).getPath(s, z).getVertexList());
Arrays.asList(S, Y, Z),
new BidirectionalAStarShortestPath<>(graph, heuristic).getPath(S, Z).getVertexList());
}

private Graph<String, DefaultWeightedEdge> getSimpleGraph()
{
Graph<String, DefaultWeightedEdge> graph =
new DirectedWeightedPseudograph<>(DefaultWeightedEdge.class);

Graphs.addAllVertices(graph, Arrays.asList(s, t, y, x, z));
Graphs.addAllVertices(graph, Arrays.asList(S, T, Y, X, Z));

Graphs.addEdge(graph, s, t, 10);
Graphs.addEdge(graph, s, y, 5);
Graphs.addEdge(graph, S, T, 10);
Graphs.addEdge(graph, S, Y, 5);

Graphs.addEdge(graph, t, y, 2);
Graphs.addEdge(graph, t, x, 1);
Graphs.addEdge(graph, T, Y, 2);
Graphs.addEdge(graph, T, X, 1);

Graphs.addEdge(graph, y, t, 3);
Graphs.addEdge(graph, y, z, 2);
Graphs.addEdge(graph, y, x, 9);
Graphs.addEdge(graph, Y, T, 3);
Graphs.addEdge(graph, Y, Z, 2);
Graphs.addEdge(graph, Y, X, 9);

Graphs.addEdge(graph, x, z, 4);
Graphs.addEdge(graph, X, Z, 4);

Graphs.addEdge(graph, z, x, 6);
Graphs.addEdge(graph, z, s, 7);
Graphs.addEdge(graph, Z, X, 6);
Graphs.addEdge(graph, Z, S, 7);

return graph;
}

private AStarAdmissibleHeuristic<String> getSimpleGraphHeuristic()
{
return (sourceVertex, targetVertex) -> {
if (sourceVertex.equals(s) && targetVertex.equals(z)) {
if (sourceVertex.equals(S) && targetVertex.equals(Z)) {
return 7;
} else if (sourceVertex.equals(y) && targetVertex.equals(z)) {
} else if (sourceVertex.equals(Y) && targetVertex.equals(Z)) {
return 2;
} else if (sourceVertex.equals(t) && targetVertex.equals(z)) {
} else if (sourceVertex.equals(T) && targetVertex.equals(Z)) {
return 4;
} else if (sourceVertex.equals(x) && targetVertex.equals(z)) {
} else if (sourceVertex.equals(X) && targetVertex.equals(Z)) {
return 4;
} else if (sourceVertex.equals(t) && targetVertex.equals(s)) {
} else if (sourceVertex.equals(T) && targetVertex.equals(S)) {
return 8;
} else if (sourceVertex.equals(y) && targetVertex.equals(s)) {
} else if (sourceVertex.equals(Y) && targetVertex.equals(S)) {
return 5;
} else if (sourceVertex.equals(x) && targetVertex.equals(s)) {
} else if (sourceVertex.equals(X) && targetVertex.equals(S)) {
return 11;
} else if (sourceVertex.equals(z) && targetVertex.equals(s)) {
} else if (sourceVertex.equals(Z) && targetVertex.equals(S)) {
return 7;
} else {
return 0;
Expand Down
Loading

0 comments on commit 743283a

Please sign in to comment.