public void PairwiseComparison_ImportanceIndexer_ValidValue_SetsAndGetsValues()
        {
            //Arrange
            var node1      = new CriterionNode("Criterion1");
            var node2      = new CriterionNode("Criterion2");
            var node3      = new CriterionNode("Criterion2");
            var comparison = new PairwiseComparison(new CriterionNode[] { node1, node2, node3 });

            //Act
            comparison[node1, node1] = 3M; //must be reset to 1
            comparison[node1, node2] = 3M;
            comparison[node1, node3] = 5M;
            comparison[node2, node3] = 1M / 7M;

            //Assert
            Assert.AreEqual(1M, comparison[node1, node1]);
            Assert.AreEqual(3M, comparison[node1, node2]);
            Assert.AreEqual(5M, comparison[node1, node3]);
            Assert.AreEqual(1M / 3M, comparison[node2, node1]);
            Assert.AreEqual(1M, comparison[node2, node2]);
            Assert.AreEqual(1M / 7M, comparison[node2, node3]);
            Assert.AreEqual(1M / 5M, comparison[node3, node1]);
            Assert.AreEqual((1M / (1M / 7M)), comparison[node3, node2]);
            Assert.AreEqual(1M, comparison[node3, node3]);
        }
        public void PairwiseComparison_ValidValues_CalculatesPrioritiesLMaxCIAndCR()
        {
            //Arrange
            var node1      = new CriterionNode("Criterion1");
            var node2      = new CriterionNode("Criterion2");
            var node3      = new CriterionNode("Criterion3");
            var node4      = new CriterionNode("Criterion4");
            var comparison = new PairwiseComparison(new CriterionNode[] { node1, node2, node3, node4 });

            //Act
            comparison[node1, node2] = 5M;
            comparison[node1, node3] = 1M / 3M;
            comparison[node1, node4] = 7M;
            comparison[node2, node3] = 1M / 5M;
            comparison[node2, node4] = 3M;
            comparison[node3, node4] = 9M;

            //Assert
            Assert.AreEqual(0.3022281814153362243706377751M, comparison[node1]);
            Assert.AreEqual(0.096248411816356253140776933M, comparison[node2]);
            Assert.AreEqual(0.5574189162664633700502966175M, comparison[node3]);
            Assert.AreEqual(0.0441044905018441524382886743M, comparison[node4]);
            Assert.AreEqual(4.2020834004705332212662807083M, comparison.LMax);
            Assert.AreEqual(0.0673611334901777404220935694M, comparison.CI);
            Assert.AreEqual(0.0748457038779752671356595216M, comparison.CR);
        }
        public void PairwiseComparison_Constructor_ValidCriterions_InitsImportancesPrioritiesAndLMax()
        {
            //Arrange
            var criterion1 = new CriterionNode("Criterion1");
            var criterion2 = new CriterionNode("Criterion2");
            var criterion3 = new CriterionNode("Criterion3");
            var criterions = new List <CriterionNode>()
            {
                criterion1, criterion2, criterion3
            };

            //Act
            var comparison = new PairwiseComparison(criterions);

            //Assert
            foreach (var node1 in criterions)
            {
                foreach (var node2 in criterions)
                {
                    Assert.AreEqual(1M, comparison[node1, node2]);
                }
            }

            foreach (var node in criterions)
            {
                Assert.AreEqual(1M / 3, comparison[node]);
            }

            Assert.AreEqual(3, comparison.LMax);
        }
        public void PairwiseComparison_Constructor_NotUniqueCriterions_ThrowsInvalidOperationException()
        {
            //Arrange
            var criterion  = new CriterionNode();
            var criterions = new List <CriterionNode>()
            {
                criterion, criterion
            };
            Exception exception = null;

            //Act
            try
            {
                var comparison = new PairwiseComparison(criterions);
            }
            catch (Exception e)
            {
                exception = e;
            }

            //Assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(InvalidOperationException));
            Assert.AreEqual("Minimum 2 unique nodes are expected for pairwise comparison.", exception.Message);
        }
        public void PairwiseComparison_CR_NodeCountMoreThan10_ThrowsInvalidOperationException()
        {
            //Arrange
            var       node1      = new CriterionNode("Criterion1");
            var       node2      = new CriterionNode("Criterion2");
            var       node3      = new CriterionNode("Criterion3");
            var       node4      = new CriterionNode("Criterion4");
            var       node5      = new CriterionNode("Criterion5");
            var       node6      = new CriterionNode("Criterion6");
            var       node7      = new CriterionNode("Criterion7");
            var       node8      = new CriterionNode("Criterion8");
            var       node9      = new CriterionNode("Criterion9");
            var       node10     = new CriterionNode("Criterion10");
            var       node11     = new CriterionNode("Criterion11");
            var       comparison = new PairwiseComparison(new CriterionNode[] { node1, node2, node3, node4, node5, node6, node7, node8, node9, node10, node11 });
            Exception exception  = null;

            //Act
            try
            {
                var cr = comparison.CR;
            }
            catch (Exception e)
            {
                exception = e;
            }

            //Assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(InvalidOperationException));
            Assert.AreEqual("Consistency Ratio can not be calculated", exception.Message);
        }
