You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2015/05/05 20:57:42 UTC
[4/9] incubator-tinkerpop git commit: added HalfStepTraversalStrategy
tests
added HalfStepTraversalStrategy tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/d20151fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/d20151fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/d20151fb
Branch: refs/heads/master
Commit: d20151fb5bcfaca171a4d9626096b69e9656ca28
Parents: 3db5851
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Tue May 5 14:14:03 2015 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Tue May 5 14:14:03 2015 +0200
----------------------------------------------------------------------
.../HalfStepTraversalStrategyTest.java | 130 +++++++++++++++++++
1 file changed, 130 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d20151fb/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/HalfStepTraversalStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/HalfStepTraversalStrategyTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/HalfStepTraversalStrategyTest.java
new file mode 100644
index 0000000..67c62d3
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/HalfStepTraversalStrategyTest.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+@RunWith(Enclosed.class)
+public class HalfStepTraversalStrategyTest {
+
+ @RunWith(Parameterized.class)
+ public static class StandardTest extends AbstractHalfStepTraversalStrategyTest {
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Iterable<Object[]> data() {
+ return generateTestParameters();
+ }
+
+ @Parameterized.Parameter(value = 0)
+ public Traversal original;
+
+ @Parameterized.Parameter(value = 1)
+ public Traversal optimized;
+
+ @Before
+ public void setup() {
+ this.traversalEngine = mock(TraversalEngine.class);
+ when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.STANDARD);
+ }
+
+ @Test
+ public void shouldApplyStrategy() {
+ doTest(original, optimized);
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ComputerTest extends AbstractHalfStepTraversalStrategyTest {
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Iterable<Object[]> data() {
+ return generateTestParameters();
+ }
+
+ @Parameterized.Parameter(value = 0)
+ public Traversal original;
+
+ @Parameterized.Parameter(value = 1)
+ public Traversal optimized;
+
+ @Before
+ public void setup() {
+ this.traversalEngine = mock(TraversalEngine.class);
+ when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
+ }
+
+ @Test
+ public void shouldApplyStrategy() {
+ doTest(original, optimized);
+ }
+ }
+
+ private static abstract class AbstractHalfStepTraversalStrategyTest {
+
+ protected TraversalEngine traversalEngine;
+
+ void applyHalfStepTraversalStrategy(final Traversal traversal) {
+ final TraversalStrategies strategies = new DefaultTraversalStrategies();
+ strategies.addStrategies(HalfStepTraversalStrategy.instance());
+
+ traversal.asAdmin().setStrategies(strategies);
+ traversal.asAdmin().applyStrategies();
+ traversal.asAdmin().setEngine(traversalEngine);
+ }
+
+ public void doTest(final Traversal traversal, final Traversal optimized) {
+ applyHalfStepTraversalStrategy(traversal);
+ assertEquals(optimized.toString(), traversal.toString());
+ }
+
+ static Iterable<Object[]> generateTestParameters() {
+
+ return Arrays.asList(new Traversal[][]{
+ {__.out().count(), __.outE().count()},
+ {__.in().count(), __.inE().count()},
+ {__.both().count(), __.bothE().count()},
+ {__.out("knows").count(), __.outE("knows").count()},
+ {__.out("knows", "likes").count(), __.outE("knows", "likes").count()},
+ {__.has(__.out()), __.has(__.outE())},
+ {__.hasNot(__.out()), __.hasNot(__.outE())},
+ {__.has(__.out("knows")), __.has(__.outE("knows"))},
+ {__.values().count(), __.properties().count()},
+ {__.values("name").count(), __.properties("name").count()},
+ {__.has(__.values()), __.has(__.properties())}});
+ }
+ }
+}