Exemple #1
0
        public void Replicate()
        {
            SequenceTerminatorTrieNode <Char> aNode = new SequenceTerminatorTrieNode <Char>('a', null);
            SequenceTerminatorTrieNode <Char> bNode = new SequenceTerminatorTrieNode <Char>('b', aNode);

            aNode.AddChildNode(bNode.Item, bNode);
            SequenceTerminatorTrieNode <Char> cNode = new SequenceTerminatorTrieNode <Char>('c', bNode);

            bNode.AddChildNode(cNode.Item, cNode);
            SequenceTerminatorTrieNode <Char> dNode = new SequenceTerminatorTrieNode <Char>('d', bNode);

            bNode.AddChildNode(dNode.Item, dNode);
            bNode.SetSubTreeSize('c', 2);
            bNode.SetSubTreeSize('d', 3);

            SequenceTerminatorTrieNode <Char> replicaNode = bNode.Replicate();

            Assert.AreEqual('b', replicaNode.Item);
            Assert.IsTrue(replicaNode.ChildNodeExists('c'));
            Assert.IsTrue(replicaNode.ChildNodeExists('d'));
            Assert.AreEqual(2, replicaNode.GetSubtreeSize('c'));
            Assert.AreEqual(3, replicaNode.GetSubtreeSize('d'));
            Assert.AreNotSame(bNode, replicaNode);
            Assert.AreNotSame(aNode, replicaNode.ParentNode);
            Assert.AreNotSame(cNode, replicaNode.GetChildNode('c'));
            Assert.AreNotSame(dNode, replicaNode.GetChildNode('d'));


            // Test replicating a node with null parent
            replicaNode = aNode.Replicate();
            Assert.AreEqual('a', replicaNode.Item);
            Assert.IsNull(replicaNode.ParentNode);
            Assert.IsTrue(replicaNode.ChildNodeExists('b'));
            Assert.AreNotSame(bNode, replicaNode.GetChildNode('b'));
        }
Exemple #2
0
        public void CloneAsSequenceTerminator()
        {
            TrieNode <Char> aNode = new TrieNode <Char>('a', null);
            TrieNode <Char> bNode = new TrieNode <Char>('b', aNode);

            aNode.AddChildNode(bNode.Item, bNode);
            TrieNode <Char> cNode = new TrieNode <Char>('c', bNode);

            bNode.AddChildNode(cNode.Item, cNode);
            TrieNode <Char> dNode = new TrieNode <Char>('d', bNode);

            bNode.AddChildNode(dNode.Item, dNode);
            bNode.SetSubTreeSize('c', 2);
            bNode.SetSubTreeSize('d', 3);

            SequenceTerminatorTrieNode <Char> clonedNode = bNode.CloneAsSequenceTerminator();

            Assert.AreEqual('b', clonedNode.Item);
            Assert.IsTrue(clonedNode.ChildNodeExists('c'));
            Assert.IsTrue(clonedNode.ChildNodeExists('d'));
            Assert.AreEqual(2, clonedNode.GetSubtreeSize('c'));
            Assert.AreEqual(3, clonedNode.GetSubtreeSize('d'));
            Assert.AreNotSame(bNode, clonedNode);
            Assert.AreSame(aNode, clonedNode.ParentNode);
            Assert.AreSame(cNode, clonedNode.GetChildNode('c'));
            Assert.AreSame(dNode, clonedNode.GetChildNode('d'));
        }