You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by fl...@apache.org on 2022/02/02 14:25:32 UTC

[tinkerpop] 01/01: TINKERPOP-2518 Enable more Gherkin scenarios

This is an automated email from the ASF dual-hosted git repository.

florianhockmann pushed a commit to branch TINKERPOP-2518
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 799e4e3b26c86c01b28b875edaaedf0574a9a401
Author: Florian Hockmann <fh...@florian-hockmann.de>
AuthorDate: Wed Feb 2 15:16:49 2022 +0100

    TINKERPOP-2518 Enable more Gherkin scenarios
    
    There were three categories of scenarios ignored that are now enabled:
    * Some scenarios passed without any change. I don't know why they were
    ignored in the first place. Maybe we've fixed something in the meantime
    but forgot to enable them again.
    * Some scenarios expected a decimal type as the result but the server
    sent a double. I simply changed the expected type there to reflect what
    we get back from the server.
    * One scenario required a more complex assertion as it expects an array
    of dictionaries which means that we have to perform a deep equality
    check.
---
 .../Gherkin/CommonSteps.cs                         | 22 ++++-
 .../Gherkin/DeepEqualityExtensions.cs              | 96 ++++++++++++++++++++++
 .../Gherkin/GherkinTestRunner.cs                   | 23 ------
 .../Gherkin/IgnoreException.cs                     |  5 --
 gremlin-test/features/sideEffect/Sack.feature      | 12 +--
 5 files changed, 121 insertions(+), 37 deletions(-)

diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
index 0c17cc3..3641e69 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
@@ -46,8 +46,9 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         private readonly IDictionary<string, object> _parameters = new Dictionary<string, object>();
         private ITraversal _traversal;
         private object[] _result;
-        private static readonly JsonSerializerOptions JsonDeserializingOptions = new JsonSerializerOptions
-            {PropertyNamingPolicy = JsonNamingPolicy.CamelCase};
+
+        private static readonly JsonSerializerOptions JsonDeserializingOptions =
+            new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
         
         public static ScenarioData ScenarioData { get; set; } = new ScenarioData(new GraphSON3MessageSerializer());
 
