use of org.junit.jupiter.params.provider.MethodSource in project redisson by redisson.
the class RedissonSpringCacheTest method testPutGet.
@ParameterizedTest
@MethodSource("data")
public void testPutGet(Class<?> contextClass) {
AnnotationConfigApplicationContext context = contexts.get(contextClass);
SampleBean bean = context.getBean(SampleBean.class);
bean.store("object1", new SampleObject("name1", "value1"));
SampleObject s = bean.read("object1");
assertThat(s.getName()).isEqualTo("name1");
assertThat(s.getValue()).isEqualTo("value1");
}
use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.
the class TestAStar method testSimplest.
/**
* <pre>
* 01234567
* +-------->x A - C: 10
* 0|A C A - B: 2 (x2)
* 1| B B - C: 3
* V
* y
* </pre>
*/
@ParameterizedTest
@MethodSource("params")
void testSimplest(Function<EvaluationContext, PathFinder<WeightedPath>> finderFactory) {
try (Transaction transaction = graphDb.beginTx()) {
Node nodeA = graph.makeNode(transaction, "A", "x", 0d, "y", 0d);
Node nodeB = graph.makeNode(transaction, "B", "x", 2d, "y", 1d);
Node nodeC = graph.makeNode(transaction, "C", "x", 7d, "y", 0d);
Relationship relAB = graph.makeEdge(transaction, "A", "B", "length", 2d);
Relationship relAB2 = graph.makeEdge(transaction, "A", "B", "length", 2);
Relationship relBC = graph.makeEdge(transaction, "B", "C", "length", 3f);
Relationship relAC = graph.makeEdge(transaction, "A", "C", "length", (short) 10);
int counter = 0;
var context = new BasicEvaluationContext(transaction, graphDb);
Iterable<WeightedPath> allPaths = finderFactory.apply(context).findAllPaths(nodeA, nodeC);
for (WeightedPath path : allPaths) {
assertEquals((Double) 5d, (Double) path.weight());
assertPath(path, nodeA, nodeB, nodeC);
counter++;
}
assertEquals(1, counter);
transaction.commit();
}
}
use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.
the class TestAStar method pathToSelfReturnsZero.
@ParameterizedTest
@MethodSource("params")
void pathToSelfReturnsZero(Function<EvaluationContext, PathFinder<WeightedPath>> finderFactory) {
// GIVEN
try (Transaction transaction = graphDb.beginTx()) {
Node start = graph.makeNode(transaction, "start", "x", 0d, "y", 0d);
// WHEN
var context = new BasicEvaluationContext(transaction, graphDb);
WeightedPath path = finderFactory.apply(context).findSinglePath(start, start);
// THEN
assertNotNull(path);
assertEquals(start, path.startNode());
assertEquals(start, path.endNode());
assertEquals(0, path.length());
transaction.commit();
}
}
use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.
the class TestAStar method wikipediaExample.
@ParameterizedTest
@MethodSource("params")
void wikipediaExample(Function<EvaluationContext, PathFinder<WeightedPath>> finderFactory) {
/* GIVEN
*
* (start)---2--->(d)
* \ \
* 1.5 .\
* v 3
* (a)-\ v
* -2-\ (e)
* ->(b) \
* / \
* /-- 2
* /-3- v
* v --4------->(end)
* (c)------/
*/
try (Transaction transaction = graphDb.beginTx()) {
Node start = graph.makeNode(transaction, "start", "x", 0d, "y", 0d);
graph.makeNode(transaction, "a", "x", 0.3d, "y", 1d);
graph.makeNode(transaction, "b", "x", 2d, "y", 2d);
graph.makeNode(transaction, "c", "x", 0d, "y", 3d);
graph.makeNode(transaction, "d", "x", 2d, "y", 0d);
graph.makeNode(transaction, "e", "x", 3d, "y", 1.5d);
Node end = graph.makeNode(transaction, "end", "x", 3.3d, "y", 2.8d);
graph.makeEdge(transaction, "start", "a", "length", 1.5d);
graph.makeEdge(transaction, "a", "b", "length", 2f);
graph.makeEdge(transaction, "b", "c", "length", 3);
graph.makeEdge(transaction, "c", "end", "length", 4L);
graph.makeEdge(transaction, "start", "d", "length", (short) 2);
graph.makeEdge(transaction, "d", "e", "length", (byte) 3);
graph.makeEdge(transaction, "e", "end", "length", 2);
// WHEN
var context = new BasicEvaluationContext(transaction, graphDb);
WeightedPath path = finderFactory.apply(context).findSinglePath(start, end);
// THEN
assertPathDef(path, "start", "d", "e", "end");
transaction.commit();
}
}
use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.
the class TestBestFirstSelectorFactory method shouldDoWholeTraversalInCorrectOrder.
@ParameterizedTest
@MethodSource("params")
void shouldDoWholeTraversalInCorrectOrder(PathExpander expander, PathInterest<Integer> interest, Uniqueness uniqueness, String[] expectedResult) {
try (Transaction transaction = graphDb.beginTx()) {
var factory = new BestFirstSelectorFactory<Integer, Integer>(interest) {
private final CostEvaluator<Integer> evaluator = CommonEvaluators.intCostEvaluator(LENGTH);
@Override
protected Integer getStartData() {
return 0;
}
@Override
protected Integer addPriority(TraversalBranch source, Integer currentAggregatedValue, Integer value) {
return value + currentAggregatedValue;
}
@Override
protected Integer calculateValue(TraversalBranch next) {
return next.length() == 0 ? 0 : evaluator.getCost(next.lastRelationship(), Direction.BOTH);
}
};
Node a = transaction.getNodeById(graph.getNode(transaction, "a").getId());
Traverser traverser = new MonoDirectionalTraversalDescription().expand(expander).order(factory).uniqueness(uniqueness).traverse(a);
var iterator = traverser.iterator();
int i = 0;
while (iterator.hasNext()) {
assertPath(transaction, iterator.next(), expectedResult[i]);
i++;
}
assertEquals(expectedResult.length, i, String.format("Not all expected paths where traversed. Missing paths are %s\n", Arrays.toString(Arrays.copyOfRange(expectedResult, i, expectedResult.length))));
transaction.commit();
}
}
Aggregations