From 64f030049b6bef2305eaa29b7680cd4fde93ab7d Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Tue, 14 Jun 2022 14:46:43 +0800 Subject: [PATCH] add test cases for count().is(0) and outE()/inE()/bothE().count() Change-Id: Ifd20c613f6ff63ac9e7609347fb4b770740367de --- .../baidu/hugegraph/core/EdgeCoreTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java index ddd6841b5b..5bfed17e4c 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java @@ -5354,6 +5354,52 @@ public void testQueryCount() { .values().count().next()); } + @Test + public void testQueryCountOfAdjacentEdges() { + HugeGraph graph = graph(); + GraphTraversalSource g = graph.traversal(); + init18Edges(); + + Vertex james = vertex("author", "id", 1); + + Assert.assertEquals(18L, g.E().count().next()); + + Assert.assertEquals(6L, g.V(james).bothE().count().next()); + + Assert.assertEquals(4L, g.V(james).outE().count().next()); + Assert.assertEquals(1L, g.V(james).outE("created").count().next()); + Assert.assertEquals(3L, g.V(james).outE("authored").count().next()); + Assert.assertEquals(1L, g.V(james).outE("authored") + .has("score", 3).count().next()); + + Assert.assertEquals(2L, g.V(james).inE().count().next()); + Assert.assertEquals(1L, g.V(james).inE("know").count().next()); + Assert.assertEquals(1L, g.V(james).inE("follow").count().next()); + } + + @Test + public void testQueryCountAsCondition() { + HugeGraph graph = graph(); + GraphTraversalSource g = graph.traversal(); + init18Edges(); + + Vertex java1 = vertex("book", "name", "java-1"); + Vertex java3 = vertex("book", "name", "java-3"); + + long paths; + paths = g.V(java1) + .repeat(__.inE().outV().simplePath()) + .until(__.or(__.inE().count().is(0), __.loops().is(3))) + .path().count().next(); + Assert.assertEquals(4L, paths); + + paths = g.V(java3) + .repeat(__.inE().outV().simplePath()) + .until(__.or(__.inE().count().is(0), __.loops().is(3))) + .path().count().next(); + Assert.assertEquals(7L, paths); + } + @Test public void testRemoveEdge() { HugeGraph graph = graph();