[ https://issues.apache.org/jira/browse/TINKERPOP-2872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17805266#comment-17805266 ]
ASF GitHub Bot commented on TINKERPOP-2872: ------------------------------------------- ryn5 commented on code in PR #2422: URL: https://github.com/apache/tinkerpop/pull/2422#discussion_r1447808171 ########## gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/element-comparison-test.js: ########## @@ -0,0 +1,261 @@ +/* + * 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. + */ + +const chai = require('chai') +const { expect } = require('chai'); +const { VertexProperty, Property, Vertex, Edge, Path } = require('../../lib/structure/graph'); +const { deepMembersById, compareElements, opt } = require('../cucumber/element-comparison'); +const deepEqual = require('deep-eql'); + +chai.use(function (chai, chaiUtils) { + chai.Assertion.overwriteMethod('members', function (_super) { + return deepMembersById; + }); +}); + +describe('primitives', function () { + it('should pass', function () { + expect(deepEqual(1, 1, opt)).to.be.true; + expect(deepEqual(false, false, opt)).to.be.true; + expect(deepEqual(null, null, opt)).to.be.true; + }); + + it('should fail', function () { + expect(deepEqual(1, 2, opt)).to.be.false; + expect(deepEqual(true, false, opt)).to.be.false; + expect(deepEqual(0, "0", opt)).to.be.false; + expect(deepEqual(0, false, opt)).to.be.false; + expect(deepEqual(0, null, opt)).to.be.false; + expect(deepEqual(false, null, opt)).to.be.false; + }); +}); + +describe('elements', function () { + const v1 = new Vertex(1, "dog", undefined); + const v2 = new Vertex(1, "cat", undefined); + const v3 = new Vertex(2, "cat", undefined); + + const e1 = new Edge(2, v1, "chases", v3, undefined); + const e2 = new Edge(3, v1, "chases", v3, undefined); + const e3 = new Edge(3, v2, "chases", v3, undefined); + + const vp1 = new VertexProperty(3, "size", "small", undefined); + const vp2 = new VertexProperty(3, "size", "large", undefined); + const vp3 = new VertexProperty(4, "size", "large", undefined); + + it('should pass with same id, different values', function () { + expect(deepEqual(v1, v2, opt)).to.be.true; + expect(deepEqual(v3, e1, opt)).to.be.true; + expect(deepEqual(e2, e3, opt)).to.be.true; + expect(deepEqual(e3, vp1, opt)).to.be.true; + expect(deepEqual(vp1, vp2, opt)).to.be.true; + }); + + it('should fail with different id, same values', function () { + expect(deepEqual(v2, v3, opt)).to.be.false; + expect(deepEqual(e1, e2, opt)).to.be.false; + expect(deepEqual(vp2, vp3, opt)).to.be.false; + }); +}); + +describe('property', function () { + const p1 = new Property("a", "1"); + const p2 = new Property("a", "1"); + const p3 = new Property("a", 1); + const p4 = new Property(1, 1); + const p5 = new Property(1, "a"); + + it('should pass only properties that match exactly', function () { + expect(deepEqual(p1, p2, opt)).to.be.true; + expect(deepEqual(p1, p3, opt)).to.be.false; + expect(deepEqual(p1, p4, opt)).to.be.false; + expect(deepEqual(p3, p5, opt)).to.be.false; + expect(deepEqual(p3, p5, opt)).to.be.false; + }); +}); + +describe('arrays', function () { Review Comment: Added `element arrays` tests similar to `arrays` > Inconsistency in comparing Elements in JavaScript tests > ------------------------------------------------------- > > Key: TINKERPOP-2872 > URL: https://issues.apache.org/jira/browse/TINKERPOP-2872 > Project: TinkerPop > Issue Type: Improvement > Components: javascript > Affects Versions: 3.7.0 > Reporter: Valentyn Kahamlyk > Priority: Major > > In most GLV's we consider Elements the same when they have the same ID. > In JavaScript tests used [member wise > comparison|https://github.com/apache/tinkerpop/blob/master/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js#L176] > Make it work like the others GLV's, just compare ID. -- This message was sent by Atlassian Jira (v8.20.10#820010)