@@ -205,7 +206,22 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
                         var expectedArray = expected.ToArray();
                         foreach (var resultItem in _result)
                         {
-                            Assert.Contains(resultItem, expectedArray);
+                            if (resultItem is Dictionary<object, object> resultItemDict)
+                            {
+                                var expectedArrayContainsResultDictionary = false;
+                                foreach (var expectedItem in expectedArray)
+                                {
+                                    if (expectedItem is not Dictionary<object, object> expectedItemDict) continue;
+                                    if (!expectedItemDict.DeepEqual(resultItemDict)) continue;
+                                    expectedArrayContainsResultDictionary = true;
+                                    break;
+                                }
+                                Assert.True(expectedArrayContainsResultDictionary);
+                            }
+                            else
+                            {
+                                Assert.Contains(resultItem, expectedArray);
+                            }
                         }
                         if (characterizedAs != "of")
                         {
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/DeepEqualityExtensions.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/DeepEqualityExtensions.cs
new file mode 100644
index 0000000..d0f36e3
--- /dev/null
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/DeepEqualityExtensions.cs
@@ -0,0 +1,96 @@
+#region License
+
+/*
+ * 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.
+ */
+
+#endregion
+
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Gremlin.Net.IntegrationTest.Gherkin;
+
+public static class DeepEqualityExtensions
+{
+    public static bool DeepEqual(this Dictionary<object, object> first, Dictionary<object, object> second)
+    {
+        if (first.Count != second.Count) return false;
+            
+        foreach (var (key1, value1) in first)
+        {
+            var foundMatch = false;
+            foreach (var (key2, value2) in second)
+            {
+                if (!key1.DeepEqual(key2) || !value1.DeepEqual(value2)) continue;
+                foundMatch = true;
+                break;
+            }
+            if (!foundMatch) return false;
+        }
+
+        return true;
+    }
+
+    private static bool DeepEqual(this object first, object second)
+    {
+        if (first == null)
+        {
+            if (second != null) return false;
+        }
+        else if (first is not string && first is IEnumerable enumerable1)
+        {
+            if (second is string || second is not IEnumerable enumerable2) return false;
+            if (!enumerable1.DeepEqual(enumerable2))
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if (!first.Equals(second)) return false;
+        }
+
+        return true;
+    }
+    
+    private static bool DeepEqual(this IEnumerable first, IEnumerable second)
+    {
+        if (first is Dictionary<object, object> dict1)
+        {
+            return second is Dictionary<object, object> dict2 && dict1.DeepEqual(dict2);
+        }
+        var objectEnum1 = first.ToObjectEnumerable();
+        var objectEnum2 = second.ToObjectEnumerable();
+            
+        // I hope that these IEnumerable<object> objects will always be simple collections so we don't need to go
+        //  even deeper...
+        return objectEnum1.SequenceEqual(objectEnum2);
+    }
+    
+    private static IEnumerable<object> ToObjectEnumerable(this IEnumerable enumerable)
+    {
+        if (enumerable.GetType().IsArray)
+        {
+            return (IEnumerable<object>)enumerable;
+        }
+
+        return (IEnumerable<object>)enumerable;
+    }
+}
\ No newline at end of file
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
index ea06c76..300eb74 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
@@ -45,29 +45,6 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             {
                 // Add here the name of scenarios to ignore and the reason, e.g.:
                 {"g_V_group_byXageX", IgnoreReason.NullKeysInMapNotSupported},
-
-                // they are not failing as a result of the Gremlin itself - they are failing because of shortcomings in
-                // the test suite.
-                // https://issues.apache.org/jira/browse/TINKERPOP-2518
-                {"g_withSackX0X_V_outE_sackXsumX_byXweightX_inV_sack_sum", IgnoreReason.NoReason},
-                {"g_V_aggregateXaX_byXageX_capXaX_unfold_sum", IgnoreReason.NoReason},
-                {"g_withSackX0X_V_repeatXoutE_sackXsumX_byXweightX_inVX_timesX2X_sack", IgnoreReason.NoReason},
-                {"g_injectXlistXnull_10_20_nullXX_meanXlocalX", IgnoreReason.NoReason},
-                {"g_injectXnull_10_20_nullX_mean", IgnoreReason.NoReason},
-                {"g_injectXnull_10_5_nullX_sum", IgnoreReason.NoReason},
-                {"g_injectXlistXnull_10_5_nullXX_sumXlocalX", IgnoreReason.NoReason},
-                {
-                    "g_withBulkXfalseX_withSackX1_sumX_VX1X_localXoutEXknowsX_barrierXnormSackX_inVX_inXknowsX_barrier_sack",
-                    IgnoreReason.NoReason
-                },
-                {
-                    "g_withSackX1_sumX_VX1X_localXoutXknowsX_barrierXnormSackXX_inXknowsX_barrier_sack",
-                    IgnoreReason.NoReason
-                },
-                {
-                    "g_V_hasXperson_name_markoX_bothXknowsX_groupCount_byXvaluesXnameX_foldX",
-                    IgnoreReason.ArrayKeysInMapNotAssertingInGherkin
-                },
             };
 
         private static class Keywords
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs
index 9579626..d7d41e2 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs
@@ -56,10 +56,5 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         /// C# does not allow a `null` value to be used as a key.
         /// </summary>
         NullKeysInMapNotSupported,
-        
-        /// <summary>
-        /// C# array equality is by reference not contents so the gherkin setup won't assert properly
-        /// </summary>
-        ArrayKeysInMapNotAssertingInGherkin
     }
 }
\ No newline at end of file
diff --git a/gremlin-test/features/sideEffect/Sack.feature b/gremlin-test/features/sideEffect/Sack.feature
index 6c4627d..4912659 100644
--- a/gremlin-test/features/sideEffect/Sack.feature
+++ b/gremlin-test/features/sideEffect/Sack.feature
@@ -42,7 +42,7 @@ Feature: Step - sack()
     When iterated to list
     Then the result should be unordered
       | result |
-      | d[3.5].m |
+      | d[3.5].d |
 
   Scenario: g_withSackX0X_V_repeatXoutE_sackXsumX_byXweightX_inVX_timesX2X_sack
     Given the modern graph
@@ -53,8 +53,8 @@ Feature: Step - sack()
     When iterated to list
     Then the result should be unordered
       | result |
-      | d[2.0].m |
-      | d[1.4].m |
+      | d[2.0].d |
+      | d[1.4].d |
 
   Scenario: g_withBulkXfalseX_withSackX1_sumX_VX1X_localXoutEXknowsX_barrierXnormSackX_inVX_inXknowsX_barrier_sack
     Given the modern graph
@@ -66,7 +66,7 @@ Feature: Step - sack()
     When iterated to list
     Then the result should be unordered
       | result |
-      | d[1.0].m |
+      | d[1.0].d |
 
   Scenario: g_withBulkXfalseX_withSackX1_sumX_V_out_barrier_sack
     Given the modern graph
@@ -92,8 +92,8 @@ Feature: Step - sack()
     When iterated to list
     Then the result should be unordered
       | result |
-      | d[1.0].m |
-      | d[1.0].m |
+      | d[1.0].d |
+      | d[1.0].d |
 
   Scenario: g_withSackXBigInteger_TEN_powX1000X_assignX_V_localXoutXknowsX_barrierXnormSackXX_inXknowsX_barrier_sack
     Given an unsupported test