예제 #6
0
        public void CriterionNode_AlternativeNodesCount_WithoutNodes_Returns0()
        {
            //Arrange => Act
            var criterion = new CriterionNode();

            //Assert
            Assert.AreEqual(0, criterion.AlternativeNodes.Count);
        }
예제 #7
0
        public void GoalNode_AddCriterionNode_AdsWithFixUp()
        {
            //Arrange
            var hierarchy = new Hierarchy();
            var criterion = new CriterionNode();

            //Act
            hierarchy.GoalNode.AddCriterionNode(criterion);

            //Assert
            Assert.AreEqual(hierarchy.GoalNode, criterion.GoalNode);
        }
예제 #8
0
        public void GoalNode_RemoveCriterionNode_RemovesWithFixUp()
        {
            //Arrange
            var hierarchy = new Hierarchy();
            var criterion = new CriterionNode();

            //Act
            hierarchy.GoalNode.AddCriterionNode(criterion);
            hierarchy.GoalNode.RemoveCriterionNode(criterion);

            //Assert
            Assert.IsNull(criterion.GoalNode);
        }
예제 #9
0
        public void CriterionNode_CriterionNode_SetsCriterionNode()
        {
            //Arrange
            var alternativeNode = new AlternativeNode(new Alternative());
            var criterion       = new CriterionNode();

            //Act
            alternativeNode.CriterionNode = criterion;

            //Assert
            Assert.AreEqual(criterion, alternativeNode.CriterionNode);
            Assert.IsTrue(criterion.AlternativeNodes.Contains(alternativeNode));
        }
예제 #10
0
        public void CriterionNode_CriterionNode_ExistingCriterion_SetsCriterionNodeToNull()
        {
            //Arrange
            var alternativeNode = new AlternativeNode(new Alternative());
            var criterion       = new CriterionNode();

            //Act
            alternativeNode.CriterionNode = criterion;
            alternativeNode.CriterionNode = null;

            //Arrange
            Assert.IsNull(alternativeNode.CriterionNode);
            Assert.IsFalse(criterion.AlternativeNodes.Contains(alternativeNode));
        }
예제 #11
0
        public void CriterionNode_ParentCriterionNode_SetsParentToNull()
        {
            //Arrange
            var criterion = new CriterionNode();
            var parent    = new CriterionNode();

            //Act
            criterion.ParentCriterionNode = parent;
            criterion.ParentCriterionNode = null;

            //Assert
            Assert.IsNull(criterion.ParentCriterionNode);
            Assert.IsFalse(parent.SubcriterionNodes.Contains(criterion));
        }
예제 #12
0
        public void CriterionNode_SubcriterionNodesRemove_RemovesWithWixUp()
        {
            //Arrange
            var hierarchy    = new Hierarchy();
            var criterion    = hierarchy.GoalNode.AddCriterionNode("Criterion");
            var subcriterion = new CriterionNode();

            //Act
            criterion.AddSubcriterionNode(subcriterion);
            criterion.RemoveSubcriterionNode(subcriterion);

            //Assert
            Assert.IsNull(subcriterion.ParentCriterionNode);
        }
