Exemplo n.º 1
0
        public void TestClone()
        {
            var obj = new Class {
                ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() }
            };
            var nodeContainer = new NodeContainer();
            var path1         = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            var clone         = path1.Clone();

            AssertAreEqual(path1, clone);
            AssertAreEqual(path1.GetHashCode(), clone.GetHashCode());
            AssertAreEqual(path1.RootNode, clone.RootNode);
            AssertAreEqual(path1.IsValid, clone.IsValid);
            AssertAreEqual(path1.IsEmpty, clone.IsEmpty);
            AssertAreEqual(path1.GetNode(), clone.GetNode());
            var path2 = path1.PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));

            clone = path2.Clone();
            AssertAreEqual(path2, clone);
            AssertAreEqual(path2.RootNode, clone.RootNode);
            AssertAreEqual(path2.IsValid, clone.IsValid);
            AssertAreEqual(path2.IsEmpty, clone.IsEmpty);
            AssertAreEqual(path2.GetNode(), clone.GetNode());
            var path3 = path1.PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember));

            clone = path3.Clone();
            AssertAreEqual(path3, clone);
            AssertAreEqual(path3.RootNode, clone.RootNode);
            AssertAreEqual(path3.IsValid, clone.IsValid);
            AssertAreEqual(path3.IsEmpty, clone.IsEmpty);
            AssertAreEqual(path3.GetNode(), clone.GetNode());
        }
 public void TestClone()
 {
     var obj = new Class { ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } };
     var nodeContainer = new NodeContainer();
     var path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
     var clone = path1.Clone();
     AssertAreEqual(path1, clone);
     AssertAreEqual(path1.GetHashCode(), clone.GetHashCode());
     AssertAreEqual(path1.RootNode, clone.RootNode);
     AssertAreEqual(path1.IsValid, clone.IsValid);
     AssertAreEqual(path1.IsEmpty, clone.IsEmpty);
     AssertAreEqual(path1.GetNode(), clone.GetNode());
     var path2 = path1.PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
     clone = path2.Clone();
     AssertAreEqual(path2, clone);
     AssertAreEqual(path2.RootNode, clone.RootNode);
     AssertAreEqual(path2.IsValid, clone.IsValid);
     AssertAreEqual(path2.IsEmpty, clone.IsEmpty);
     AssertAreEqual(path2.GetNode(), clone.GetNode());
     var path3 = path1.PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember));
     clone = path3.Clone();
     AssertAreEqual(path3, clone);
     AssertAreEqual(path3.RootNode, clone.RootNode);
     AssertAreEqual(path3.IsValid, clone.IsValid);
     AssertAreEqual(path3.IsEmpty, clone.IsEmpty);
     AssertAreEqual(path3.GetNode(), clone.GetNode());
 }
Exemplo n.º 3
0
        public void TestEquals()
        {
            var obj = new Class {
                StructMember = { StringMember = "aa" }, ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() }
            };
            var nodeContainer = new NodeContainer();
            var path1         = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.IntMember));
            var path2         = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.IntMember));

            AssertAreEqual(path1, path2);
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember));
            AssertAreNotEqual(path1, path2);
            AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember));
            AssertAreEqual(path1, path2);
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember)).PushTarget();
            AssertAreNotEqual(path1, path2);
            AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember)).PushTarget();
            AssertAreEqual(path1, path2);
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
            AssertAreNotEqual(path1, path2);
            AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
            AssertAreEqual(path1, path2);
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ListMember)).PushIndex(new Index(0));
            AssertAreNotEqual(path1, path2);
            AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ListMember)).PushIndex(new Index(0));
            AssertAreEqual(path1, path2);
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1));
            AssertAreNotEqual(path1, path2);
            AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
        }
 public void TestEquals()
 {
     var obj = new Class { StructMember = { StringMember = "aa" }, ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } };
     var nodeContainer = new NodeContainer();
     var path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.IntMember));
     var path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.IntMember));
     AssertAreEqual(path1, path2);
     AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
     path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember));
     AssertAreNotEqual(path1, path2);
     AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
     path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember));
     AssertAreEqual(path1, path2);
     AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
     path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember)).PushTarget();
     AssertAreNotEqual(path1, path2);
     AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
     path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember)).PushTarget();
     AssertAreEqual(path1, path2);
     AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
     path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
     AssertAreNotEqual(path1, path2);
     AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
     path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
     AssertAreEqual(path1, path2);
     AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
     path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ListMember)).PushIndex(new Index(0));
     AssertAreNotEqual(path1, path2);
     AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
     path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ListMember)).PushIndex(new Index(0));
     AssertAreEqual(path1, path2);
     AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
     path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1));
     AssertAreNotEqual(path1, path2);
     AssertAreNotEqual(path1.GetHashCode(), path2.GetHashCode());
 }
Exemplo n.º 5
0
        public void TestEquals()
        {
            // Note: comparing GraphNodePath.GetHashCode() returns true when the root node is equivalent. This is because the root node is the only invariant.

            var obj = new Class {
                StructMember = { StringMember = "aa" }, ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() }
            };
            var nodeContainer = new NodeContainer();
            var path1         = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));

            path1.PushMember(nameof(Class.IntMember));
            var path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));

            path2.PushMember(nameof(Class.IntMember));
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreEqual(path1, path2);

            path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            path1.PushMember(nameof(Class.ClassMember));
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreNotEqual(path1, path2);
            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            path2.PushMember(nameof(Class.ClassMember));
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreEqual(path1, path2);

            path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            path1.PushMember(nameof(Class.ClassMember));
            path1.PushTarget();
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreNotEqual(path1, path2);
            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            path2.PushMember(nameof(Class.ClassMember));
            path2.PushTarget();
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreEqual(path1, path2);

            path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            path1.PushMember(nameof(Class.ClassMember));
            path1.PushTarget();
            path1.PushMember(nameof(Class.IntMember));
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreNotEqual(path1, path2);
            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            path2.PushMember(nameof(Class.ClassMember));
            path2.PushTarget();
            path2.PushMember(nameof(Class.IntMember));
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreEqual(path1, path2);

            path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            path1.PushMember(nameof(Class.ListMember));
            path1.PushIndex(new NodeIndex(0));
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreNotEqual(path1, path2);
            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            path2.PushMember(nameof(Class.ListMember));
            path2.PushIndex(new NodeIndex(0));
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreEqual(path1, path2);

            path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
            path2.PushMember(nameof(Class.ListMember));
            path2.PushIndex(new NodeIndex(1));
            AssertAreEqual(path1.GetHashCode(), path2.GetHashCode());
            AssertAreNotEqual(path1, path2);
        }