示例#1
0
        public void SortedSubsetOperatorBase_InsertGenesAtPositionWithConflict_ShouldReturns(bool leftConflict, bool rightConflict, bool expectedSuccess)
        {
            var geneValuesToInsert = new int[] { 10, 11, 12, 13 };
            var chromosome         = SortedSubsetTestData.CreateChromosome();
            var random             = Substitute.For <IRandom>();
            var parameterSet       = new ParameterSet();
            var conflictDetectors  = new List <INeighborhoodConflictDetector>()
            {
                new PredeterminedConflictDetector(leftConflict, rightConflict)
            };
            var operatorBase = new SortedSubsetOperatorBase(random, parameterSet, conflictDetectors);

            var success = operatorBase.InsertGenes(chromosome, 0, 1, geneValuesToInsert, 0, 1);

            success.Should().Be(expectedSuccess);
        }
示例#2
0
        public void SortedSubsetOperatorBase_InsertGenesAtPosition_ShouldInsert(int sectionIndex, int insertPosition, int firstGeneIndex, int count)
        {
            var geneValuesToInsert = new int[] { 10, 11, 12, 13 };

            var chromosome        = SortedSubsetTestData.CreateChromosome();
            var clone             = chromosome.DeepClone();
            var random            = Substitute.For <IRandom>();
            var parameterSet      = new ParameterSet();
            var conflictDetectors = new List <INeighborhoodConflictDetector>()
            {
                AllRightConflictDetector.Instance
            };
            var operatorBase = new SortedSubsetOperatorBase(random, parameterSet, conflictDetectors);

            operatorBase.InsertGenes(chromosome, sectionIndex, insertPosition, geneValuesToInsert, firstGeneIndex, count);

            chromosome.Sections[sectionIndex].Length.Should().Be(clone.Sections[sectionIndex].Length + count);
            chromosome.Sections[sectionIndex][insertPosition].Should().Be(geneValuesToInsert[firstGeneIndex]);
            chromosome.Sections[sectionIndex][insertPosition + count - 1].Should().Be(geneValuesToInsert[firstGeneIndex + count - 1]);
        }