예제 #13
0
        public void CriterionNode_GoalNode_SetsGoalToNull()
        {
            //Arrange
            var hierarchy = new Hierarchy();
            var criterion = new CriterionNode();

            //Act
            criterion.GoalNode = hierarchy.GoalNode;
            criterion.GoalNode = null;

            //Assert
            Assert.IsNull(criterion.GoalNode);
            Assert.IsFalse(hierarchy.GoalNode.CriterionNodes.Contains(criterion));
        }
예제 #14
0
        public void CriterionNode_ParentCriterionNode_ChangesParent()
        {
            //Arrange
            var criterion = new CriterionNode();
            var parent    = new CriterionNode();
            var parentNew = new CriterionNode();

            //Act
            criterion.ParentCriterionNode = parent;
            criterion.ParentCriterionNode = parentNew;

            //Assert
            Assert.IsFalse(parent.SubcriterionNodes.Contains(criterion));
            Assert.AreEqual(parentNew, criterion.ParentCriterionNode);
            Assert.IsTrue(parentNew.SubcriterionNodes.Contains(criterion));
        }
예제 #15
0
        public void CriterionNode_CriterionNode_ExistingCriterion_ChangesCriterionNode()
        {
            //Arrange
            var alternativeNode = new AlternativeNode(new Alternative());
            var criterion       = new CriterionNode();
            var criterionNew    = new CriterionNode();

            //Act
            alternativeNode.CriterionNode = criterion;
            alternativeNode.CriterionNode = criterionNew;

            //Arrange
            Assert.IsFalse(criterion.AlternativeNodes.Contains(alternativeNode));
            Assert.AreEqual(criterionNew, alternativeNode.CriterionNode);
            Assert.IsTrue(criterionNew.AlternativeNodes.Contains(alternativeNode));
        }
예제 #16
0
        public void CriterionNode_GoalNode_ChangesGoal()
        {
            //Arrange
            var hierarchy    = new Hierarchy();
            var hierarchyNew = new Hierarchy();
            var criterion    = new CriterionNode();

            //Act
            criterion.GoalNode = hierarchy.GoalNode;
            criterion.GoalNode = hierarchyNew.GoalNode;

            //Assert
            Assert.IsFalse(hierarchy.GoalNode.CriterionNodes.Contains(criterion));
            Assert.AreEqual(hierarchyNew.GoalNode, criterion.GoalNode);
            Assert.IsTrue(hierarchyNew.GoalNode.CriterionNodes.Contains(criterion));
        }
예제 #17
0
        public void CriterionNode_GoalNode_SetsGoalAndSetsParentCriterionNodeToNull()
        {
            //Arrange
            var hierarchy = new Hierarchy();
            var criterion = new CriterionNode();

            criterion.ParentCriterionNode = new CriterionNode();

            //Act
            criterion.GoalNode = hierarchy.GoalNode;

            //Assert
            Assert.AreEqual(hierarchy.GoalNode, criterion.GoalNode);
            Assert.IsTrue(hierarchy.GoalNode.CriterionNodes.Contains(criterion));
            Assert.IsNull(criterion.ParentCriterionNode);
        }
예제 #18
0
        public void CriterionNode_SubcriterionNodes_Add_AddsWithFixUp()
        {
            //Arrange
            var hierarchy = new Hierarchy();

            hierarchy.AddAlternative(new Alternative("Alternative1"));
            hierarchy.AddAlternative(new Alternative("Alternative2"));

            var criterion    = hierarchy.GoalNode.AddCriterionNode("Criterion");
            var subcriterion = new CriterionNode();

            //Act
            criterion.AddSubcriterionNode(subcriterion);

            //Assert
            Assert.AreEqual(criterion, subcriterion.ParentCriterionNode);
            Assert.AreEqual(0, criterion.AlternativeNodes.Count);
        }
