Esempio n. 1
0
        public void SerializeFourLevelTree()
        {
            var node = new Node {
                ratio      = { aCount = 1, anCount = 11 },
                SortedKids = new[] {
                    new Node {
                        c          = 'b',
                        ratio      = { aCount = 5, anCount = 0 },
                        SortedKids = new[] {
                            new Node {
                                c          = 'c',
                                ratio      = { aCount = 3, anCount = 4 },
                                SortedKids = new[] {
                                    new Node {
                                        c     = 'd',
                                        ratio = { aCount = 0x100, anCount = 0x80 }
                                    },
                                },
                            },
                            new Node {
                                c     = 'u',
                                ratio = { aCount = 2, anCount = 15 }
                            },
                        },
                    },
                }
            };
            const string serializedNode = @"(1:b)b(5:0)bc(3:4)bcd(100:80)bu(2:f)";

            Assert.Equal(serializedNode, NodeSerializer.Serialize(node));
            Assert.Equal(node, NodeSerializer.Deserialize(serializedNode), NodeEqualityComparer.Instance);
        }
Esempio n. 2
0
        public void SingleNodeWorks()
        {
            var node = new Node {
                ratio = { aCount = 0x2468ad, anCount = 0x12345 }
            };
            const string serializedNode = @"(2468ad:12345)";

            Assert.Equal(serializedNode, NodeSerializer.Serialize(node));
            Assert.Equal(node, NodeSerializer.Deserialize(serializedNode), NodeEqualityComparer.Instance);
        }
Esempio n. 3
0
        public void TestDeserializeNode()
        {
            MemoryStream ms       = new MemoryStream();
            var          f        = new CoreEntityFactory();
            var          ns       = new NodeSerializer(ms, f, new DummyContextFactory());
            var          nodeOrig = f.CreateNode();

            ns.Serialize(nodeOrig);

            ms.Position = 0;
            var node = ns.Deserialize();

            Assert.Equal(nodeOrig.Id, node.Id);
        }
Esempio n. 4
0
        public void TestEdgeDeserialization()
        {
            MemoryStream ms = new MemoryStream();
            var          f  = new VirEntityFactory();
            var          ns = new NodeSerializer(ms, f, new DummyContextFactory());

            var node = new Person(f);

            node.ConnectTo(f.CreateNode(), Core.Interfaces.EdgeDirection.Both);

            ns.Serialize(node);

            ms.Position = 0;
            var nOut = ns.Deserialize();

            Assert.Single(nOut.Edges);
            Assert.IsAssignableFrom <IRemoteNode>(nOut.Edges.Single().GetOtherNode(nOut));
        }
        public void TestHomeIndex(string tree)
        {
            var homeController = new HomeController();
            var parseModel     = new ParseModel {
                TreeRequest = tree
            };
            var result = homeController.Index(parseModel) as ViewResult;

            parseModel = result?.Model as ParseModel;
            if (parseModel != null)
            {
                var node = NodeSerializer.Deserialize(parseModel.TreeResultJson);
                node = BalanceExample.Balance(node);
                Assert.True(BalanceExample.IsAvl(node));
            }
            else
            {
                throw new Exception("Error");
            }
        }
Esempio n. 6
0
        public void RootNodeWithKidsWorks()
        {
            var node = new Node {
                ratio      = { aCount = 1, anCount = 11 },
                SortedKids = new[] {
                    new Node {
                        c     = 'b',
                        ratio = { aCount = 5, anCount = 0 },
                    },
                    new Node {
                        c     = 'u',
                        ratio = { aCount = 2, anCount = 15 },
                    },
                }
            };

            const string serializedNode = @"(1:b)b(5:0)u(2:f)";

            Assert.Equal(serializedNode, NodeSerializer.Serialize(node));
            Node deserialized = NodeSerializer.Deserialize(serializedNode);

            Assert.Equal(node, deserialized, NodeEqualityComparer.Instance);
        }