Esempio n. 1
0
        public void MergeShouldThrowWhenContentIsNull()
        {
            var nodeCollection = new MergeableNodeCollection <NamedObject>();

            nodeCollection.AddRange(new[]
            {
                new MergeableNode <NamedObject>(),
            });

            MergeAlgorithm <NamedObject> mergeAlgorithm = new MergeAlgorithm <NamedObject>();

            Assert.Throws <NotSupportedException>(() => mergeAlgorithm.Merge(_emptyNodeCollection, nodeCollection));
        }
Esempio n. 2
0
        public void Traversal()
        {
            var nodeCollection = new MergeableNodeCollection <NamedObject>();

            nodeCollection.AddRange(new[]
            {
                new MergeableNode <NamedObject>(new NamedObject("File")),
                new MergeableNode <NamedObject>(new NamedObject("Edit"),
                                                new MergeableNode <NamedObject>(new NamedObject("Undo")),
                                                new MergeableNode <NamedObject>(new NamedObject("Redo"))),
                new MergeableNode <NamedObject>(new NamedObject("Tools")),
                new MergeableNode <NamedObject>(new NamedObject("Help")),
            });

            // GetRoot()
            Assert.AreSame(nodeCollection[1], nodeCollection[1].Children[1].GetRoot());

            // GetAncestors()
            var ancestors = nodeCollection[1].Children[1].GetAncestors().ToList();

            Assert.AreEqual(1, ancestors.Count);
            Assert.AreSame(nodeCollection[1], ancestors[0]);

            // GetDescendants()
            var descendants = nodeCollection[1].GetDescendants().ToList();

            Assert.AreEqual(2, descendants.Count);
            Assert.AreSame(nodeCollection[1].Children[0], descendants[0]);
            Assert.AreSame(nodeCollection[1].Children[1], descendants[1]);

            descendants = nodeCollection[1].GetDescendants(false).ToList();
            Assert.AreEqual(2, descendants.Count);
            Assert.AreSame(nodeCollection[1].Children[0], descendants[0]);
            Assert.AreSame(nodeCollection[1].Children[1], descendants[1]);

            // GetSubtree()
            var subtree = nodeCollection[1].GetSubtree().ToList();

            Assert.AreEqual(3, subtree.Count);
            Assert.AreSame(nodeCollection[1], subtree[0]);
            Assert.AreSame(nodeCollection[1].Children[0], subtree[1]);
            Assert.AreSame(nodeCollection[1].Children[1], subtree[2]);

            subtree = nodeCollection[1].GetSubtree(false).ToList();
            Assert.AreEqual(3, subtree.Count);
            Assert.AreSame(nodeCollection[1], subtree[0]);
            Assert.AreSame(nodeCollection[1].Children[0], subtree[1]);
            Assert.AreSame(nodeCollection[1].Children[1], subtree[2]);
        }
Esempio n. 3
0
        public void SetUp()
        {
            _emptyNodeCollection = new MergeableNodeCollection <NamedObject>();

            _nodeCollection = new MergeableNodeCollection <NamedObject>();
            _nodeCollection.AddRange(new[]
            {
                new MergeableNode <NamedObject>(new NamedObject("File")),
                new MergeableNode <NamedObject>(new NamedObject("Edit"),
                                                new MergeableNode <NamedObject>(new NamedObject("Undo")),
                                                new MergeableNode <NamedObject>(new NamedObject("Redo"))),
                new MergeableNode <NamedObject>(new NamedObject("Tools")),
                new MergeableNode <NamedObject>(new NamedObject("Help")),
            });
        }
