Skip to content

Commit

Permalink
Remove BaseProcTest usage
Browse files Browse the repository at this point in the history
  • Loading branch information
IoannisPanagiotas committed Jul 30, 2024
1 parent 89c3a55 commit a25b1d5
Showing 1 changed file with 32 additions and 46 deletions.
78 changes: 32 additions & 46 deletions algo/src/test/java/org/neo4j/gds/paths/PathFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
package org.neo4j.gds.paths;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.neo4j.gds.BaseProcTest;
import org.neo4j.gds.compat.GraphDatabaseApiProxy;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.RelationshipType;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class PathFactoryTest extends BaseProcTest {
class PathFactoryTest {

@AfterEach
void resetIds() {
Expand All @@ -39,68 +39,54 @@ void resetIds() {

@Nested
class SingleNode {
static final String DB_CYPHER = "CREATE ()";

@BeforeEach
void setup() {
runQuery(DB_CYPHER);
}

@Test
void emptyPath() {
var nodeIds = new long[]{0L};
var costs = new double[]{0.0D};

GraphDatabaseApiProxy.runInFullAccessTransaction(db, tx -> {
var path = PathFactory.create(
tx::getNodeById,
nodeIds,
costs,
RelationshipType.withName("REL"),
"prop"
);
assertEquals(0, path.length());
});
var path = PathFactory.create(
v-> mock(Node.class),
nodeIds,
costs,
RelationshipType.withName("REL"),
"prop"
);
assertEquals(0, path.length());
}
}

@Nested
class MultipleNodes {
static final String DB_CYPHER =
"CREATE" +
" (a)" +
", (b)" +
", (c)" +
", (a)-[:R]->(b)" +
", (b)-[:R]->(c)";

@BeforeEach
void setup() {
runQuery(DB_CYPHER);
}

@Test
void pathWithCosts() {
var nodeIds = new long[]{0L, 1L, 2L};
var costs = new double[]{0.0D, 1.0D, 4.0D};

GraphDatabaseApiProxy.runInFullAccessTransaction(db, tx -> {
var path = PathFactory.create(
tx::getNodeById,
nodeIds,
costs,
RelationshipType.withName("REL"),
"prop"
);
var mockNode0 = mock(Node.class);
var mockNode1 = mock(Node.class);
var mockNode2 = mock(Node.class);

when(mockNode0.getId()).thenReturn(nodeIds[0]);
when(mockNode1.getId()).thenReturn(nodeIds[1]);
when(mockNode2.getId()).thenReturn(nodeIds[2]);

var path = PathFactory.create(
v -> new Node[]{mockNode0,mockNode1,mockNode2}[(int)v],
nodeIds,
costs,
RelationshipType.withName("REL"),
"prop"
);

assertEquals(2, path.length());
assertEquals(2, path.length());

path.relationships().forEach(relationship -> {
var actualCost = (double) relationship.getProperty("prop");
var expectedCost = costs[(int) relationship.getEndNodeId()] - costs[(int) relationship.getStartNodeId()];
path.relationships().forEach(relationship -> {
var actualCost = (double) relationship.getProperty("prop");
var expectedCost = costs[(int) relationship.getEndNodeId()] - costs[(int) relationship.getStartNodeId()];

assertEquals(expectedCost, actualCost, 1E-4);
});
assertEquals(expectedCost, actualCost, 1E-4);
});
}
}
Expand Down

0 comments on commit a25b1d5

Please sign in to comment.