예제 #19
0
        public void AlternativeNode_GlobalPriority_ReturnsCorrectValue()
        {
            //Arrange => Act
            var alternative1 = new Alternative();
            var alternative2 = new Alternative();
            var criterion    = new CriterionNode("Criterion", 0.374M);

            var hierarchy = new Hierarchy();

            hierarchy.AddAlternative(alternative1);
            hierarchy.AddAlternative(alternative2);
            hierarchy.GoalNode.AddCriterionNode(criterion);

            criterion.AlternativeNodes[alternative1].LocalPriority = 0.791M;
            criterion.AlternativeNodes[alternative2].LocalPriority = 0.673M;

            //Assert
            Assert.AreEqual(0.791M * 0.374M, criterion.AlternativeNodes[alternative1].GlobalPriority);
            Assert.AreEqual(0.673M * 0.374M, criterion.AlternativeNodes[alternative2].GlobalPriority);
        }
        public void PairwiseComparison_PriorityIndexerGetter_NullNode_ThrowsArgumentNullException()
        {
            //Arrange
            var       node1      = new CriterionNode("Criterion1");
            var       node2      = new CriterionNode("Criterion2");
            var       comparison = new PairwiseComparison(new CriterionNode[] { node1, node2 });
            Exception exception  = null;

            //Act
            try
            {
                var priority = comparison[null];
            }
            catch (Exception e)
            {
                exception = e;
            }

            //Assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(ArgumentNullException));
            Assert.AreEqual("node", ((ArgumentNullException)exception).ParamName);
        }
        public void PairwiseComparison_PriorityIndexerGetter_InvalidNode_ThrowsKeyNotFoundException()
        {
            //Arrange
            var       node1      = new CriterionNode("Criterion1");
            var       node2      = new CriterionNode("Criterion2");
            var       nodeWrong  = new CriterionNode("Criterion3");
            var       comparison = new PairwiseComparison(new CriterionNode[] { node1, node2 });
            Exception exception  = null;

            //Act
            try
            {
                var priority = comparison[nodeWrong];
            }
            catch (Exception e)
            {
                exception = e;
            }

            //Assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(KeyNotFoundException));
            Assert.AreEqual("Parameter node is not found in the nodes of the PairwiseComparison object.", exception.Message);
        }
        public void PairwiseComparison_ImportanceIndexerSetter_InvalidValue_ThrowsArgumentOutOfRangeException()
        {
            //Arrange
            var       node1      = new CriterionNode("Criterion1");
            var       node2      = new CriterionNode("Criterion2");
            var       comparison = new PairwiseComparison(new CriterionNode[] { node1, node2 });
            Exception exception1 = null;
            Exception exception2 = null;

            //Act
            try
            {
                comparison[node1, node2] = 1M / 10M;
            }
            catch (Exception e)
            {
                exception1 = e;
            }

            try
            {
                comparison[node1, node2] = 10;
            }
            catch (Exception e)
            {
                exception2 = e;
            }

            //Assert
            Assert.IsNotNull(exception1);
            Assert.IsNotNull(exception2);
            Assert.IsInstanceOfType(exception1, typeof(ArgumentOutOfRangeException));
            Assert.IsInstanceOfType(exception2, typeof(ArgumentOutOfRangeException));
            Assert.AreEqual("value", ((ArgumentOutOfRangeException)exception1).ParamName);
            Assert.AreEqual("value", ((ArgumentOutOfRangeException)exception2).ParamName);
        }
예제 #23
0
 public CriterionNodeViewModel(HierarchyViewModel hierarchy, CriterionNode criterion)
     : base(hierarchy)
 {
     Criterion = criterion;
     Name      = criterion.Name;
 }
예제 #24
0
 public void AddSubcriterion(CriterionNode parent, string name)
 {
     parent.AddSubcriterionNode(name);
     OnHierarchyChanged();
 }
