Beispiel #1
0
        public void GeneticComponent_CreateNew()
        {
            TestComponent    component  = new TestComponent();
            GeneticComponent component2 = component.CreateNew();

            Assert.IsType <TestComponent>(component2);
            Assert.NotSame(component, component2);
        }
Beispiel #2
0
            public override bool IsValid(GeneticComponent component, out string errorMessage)
            {
                if (((TestComponent)component).IntValue == 5)
                {
                    errorMessage = "bad value";
                    return(false);
                }

                errorMessage = null;
                return(true);
            }
        /// <summary>
        /// Returns whether <paramref name="component"/> is valid.
        /// </summary>
        /// <param name="component"><see cref="GeneticComponent"/> to be validated.</param>
        /// <param name="errorMessage">Error message that should be displayed if the component fails validation.</param>
        /// <returns>True if <paramref name="component"/> is valid; otherwise, false.</returns>
        public override bool IsValid(GeneticComponent component, out string?errorMessage)
        {
            errorMessage = null;

            MultiPointCrossoverOperator crossoverOp = (MultiPointCrossoverOperator)component;

            if (((ListEntityBase?)crossoverOp.Algorithm?.GeneticEntitySeed)?.RequiresUniqueElementValues == true &&
                crossoverOp.CrossoverPointCount > 2)
            {
                errorMessage = StringUtil.GetFormattedString(Resources.ErrorMsg_MultiPointCrossoverOperationCrossoverPointValidator_ValidationError);
            }

            return(errorMessage == null);
        }
Beispiel #4
0
        /// <summary>
        /// Returns whether <paramref name="component"/> is valid.
        /// </summary>
        /// <param name="component"><see cref="GeneticComponent"/> to be validated.</param>
        /// <param name="errorMessage">Error message that should be displayed if the component fails validation.</param>
        /// <returns>True if <paramref name="component"/> is valid; otherwise, false.</returns>
        public override bool IsValid(GeneticComponent component, out string?errorMessage)
        {
            errorMessage = null;

            ListEntityBase entity = (ListEntityBase)component;

            if (entity.MinimumStartingLength > entity.MaximumStartingLength)
            {
                errorMessage = StringUtil.GetFormattedString(
                    Resources.ErrorMsg_MismatchedMinMaxValues,
                    nameof(ListEntityBase.MinimumStartingLength),
                    nameof(ListEntityBase.MaximumStartingLength));
            }

            return(errorMessage == null);
        }
        /// <summary>
        /// Checks whether the property is valid.
        /// </summary>
        /// <param name="validator"><see cref="ComponentValidator"/> to perform the validation.</param>
        /// <param name="component">The <see cref="GeneticComponent"/> to be validated.</param>
        public static void EnsureIsValid(this ComponentValidator validator, GeneticComponent component)
        {
            if (validator == null)
            {
                throw new ArgumentNullException(nameof(validator));
            }

            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            string?errorMessage;

            if (!validator.IsValid(component, out errorMessage))
            {
                throw new ValidationException(errorMessage !);
            }
        }
        public override sealed bool IsValid(GeneticComponent component, out string?errorMessage)
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            GeneticAlgorithm?algorithmContext;

            if (component is GeneticComponentWithAlgorithm componentWithAlg)
            {
                algorithmContext = componentWithAlg.Algorithm;
            }
            else
            {
                algorithmContext = component as GeneticAlgorithm;
            }

            if (algorithmContext is null)
            {
                throw new ArgumentException(
                          StringUtil.GetFormattedString(Resources.ErrorMsg_RequiredComponentValidator_NoAlgorithm,
                                                        typeof(GeneticAlgorithm), typeof(GeneticComponentWithAlgorithm)),
                          nameof(component));
            }

            if (!this.HasRequiredComponent(algorithmContext))
            {
                errorMessage = StringUtil.GetFormattedString(Resources.ErrorMsg_NoRequiredConfigurableType,
                                                             component.GetType().FullName, this.ComponentFriendlyName.ToLower(CultureInfo.CurrentCulture), this.RequiredComponentType.FullName);

                return(false);
            }

            errorMessage = null;
            return(true);
        }
 public override bool IsValid(GeneticComponent component, out string errorMessage)
 {
     throw new NotImplementedException();
 }
Beispiel #8
0
 public abstract bool IsValid(GeneticComponent component, out string?errorMessage);
 public bool TestIsEquivalentType(GeneticComponent configuredComponent)
 {
     return(this.IsEquivalentType(configuredComponent));
 }
 public override bool IsValid(GeneticComponent component, out string errorMessage)
 {
     Assert.Same(this.component, component);
     errorMessage = this.errorMessage;
     return(this.isValid);
 }
 public TestValidator(GeneticComponent component, bool isValid, string errorMessage)
 {
     this.component    = component;
     this.isValid      = isValid;
     this.errorMessage = errorMessage;
 }