You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/10/04 18:57:03 UTC
[1/7] tinkerpop git commit: TINKERPOP-2055 Added support for special
Double values
Repository: tinkerpop
Updated Branches:
refs/heads/tp32 b510613b1 -> 80fa89bdf
TINKERPOP-2055 Added support for special Double values
Includes Nan and the infinity values.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/afc12bd2
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/afc12bd2
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/afc12bd2
Branch: refs/heads/tp32
Commit: afc12bd27bc9c4c26b3ba2594c4c0810d5d76421
Parents: e7af98b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Oct 2 15:35:53 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Oct 2 15:35:53 2018 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../io/graphson/GraphSONSerializersV2d0.java | 19 ++++++++++++++++---
.../graphson/GraphSONMapperEmbeddedTypeTest.java | 15 +++++++++++++++
3 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/afc12bd2/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index e93c1c9..33d35d3 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -37,6 +37,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Added support for GraphSON serialization of `Date` in Javascript.
* Added synchronized `Map` to Gryo 1.0 registrations.
* Added `Triple` to Gryo 1.0 registrations.
+* Added support for `Double.NaN`, `Double.POSITIVE_INFINITY` and `Double.NEGATIVE_INFINITY`.
* Improved escaping of special characters in strings passed to the `GroovyTranslator`.
* Added better internal processing of `Column` in `by(Function)`.
* Added `hasNext()` support on `Traversal` for `gremlin-python`.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/afc12bd2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
index 2ddb37a..177e2d0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
@@ -677,7 +677,7 @@ class GraphSONSerializersV2d0 {
}
@Override
- public Integer deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+ public Integer deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
return jsonParser.getIntValue();
}
@@ -694,8 +694,21 @@ class GraphSONSerializersV2d0 {
}
@Override
- public Double deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
- return jsonParser.getDoubleValue();
+ public Double deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+ if (jsonParser.getCurrentToken().isNumeric())
+ return jsonParser.getDoubleValue();
+ else {
+ final String numberText = jsonParser.getValueAsString();
+ if ("NaN".equalsIgnoreCase(numberText))
+ return Double.NaN;
+ else if ("-Infinity".equals(numberText) || "-INF".equalsIgnoreCase(numberText))
+ return Double.NEGATIVE_INFINITY;
+ else if ("Infinity".equals(numberText) || "INF".equals(numberText))
+ return Double.POSITIVE_INFINITY;
+ else
+ throw new IllegalStateException("Double value unexpected: " + numberText);
+ }
+
}
@Override
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/afc12bd2/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
index 9079c8a..e5f2693 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
@@ -42,7 +42,9 @@ import java.time.Year;
import java.time.YearMonth;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static org.hamcrest.core.StringStartsWith.startsWith;
import static org.junit.Assert.assertEquals;
@@ -72,6 +74,19 @@ public class GraphSONMapperEmbeddedTypeTest extends AbstractGraphSONTest {
public String version;
@Test
+ public void shouldHandleNumberConstants() throws Exception {
+ assumeThat(version, startsWith("v2"));
+
+ final List<Object> o = new ArrayList<>();
+ o.add(123.321d);
+ o.add(Double.NaN);
+ o.add(Double.NEGATIVE_INFINITY);
+ o.add(Double.POSITIVE_INFINITY);
+
+ assertEquals(o, serializeDeserialize(mapper, o, List.class));
+ }
+
+ @Test
public void shouldHandleBiFunctionLambda() throws Exception {
assumeThat(version, startsWith("v2"));
[2/7] tinkerpop git commit: TINKERPOP-2055 Support for special
numbers in python
Posted by sp...@apache.org.
TINKERPOP-2055 Support for special numbers in python
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/854914e6
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/854914e6
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/854914e6
Branch: refs/heads/tp32
Commit: 854914e6e3adbf7f0854eb0fec0c3a38b61d4644
Parents: afc12bd
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Oct 2 16:55:50 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Oct 2 16:55:50 2018 -0400
----------------------------------------------------------------------
.../gremlin_python/structure/io/graphson.py | 26 ++++++++++++++++++++
.../jython/tests/structure/io/test_graphson.py | 25 +++++++++++++++++++
2 files changed, 51 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/854914e6/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index 24e86bb..f3411ba 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -20,6 +20,7 @@ import datetime
import json
import time
import uuid
+import math
from collections import OrderedDict
import six
@@ -381,6 +382,31 @@ class FloatIO(_NumberIO):
graphson_type = "g:Float"
graphson_base_type = "Float"
+ @classmethod
+ def dictify(cls, n, writer):
+ if isinstance(n, bool): # because isinstance(False, int) and isinstance(True, int)
+ return n
+ elif math.isnan(n):
+ return GraphSONUtil.typedValue(cls.graphson_base_type, "NaN")
+ elif math.isinf(n) and n > 0:
+ return GraphSONUtil.typedValue(cls.graphson_base_type, "Infinity")
+ elif math.isinf(n) and n < 0:
+ return GraphSONUtil.typedValue(cls.graphson_base_type, "-Infinity")
+ else:
+ return GraphSONUtil.typedValue(cls.graphson_base_type, n)
+
+ @classmethod
+ def objectify(cls, v, _):
+ if isinstance(v, str):
+ if v == 'NaN':
+ return float('nan')
+ elif v == "Infinity":
+ return float('inf')
+ elif v == "-Infinity":
+ return float('-inf')
+
+ return cls.python_type(v)
+
class DoubleIO(FloatIO):
graphson_type = "g:Double"
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/854914e6/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
index 928b33f..37e99c6 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
@@ -22,6 +22,7 @@ import datetime
import time
import json
import uuid
+import math
from mock import Mock
@@ -70,6 +71,27 @@ class TestGraphSONReader(object):
}))
assert isinstance(x, float)
assert 31.2 == x
+ ##
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Double",
+ "@value": "NaN"
+ }))
+ assert isinstance(x, float)
+ assert math.isnan(x)
+ ##
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Double",
+ "@value": "Infinity"
+ }))
+ assert isinstance(x, float)
+ assert math.isinf(x) and x > 0
+ ##
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Double",
+ "@value": "-Infinity"
+ }))
+ assert isinstance(x, float)
+ assert math.isinf(x) and x < 0
def test_graph(self):
vertex = self.graphson_reader.readObject(
@@ -163,6 +185,9 @@ class TestGraphSONWriter(object):
assert {"@type": "g:Int64", "@value": 2} == json.loads(self.graphson_writer.writeObject(long(2)))
assert {"@type": "g:Int32", "@value": 1} == json.loads(self.graphson_writer.writeObject(1))
assert {"@type": "g:Double", "@value": 3.2} == json.loads(self.graphson_writer.writeObject(3.2))
+ assert {"@type": "g:Double", "@value": "NaN"} == json.loads(self.graphson_writer.writeObject(float('nan')))
+ assert {"@type": "g:Double", "@value": "Infinity"} == json.loads(self.graphson_writer.writeObject(float('inf')))
+ assert {"@type": "g:Double", "@value": "-Infinity"} == json.loads(self.graphson_writer.writeObject(float('-inf')))
assert """true""" == self.graphson_writer.writeObject(True)
def test_P(self):
[7/7] tinkerpop git commit: Merge branch 'TINKERPOP-2055' into tp32
Posted by sp...@apache.org.
Merge branch 'TINKERPOP-2055' into tp32
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/80fa89bd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/80fa89bd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/80fa89bd
Branch: refs/heads/tp32
Commit: 80fa89bdff687f4dcd3c48965be7cb9478fadccc
Parents: b510613 bd7048d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Oct 4 14:03:44 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Oct 4 14:03:44 2018 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
docs/src/dev/io/graphson.asciidoc | 2 +
.../io/graphson/GraphSONSerializersV2d0.java | 19 ++++++++--
.../GraphSONMapperEmbeddedTypeTest.java | 15 ++++++++
.../IO/GraphSON/GraphSONReaderTests.cs | 38 ++++++++++++++++++-
.../IO/GraphSON/GraphSONWriterTests.cs | 30 +++++++++++++++
.../lib/structure/io/type-serializers.js | 30 ++++++++++++++-
.../test/unit/graphson-test.js | 39 ++++++++++++++++++++
.../gremlin_python/structure/io/graphson.py | 26 +++++++++++++
.../jython/tests/structure/io/test_graphson.py | 25 +++++++++++++
10 files changed, 218 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/80fa89bd/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --cc CHANGELOG.asciidoc
index f3340cc,33d35d3..a7e6388
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@@ -38,10 -37,8 +38,11 @@@ image::https://raw.githubusercontent.co
* Added support for GraphSON serialization of `Date` in Javascript.
* Added synchronized `Map` to Gryo 1.0 registrations.
* Added `Triple` to Gryo 1.0 registrations.
+ * Added support for `Double.NaN`, `Double.POSITIVE_INFINITY` and `Double.NEGATIVE_INFINITY`.
* Improved escaping of special characters in strings passed to the `GroovyTranslator`.
+* Added `Cluster` configuration option to set a custom validation script to use to test server connectivity in the Java driver.
+* Improved ability of `GroovyTranslator` to handle more types supported by GraphSON.
+* Improved ability of `GroovyTranslator` to handle custom types.
* Added better internal processing of `Column` in `by(Function)`.
* Added `hasNext()` support on `Traversal` for `gremlin-python`.
* Added support for additional extended types in Gremlin.Net with `decimal`, `TimeSpan`, `BigInteger`, `byte`, `byte[]`, `char` and `short`.
[6/7] tinkerpop git commit: TINKERPOP-2055 Minor comment fixes
Posted by sp...@apache.org.
TINKERPOP-2055 Minor comment fixes
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/bd7048dd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/bd7048dd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/bd7048dd
Branch: refs/heads/tp32
Commit: bd7048dda3e9fb20b717412ee708cffc62f2ca41
Parents: a083fbf
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Oct 4 14:02:08 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Oct 4 14:02:19 2018 -0400
----------------------------------------------------------------------
.../javascript/gremlin-javascript/test/unit/graphson-test.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bd7048dd/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
index a1ac0d6..66a36c6 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
@@ -46,7 +46,7 @@ describe('GraphSONReader', function () {
assert.strictEqual(result, item[1]);
});
});
- it('should parse GraphSON Nan from GraphSON', function () {
+ it('should parse GraphSON NaN from GraphSON', function () {
const reader = new GraphSONReader();
var result = reader.read({
"@type": "g:Double",
@@ -54,7 +54,7 @@ describe('GraphSONReader', function () {
});
assert.ok(isNaN(result));
});
- it('should parse GraphSON -Infinity and Nan from GraphSON', function () {
+ it('should parse GraphSON -Infinity from GraphSON', function () {
const reader = new GraphSONReader();
var result = reader.read({
"@type": "g:Double",
@@ -62,7 +62,7 @@ describe('GraphSONReader', function () {
});
assert.strictEqual(result, Number.NEGATIVE_INFINITY);
});
- it('should parse GraphSON Infinity and Nan from GraphSON', function () {
+ it('should parse GraphSON Infinity from GraphSON', function () {
const reader = new GraphSONReader();
var result = reader.read({
"@type": "g:Double",
[3/7] tinkerpop git commit: TINKERPOP-2055 Added special number
handling in javascript
Posted by sp...@apache.org.
TINKERPOP-2055 Added special number handling in javascript
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2d3041f2
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2d3041f2
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2d3041f2
Branch: refs/heads/tp32
Commit: 2d3041f226310379c966214461c79cf47432f4c9
Parents: 854914e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Oct 3 04:33:40 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Oct 3 04:33:40 2018 -0400
----------------------------------------------------------------------
.../lib/structure/io/type-serializers.js | 30 ++++++++++++++-
.../test/unit/graphson-test.js | 39 ++++++++++++++++++++
2 files changed, 67 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d3041f2/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
index fdf049f..5583c47 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
@@ -49,11 +49,37 @@ class TypeSerializer {
class NumberSerializer extends TypeSerializer {
serialize(item) {
- return item;
+ if (isNaN(item)) {
+ return {
+ [typeKey]: 'g:Double',
+ [valueKey]: 'NaN'
+ };
+ } else if (item === Number.POSITIVE_INFINITY) {
+ return {
+ [typeKey]: 'g:Double',
+ [valueKey]: 'Infinity'
+ };
+ } else if (item === Number.NEGATIVE_INFINITY) {
+ return {
+ [typeKey]: 'g:Double',
+ [valueKey]: '-Infinity'
+ };
+ } else {
+ return item;
+ }
}
deserialize(obj) {
- return parseFloat(obj[valueKey]);
+ var val = obj[valueKey];
+ if (val === 'NaN') {
+ return NaN;
+ } else if (val === 'Infinity') {
+ return Number.POSITIVE_INFINITY;
+ } else if (val === '-Infinity') {
+ return Number.NEGATIVE_INFINITY;
+ } else {
+ return parseFloat(val);
+ }
}
canBeUsedFor(value) {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d3041f2/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
index b459407..a1ac0d6 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js
@@ -46,6 +46,30 @@ describe('GraphSONReader', function () {
assert.strictEqual(result, item[1]);
});
});
+ it('should parse GraphSON Nan from GraphSON', function () {
+ const reader = new GraphSONReader();
+ var result = reader.read({
+ "@type": "g:Double",
+ "@value": "NaN"
+ });
+ assert.ok(isNaN(result));
+ });
+ it('should parse GraphSON -Infinity and Nan from GraphSON', function () {
+ const reader = new GraphSONReader();
+ var result = reader.read({
+ "@type": "g:Double",
+ "@value": "-Infinity"
+ });
+ assert.strictEqual(result, Number.NEGATIVE_INFINITY);
+ });
+ it('should parse GraphSON Infinity and Nan from GraphSON', function () {
+ const reader = new GraphSONReader();
+ var result = reader.read({
+ "@type": "g:Double",
+ "@value": "Infinity"
+ });
+ assert.strictEqual(result, Number.POSITIVE_INFINITY);
+ });
it('should parse Date', function() {
const obj = { "@type" : "g:Date", "@value" : 1481750076295 };
const reader = new GraphSONReader();
@@ -102,6 +126,21 @@ describe('GraphSONWriter', function () {
const writer = new GraphSONWriter();
assert.strictEqual(writer.write(2), '2');
});
+ it('should write NaN', function () {
+ const writer = new GraphSONWriter();
+ const expected = JSON.stringify({ "@type" : "g:Double", "@value" : "NaN" });
+ assert.strictEqual(writer.write(NaN), expected);
+ });
+ it('should write Infinity', function () {
+ const writer = new GraphSONWriter();
+ const expected = JSON.stringify({ "@type" : "g:Double", "@value" : "Infinity" });
+ assert.strictEqual(writer.write(Number.POSITIVE_INFINITY), expected);
+ });
+ it('should write -Infinity', function () {
+ const writer = new GraphSONWriter();
+ const expected = JSON.stringify({ "@type" : "g:Double", "@value" : "-Infinity" });
+ assert.strictEqual(writer.write(Number.NEGATIVE_INFINITY), expected);
+ });
it('should write Date', function() {
const writer = new GraphSONWriter();
const expected = JSON.stringify({ "@type" : "g:Date", "@value" : 1481750076295 });
[4/7] tinkerpop git commit: TINKERPOP-2055 Added tests for .Net on
special numbers
Posted by sp...@apache.org.
TINKERPOP-2055 Added tests for .Net on special numbers
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b5420278
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b5420278
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b5420278
Branch: refs/heads/tp32
Commit: b542027825fe905c0c46b81a00fe7dfd5275e8c6
Parents: 2d3041f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Oct 3 05:11:56 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Oct 3 05:11:56 2018 -0400
----------------------------------------------------------------------
.../IO/GraphSON/GraphSONReaderTests.cs | 38 ++++++++++++++++++--
.../IO/GraphSON/GraphSONWriterTests.cs | 30 ++++++++++++++++
2 files changed, 66 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5420278/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
index 74bf385..08a91ae 100644
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
@@ -24,11 +24,9 @@
using System;
using System.Collections.Generic;
using System.Numerics;
-using Gremlin.Net.Process.Traversal;
using Gremlin.Net.Structure;
using Gremlin.Net.Structure.IO.GraphSON;
using Moq;
-using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
@@ -178,6 +176,42 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON
}
[Fact]
+ public void ShouldDeserializeNaN()
+ {
+ var serializedValue = "{\"@type\":\"g:Double\",\"@value\":'NaN'}";
+ var reader = CreateStandardGraphSONReader();
+
+ var jObject = JObject.Parse(serializedValue);
+ var deserializedValue = reader.ToObject(jObject);
+
+ Assert.Equal(Double.NaN, deserializedValue);
+ }
+
+ [Fact]
+ public void ShouldDeserializePositiveInfinity()
+ {
+ var serializedValue = "{\"@type\":\"g:Double\",\"@value\":'Infinity'}";
+ var reader = CreateStandardGraphSONReader();
+
+ var jObject = JObject.Parse(serializedValue);
+ var deserializedValue = reader.ToObject(jObject);
+
+ Assert.Equal(Double.PositiveInfinity, deserializedValue);
+ }
+
+ [Fact]
+ public void ShouldDeserializeNegativeInfinity()
+ {
+ var serializedValue = "{\"@type\":\"g:Double\",\"@value\":'-Infinity'}";
+ var reader = CreateStandardGraphSONReader();
+
+ var jObject = JObject.Parse(serializedValue);
+ var deserializedValue = reader.ToObject(jObject);
+
+ Assert.Equal(Double.NegativeInfinity, deserializedValue);
+ }
+
+ [Fact]
public void ShouldDeserializeDecimal()
{
var serializedValue = "{\"@type\":\"gx:BigDecimal\",\"@value\":-8.201}";
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5420278/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
index a544fb3..13fbddc 100644
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
@@ -81,6 +81,36 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON
}
[Fact]
+ public void ShouldSerializeNaN()
+ {
+ var writer = CreateStandardGraphSONWriter();
+
+ var graphSon = writer.WriteObject(Double.NaN);
+
+ Assert.Equal("{\"@type\":\"g:Double\",\"@value\":\"NaN\"}", graphSon);
+ }
+
+ [Fact]
+ public void ShouldSerializePositiveInfinity()
+ {
+ var writer = CreateStandardGraphSONWriter();
+
+ var graphSon = writer.WriteObject(Double.PositiveInfinity);
+
+ Assert.Equal("{\"@type\":\"g:Double\",\"@value\":\"Infinity\"}", graphSon);
+ }
+
+ [Fact]
+ public void ShouldSerializeNegativeInfinity()
+ {
+ var writer = CreateStandardGraphSONWriter();
+
+ var graphSon = writer.WriteObject(Double.NegativeInfinity);
+
+ Assert.Equal("{\"@type\":\"g:Double\",\"@value\":\"-Infinity\"}", graphSon);
+ }
+
+ [Fact]
public void ShouldSerializeDecimal()
{
var writer = CreateStandardGraphSONWriter();
[5/7] tinkerpop git commit: TINKERPOP-2055 Updated IO docs to include
special numbers
Posted by sp...@apache.org.
TINKERPOP-2055 Updated IO docs to include special numbers
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/a083fbff
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/a083fbff
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/a083fbff
Branch: refs/heads/tp32
Commit: a083fbff62fcc38a3dae9b138f56b0d052e0c143
Parents: b542027
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Oct 3 05:30:27 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Oct 3 05:30:27 2018 -0400
----------------------------------------------------------------------
docs/src/dev/io/graphson.asciidoc | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a083fbff/docs/src/dev/io/graphson.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/dev/io/graphson.asciidoc b/docs/src/dev/io/graphson.asciidoc
index c120634..064ac2e 100644
--- a/docs/src/dev/io/graphson.asciidoc
+++ b/docs/src/dev/io/graphson.asciidoc
@@ -1491,6 +1491,8 @@ types. By default, TinkerPop types will have the namespace "g" (or "gx" for "ext
==== Double
+While the `@value` is expected to be a JSON number, it might also be a `String` of `NaN`, `Infinity` or `-Infinity`.
+
[source,json]
----
{