예제 #25
0
 public void RemoveCriterion(CriterionNode criterion)
 {
     Hierarchy.RemoveCriterionNode(criterion);
     OnHierarchyChanged();
 }
        public void PairwiseComparison_ImportanceIndexerSetterAndGetter_NullNode_ThrowsArgumentNullException()
        {
            //Arrange
            var       node1      = new CriterionNode("Criterion1");
            var       node2      = new CriterionNode("Criterion2");
            var       comparison = new PairwiseComparison(new CriterionNode[] { node1, node2 });
            Exception exception1 = null;
            Exception exception2 = null;
            Exception exception3 = null;
            Exception exception4 = null;

            //Act
            try
            {
                comparison[node1, null] = 1M;
            }
            catch (Exception e)
            {
                exception1 = e;
            }

            try
            {
                comparison[null, node2] = 1M;
            }
            catch (Exception e)
            {
                exception2 = e;
            }

            try
            {
                var importance = comparison[node1, null];
            }
            catch (Exception e)
            {
                exception3 = e;
            }

            try
            {
                var importance = comparison[null, node2];
            }
            catch (Exception e)
            {
                exception4 = e;
            }

            //Assert
            Assert.IsNotNull(exception1);
            Assert.IsNotNull(exception2);
            Assert.IsNotNull(exception3);
            Assert.IsNotNull(exception4);
            Assert.IsInstanceOfType(exception1, typeof(ArgumentNullException));
            Assert.IsInstanceOfType(exception2, typeof(ArgumentNullException));
            Assert.IsInstanceOfType(exception3, typeof(ArgumentNullException));
            Assert.IsInstanceOfType(exception4, typeof(ArgumentNullException));
            Assert.AreEqual("node2", ((ArgumentNullException)exception1).ParamName);
            Assert.AreEqual("node1", ((ArgumentNullException)exception2).ParamName);
            Assert.AreEqual("node2", ((ArgumentNullException)exception3).ParamName);
            Assert.AreEqual("node1", ((ArgumentNullException)exception4).ParamName);
        }
        public void PairwiseComparison_ImportanceIndexerSetterGetter_InvalidNode_ThrowsKeyNotFoundException()
        {
            //Arrange
            var       node1      = new CriterionNode("Criterion1");
            var       node2      = new CriterionNode("Criterion2");
            var       nodeWrong  = new CriterionNode("Criterion3");
            var       comparison = new PairwiseComparison(new CriterionNode[] { node1, node2 });
            Exception exception1 = null;
            Exception exception2 = null;
            Exception exception3 = null;
            Exception exception4 = null;

            //Act
            try
            {
                comparison[node1, nodeWrong] = 1M;
            }
            catch (Exception e)
            {
                exception1 = e;
            }

            try
            {
                comparison[nodeWrong, node2] = 1M;
            }
            catch (Exception e)
            {
                exception2 = e;
            }

            try
            {
                var importance = comparison[node1, nodeWrong];
            }
            catch (Exception e)
            {
                exception3 = e;
            }

            try
            {
                var importance = comparison[nodeWrong, node2];
            }
            catch (Exception e)
            {
                exception4 = e;
            }

            //Assert
            Assert.IsNotNull(exception1);
            Assert.IsNotNull(exception2);
            Assert.IsNotNull(exception3);
            Assert.IsNotNull(exception4);
            Assert.IsInstanceOfType(exception1, typeof(KeyNotFoundException));
            Assert.IsInstanceOfType(exception2, typeof(KeyNotFoundException));
            Assert.IsInstanceOfType(exception3, typeof(KeyNotFoundException));
            Assert.IsInstanceOfType(exception4, typeof(KeyNotFoundException));
            Assert.AreEqual("Parameter node2 is not found in the nodes of the PairwiseComparison object.", exception1.Message);
            Assert.AreEqual("Parameter node1 is not found in the nodes of the PairwiseComparison object.", exception2.Message);
            Assert.AreEqual("Parameter node2 is not found in the nodes of the PairwiseComparison object.", exception3.Message);
            Assert.AreEqual("Parameter node1 is not found in the nodes of the PairwiseComparison object.", exception4.Message);
        }