Esempio n. 4
0
        public void ComplexMerge()
        {
            var nodeCollection = new MergeableNodeCollection <NamedObject>();

            nodeCollection.AddRange(new[]
            {
                new MergeableNode <NamedObject>(new NamedObject("Ignore1"), new MergePoint(MergeOperation.Ignore, null)),
                new MergeableNode <NamedObject>(new NamedObject("Ignore2"), new MergePoint(MergeOperation.Match, "Unknown")),
                new MergeableNode <NamedObject>(new NamedObject("Ignore3"), new MergePoint(MergeOperation.InsertBefore, "Unknown")),
                new MergeableNode <NamedObject>(new NamedObject("Ignore4"), new MergePoint(MergeOperation.InsertAfter, "Unknown")),
                new MergeableNode <NamedObject>(new NamedObject("Ignore5"), new MergePoint(MergeOperation.Replace, "Unknown")),
                new MergeableNode <NamedObject>(new NamedObject("Ignore6"), new MergePoint(MergeOperation.Remove, "Unknown")),

                new MergeableNode <NamedObject>(new NamedObject("PostHelp")),
                new MergeableNode <NamedObject>(new NamedObject("PreFile"), new MergePoint(MergeOperation.Prepend, null)),
                new MergeableNode <NamedObject>(new NamedObject("DoNothing"), new MergePoint(MergeOperation.Match, "Help")),
                new MergeableNode <NamedObject>(new NamedObject("View"), new MergePoint(MergeOperation.InsertAfter, "Edit")),
                new MergeableNode <NamedObject>(new NamedObject("Windows"), new MergePoint(MergeOperation.InsertBefore, "Help")),
                new MergeableNode <NamedObject>(new NamedObject("HelpNew"), new MergePoint(MergeOperation.Replace, "Help")),
                new MergeableNode <NamedObject>(new NamedObject("RemoveTools"), new MergePoint(MergeOperation.Remove, "Tools")),

                new MergeableNode <NamedObject>(
                    new NamedObject("Edit"),
                    new MergePoint(MergeOperation.Append),
                    new MergeableNode <NamedObject>(new NamedObject("Cut"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.InsertAfter, "Redo")),
                    new MergeableNode <NamedObject>(new NamedObject("Paste"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Append)),
                    new MergeableNode <NamedObject>(new NamedObject("Copy"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.InsertBefore, "Paste")),
                    new MergeableNode <NamedObject>(new NamedObject("Format"),
                                                    new MergeableNode <NamedObject>(new NamedObject("Comment")),
                                                    new MergeableNode <NamedObject>(new NamedObject("Uncomment"))),
                    new MergeableNode <NamedObject>(new NamedObject("PreUndo"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Prepend)),
                    new MergeableNode <NamedObject>(new NamedObject("Ignore"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Ignore)),
                    new MergeableNode <NamedObject>(new NamedObject("UndoNew"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Replace, "Undo")),
                    new MergeableNode <NamedObject>(new NamedObject("Redo"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Remove, "Redo"))),
            });

            MergeAlgorithm <NamedObject> mergeAlgorithm = new MergeAlgorithm <NamedObject>();

            mergeAlgorithm.Merge(_nodeCollection, nodeCollection);

            Assert.AreEqual(7, _nodeCollection.Count);
            Assert.AreEqual("PreFile", _nodeCollection[0].Content.Name);
            Assert.That(_nodeCollection[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("File", _nodeCollection[1].Content.Name);
            Assert.That(_nodeCollection[1].Children, Is.Null.Or.Empty);

            Assert.AreEqual("Edit", _nodeCollection[2].Content.Name);
            Assert.AreEqual(6, _nodeCollection[2].Children.Count);
            Assert.AreEqual("PreUndo", _nodeCollection[2].Children[0].Content.Name);
            Assert.That(_nodeCollection[2].Children[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("UndoNew", _nodeCollection[2].Children[1].Content.Name);
            Assert.That(_nodeCollection[2].Children[1].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Cut", _nodeCollection[2].Children[2].Content.Name);
            Assert.That(_nodeCollection[2].Children[2].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Copy", _nodeCollection[2].Children[3].Content.Name);
            Assert.That(_nodeCollection[2].Children[3].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Paste", _nodeCollection[2].Children[4].Content.Name);
            Assert.That(_nodeCollection[2].Children[4].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Format", _nodeCollection[2].Children[5].Content.Name);
            Assert.AreEqual(2, _nodeCollection[2].Children[5].Children.Count);
            Assert.AreEqual("Comment", _nodeCollection[2].Children[5].Children[0].Content.Name);
            Assert.That(_nodeCollection[2].Children[5].Children[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Uncomment", _nodeCollection[2].Children[5].Children[1].Content.Name);
            Assert.That(_nodeCollection[2].Children[5].Children[1].Children, Is.Null.Or.Empty);

            Assert.AreEqual("View", _nodeCollection[3].Content.Name);
            Assert.That(_nodeCollection[3].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Windows", _nodeCollection[4].Content.Name);
            Assert.That(_nodeCollection[4].Children, Is.Null.Or.Empty);
            Assert.AreEqual("HelpNew", _nodeCollection[5].Content.Name);
            Assert.That(_nodeCollection[5].Children, Is.Null.Or.Empty);
            Assert.AreEqual("PostHelp", _nodeCollection[6].Content.Name);
            Assert.That(_nodeCollection[6].Children, Is.Null.Or.Empty);
        }
Esempio n. 5
0
        public void ComplexMerge()
        {
            var nodeCollection = new MergeableNodeCollection<NamedObject>();
            nodeCollection.AddRange(new[]
            {
                new MergeableNode<NamedObject>(new NamedObject("Ignore1"), new MergePoint(MergeOperation.Ignore, null)),
                new MergeableNode<NamedObject>(new NamedObject("Ignore2"), new MergePoint(MergeOperation.Match, "Unknown")),
                new MergeableNode<NamedObject>(new NamedObject("Ignore3"), new MergePoint(MergeOperation.InsertBefore, "Unknown")),
                new MergeableNode<NamedObject>(new NamedObject("Ignore4"), new MergePoint(MergeOperation.InsertAfter, "Unknown")),
                new MergeableNode<NamedObject>(new NamedObject("Ignore5"), new MergePoint(MergeOperation.Replace, "Unknown")),
                new MergeableNode<NamedObject>(new NamedObject("Ignore6"), new MergePoint(MergeOperation.Remove, "Unknown")),

                new MergeableNode<NamedObject>(new NamedObject("PostHelp")),
                new MergeableNode<NamedObject>(new NamedObject("PreFile"), new MergePoint(MergeOperation.Prepend, null)),
                new MergeableNode<NamedObject>(new NamedObject("DoNothing"), new MergePoint(MergeOperation.Match, "Help")),
                new MergeableNode<NamedObject>(new NamedObject("View"), new MergePoint(MergeOperation.InsertAfter, "Edit")),
                new MergeableNode<NamedObject>(new NamedObject("Windows"), new MergePoint(MergeOperation.InsertBefore, "Help")),
                new MergeableNode<NamedObject>(new NamedObject("HelpNew"), new MergePoint(MergeOperation.Replace, "Help")),
                new MergeableNode<NamedObject>(new NamedObject("RemoveTools"), new MergePoint(MergeOperation.Remove, "Tools")),

                new MergeableNode<NamedObject>(
                    new NamedObject("Edit"),
                    new MergePoint(MergeOperation.Append),
                        new MergeableNode<NamedObject>(new NamedObject("Cut"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.InsertAfter, "Redo")),
                        new MergeableNode<NamedObject>(new NamedObject("Paste"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Append)),
                        new MergeableNode<NamedObject>(new NamedObject("Copy"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.InsertBefore, "Paste")),
                        new MergeableNode<NamedObject>(new NamedObject("Format"),
                            new MergeableNode<NamedObject>(new NamedObject("Comment")),
                            new MergeableNode<NamedObject>(new NamedObject("Uncomment"))),
                        new MergeableNode<NamedObject>(new NamedObject("PreUndo"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Prepend)),
                        new MergeableNode<NamedObject>(new NamedObject("Ignore"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Ignore)),
                        new MergeableNode<NamedObject>(new NamedObject("UndoNew"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Replace, "Undo")),
                        new MergeableNode<NamedObject>(new NamedObject("Redo"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Remove, "Redo"))),
            });

            MergeAlgorithm<NamedObject> mergeAlgorithm = new MergeAlgorithm<NamedObject>();
            mergeAlgorithm.Merge(_nodeCollection, nodeCollection);

            Assert.AreEqual(7, _nodeCollection.Count);
            Assert.AreEqual("PreFile", _nodeCollection[0].Content.Name);
            Assert.That(_nodeCollection[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("File", _nodeCollection[1].Content.Name);
            Assert.That(_nodeCollection[1].Children, Is.Null.Or.Empty);

            Assert.AreEqual("Edit", _nodeCollection[2].Content.Name);
            Assert.AreEqual(6, _nodeCollection[2].Children.Count);
            Assert.AreEqual("PreUndo", _nodeCollection[2].Children[0].Content.Name);
            Assert.That(_nodeCollection[2].Children[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("UndoNew", _nodeCollection[2].Children[1].Content.Name);
            Assert.That(_nodeCollection[2].Children[1].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Cut", _nodeCollection[2].Children[2].Content.Name);
            Assert.That(_nodeCollection[2].Children[2].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Copy", _nodeCollection[2].Children[3].Content.Name);
            Assert.That(_nodeCollection[2].Children[3].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Paste", _nodeCollection[2].Children[4].Content.Name);
            Assert.That(_nodeCollection[2].Children[4].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Format", _nodeCollection[2].Children[5].Content.Name);
            Assert.AreEqual(2, _nodeCollection[2].Children[5].Children.Count);
            Assert.AreEqual("Comment", _nodeCollection[2].Children[5].Children[0].Content.Name);
            Assert.That(_nodeCollection[2].Children[5].Children[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Uncomment", _nodeCollection[2].Children[5].Children[1].Content.Name);
            Assert.That(_nodeCollection[2].Children[5].Children[1].Children, Is.Null.Or.Empty);

            Assert.AreEqual("View", _nodeCollection[3].Content.Name);
            Assert.That(_nodeCollection[3].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Windows", _nodeCollection[4].Content.Name);
            Assert.That(_nodeCollection[4].Children, Is.Null.Or.Empty);
            Assert.AreEqual("HelpNew", _nodeCollection[5].Content.Name);
            Assert.That(_nodeCollection[5].Children, Is.Null.Or.Empty);
            Assert.AreEqual("PostHelp", _nodeCollection[6].Content.Name);
            Assert.That(_nodeCollection[6].Children, Is.Null.Or.Empty);
        }
Esempio n. 6
0
        public void SetUp()
        {
            _emptyNodeCollection = new MergeableNodeCollection<NamedObject>();

            _nodeCollection = new MergeableNodeCollection<NamedObject>();
            _nodeCollection.AddRange(new[]
            {
                new MergeableNode<NamedObject>(new NamedObject("File")),
                new MergeableNode<NamedObject>(new NamedObject("Edit"),
                    new MergeableNode<NamedObject>(new NamedObject("Undo")),
                    new MergeableNode<NamedObject>(new NamedObject("Redo"))),
                new MergeableNode<NamedObject>(new NamedObject("Tools")),
                new MergeableNode<NamedObject>(new NamedObject("Help")),
            });
        }
Esempio n. 7
0
        public void MergeShouldThrowWhenContentIsNull()
        {
            var nodeCollection = new MergeableNodeCollection<NamedObject>();
            nodeCollection.AddRange(new[]
            {
                new MergeableNode<NamedObject>(),
            });

            MergeAlgorithm<NamedObject> mergeAlgorithm = new MergeAlgorithm<NamedObject>();
            Assert.Throws<NotSupportedException>(() => mergeAlgorithm.Merge(_emptyNodeCollection, nodeCollection));
        }
Esempio n. 8
0
        public void Traversal()
        {
            var nodeCollection = new MergeableNodeCollection<NamedObject>();
            nodeCollection.AddRange(new[]
            {
                new MergeableNode<NamedObject>(new NamedObject("File")),
                new MergeableNode<NamedObject>(new NamedObject("Edit"),
                    new MergeableNode<NamedObject>(new NamedObject("Undo")),
                    new MergeableNode<NamedObject>(new NamedObject("Redo"))),
                new MergeableNode<NamedObject>(new NamedObject("Tools")),
                new MergeableNode<NamedObject>(new NamedObject("Help")),
            });

            // GetRoot()
            Assert.AreSame(nodeCollection[1], nodeCollection[1].Children[1].GetRoot());

            // GetAncestors()
            var ancestors = nodeCollection[1].Children[1].GetAncestors().ToList();
            Assert.AreEqual(1, ancestors.Count);
            Assert.AreSame(nodeCollection[1], ancestors[0]);

            // GetDescendants()
            var descendants = nodeCollection[1].GetDescendants().ToList();
            Assert.AreEqual(2, descendants.Count);
            Assert.AreSame(nodeCollection[1].Children[0], descendants[0]);
            Assert.AreSame(nodeCollection[1].Children[1], descendants[1]);

            descendants = nodeCollection[1].GetDescendants(false).ToList();
            Assert.AreEqual(2, descendants.Count);
            Assert.AreSame(nodeCollection[1].Children[0], descendants[0]);
            Assert.AreSame(nodeCollection[1].Children[1], descendants[1]);

            // GetSubtree()
            var subtree = nodeCollection[1].GetSubtree().ToList();
            Assert.AreEqual(3, subtree.Count);
            Assert.AreSame(nodeCollection[1], subtree[0]);
            Assert.AreSame(nodeCollection[1].Children[0], subtree[1]);
            Assert.AreSame(nodeCollection[1].Children[1], subtree[2]);

            subtree = nodeCollection[1].GetSubtree(false).ToList();
            Assert.AreEqual(3, subtree.Count);
            Assert.AreSame(nodeCollection[1], subtree[0]);
            Assert.AreSame(nodeCollection[1].Children[0], subtree[1]);
            Assert.AreSame(nodeCollection[1].Children[1], subtree[2]);
        }