Changeset View
Changeset View
Standalone View
Standalone View
java/src/test/java/org/softwareheritage/graph/GraphTest.java
Show All 10 Lines | |||||
import it.unimi.dsi.big.webgraph.LazyLongIterators; | import it.unimi.dsi.big.webgraph.LazyLongIterators; | ||||
import org.hamcrest.MatcherAssert; | import org.hamcrest.MatcherAssert; | ||||
import org.junit.jupiter.api.BeforeAll; | import org.junit.jupiter.api.BeforeAll; | ||||
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; | import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; | ||||
public class GraphTest { | public class GraphTest { | ||||
static Graph graph; | static Graph graph; | ||||
static Graph forwardGraph; | |||||
static Graph backwardGraph; | |||||
@BeforeAll | @BeforeAll | ||||
public static void setUp() throws IOException { | public static void setUp() throws IOException { | ||||
Path graphPath = Paths.get("..", "swh", "graph", "tests", "dataset", "output", "example"); | Path graphPath = Paths.get("..", "swh", "graph", "tests", "dataset", "output", "example"); | ||||
graph = Graph.loadMapped(graphPath.toString()); | graph = Graph.loadMapped(graphPath.toString(), Graph.LoadDirection.BOTH); | ||||
forwardGraph = Graph.loadMapped(graphPath.toString(), Graph.LoadDirection.FORWARD); | |||||
backwardGraph = Graph.loadMapped(graphPath.toString(), Graph.LoadDirection.BACKWARD); | |||||
} | } | ||||
public Graph getGraph() { | public Graph getGraph() { | ||||
return graph; | return graph; | ||||
} | } | ||||
public Graph getForwardGraph() { | |||||
return forwardGraph; | |||||
} | |||||
public Graph getBackwardGraph() { | |||||
return backwardGraph; | |||||
} | |||||
public static SWHID fakeSWHID(String type, int num) { | public static SWHID fakeSWHID(String type, int num) { | ||||
return new SWHID(String.format("swh:1:%s:%040d", type, num)); | return new SWHID(String.format("swh:1:%s:%040d", type, num)); | ||||
} | } | ||||
public static <T> void assertEqualsAnyOrder(Collection<T> expecteds, Collection<T> actuals) { | public static <T> void assertEqualsAnyOrder(Collection<T> expecteds, Collection<T> actuals) { | ||||
MatcherAssert.assertThat(expecteds, containsInAnyOrder(actuals.toArray())); | MatcherAssert.assertThat(expecteds, containsInAnyOrder(actuals.toArray())); | ||||
} | } | ||||
public static ArrayList<Long> lazyLongIteratorToList(LazyLongIterator input) { | public static ArrayList<Long> lazyLongIteratorToList(LazyLongIterator input) { | ||||
ArrayList<Long> inputList = new ArrayList<>(); | ArrayList<Long> inputList = new ArrayList<>(); | ||||
Iterator<Long> inputIt = LazyLongIterators.eager(input); | Iterator<Long> inputIt = LazyLongIterators.eager(input); | ||||
inputIt.forEachRemaining(inputList::add); | inputIt.forEachRemaining(inputList::add); | ||||
return inputList; | return inputList; | ||||
} | } | ||||
} | } |