示例#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;1;b5;;2;c3;4;1;d74;3k;;u2;f;;";

            Assert.Equal(serializedNode, NodeSerializer.SerializeDense(node));
            Assert.Equal(node, NodeDeserializer.DeserializeDense(serializedNode), NodeEqualityComparer.Instance);
        }
示例#2
0
        public void SingleNodeWorks()
        {
            var node = new Node {
                ratio = { aCount = 0x2468ad, anCount = 0x12345 }
            };
            const string serializedNode = @"1f54d;1lj9;;";

            Assert.Equal(serializedNode, NodeSerializer.SerializeDense(node));
            Assert.Equal(node, NodeDeserializer.DeserializeDense(serializedNode), NodeEqualityComparer.Instance);
        }
示例#3
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;2;b5;;;u2;f;;";

            Assert.Equal(serializedNode, NodeSerializer.SerializeDense(node));
            var deserialized = NodeDeserializer.DeserializeDense(serializedNode);

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