Beispiel #1
0
        public void TreeEntityBase_GetPostfixTree()
        {
            GeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                PopulationSeed    = new MockPopulation(),
                SelectionOperator = new MockSelectionOperator(),
                FitnessEvaluator  = new MockFitnessEvaluator(),
                GeneticEntitySeed = new TestTreeEntity()
            };
            TestTreeEntity entity = new TestTreeEntity();

            entity.Initialize(algorithm);

            entity.SetRootNode(new TreeNode());
            entity.RootNode.AppendChild(new TreeNode());
            entity.RootNode.ChildNodes[0].AppendChild(new TreeNode());
            entity.RootNode.AppendChild(new TreeNode());

            int loopCount = 0;
            IEnumerable <TreeNode> nodes = entity.GetPostfixTree();

            foreach (TreeNode node in nodes)
            {
                switch (loopCount)
                {
                case 0:
                    Assert.Same(entity.RootNode.ChildNodes[0].ChildNodes[0], node);
                    break;

                case 1:
                    Assert.Same(entity.RootNode.ChildNodes[0], node);
                    break;

                case 2:
                    Assert.Same(entity.RootNode.ChildNodes[1], node);
                    break;

                case 3:
                    Assert.Same(entity.RootNode, node);
                    break;

                default:
                    Assert.True(false, "More nodes encountered than expected.");
                    break;
                }
                loopCount++;
            }
        }