src/GenFx.Components.Tests/TreeEntityBaseTest.cs
/// <summary>
/// Tests that the GetPrefixTree method works correctly.
/// </summary>
Tests that the GetPrefixTree method works correctly.
Tests that the GetPrefixTree method works correctly .
[Fact]
        public void TreeEntityBase_GetPrefixTree()
        {
            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.GetPrefixTree();
            foreach (TreeNode node in nodes)
            {
                switch (loopCount)
                {
                    case 0:
                        Assert.Same(entity.RootNode, node);
                        break;
                    case 1:
                        Assert.Same(entity.RootNode.ChildNodes[0], node);
                        break;
                    case 2:
                        Assert.Same(entity.RootNode.ChildNodes[0].ChildNodes[0], node);
                        break;
                    case 3:
                        Assert.Same(entity.RootNode.ChildNodes[1], node);
                        break;
                    default:
                        Assert.True(false, "More nodes encountered than expected.");
                        break;
                }
                loopCount++;
            }
        }
[ Fact ] public void TreeEntityBase_GetPrefixTree ( ) { 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 . GetPrefixTree ( ) ; foreach ( TreeNode node in nodes ) { switch ( loopCount ) { case 0 : Assert . Same ( entity . RootNode , node ) ; break ; case 1 : Assert . Same ( entity . RootNode . ChildNodes [ 0 ] , node ) ; break ; case 2 : Assert . Same ( entity . RootNode . ChildNodes [ 0 ] . ChildNodes [ 0 ] , node ) ; break ; case 3 : Assert . Same ( entity . RootNode . ChildNodes [ 1 ] , node ) ; break ; default : Assert . True ( false , " " ) ; break ; } loopCount ++ ; } }
Tests that the GetPrefixTree method works correctly.
Tests that the GetPrefixTree method works correctly .