Пример #1
0
        public void ExtractActiveParametersThrowsForParametersNull()
        {
            var specification = new ParameterConfigurationSpaceSpecification(
                new List <IParameterNode> {
                new ValueNode <double>("a", new ContinuousDomain())
            },
                new Dictionary <string, List <EqualsCondition> >(),
                new List <ForbiddenParameterCombination>());

            Assert.Throws <ArgumentNullException>(() => specification.ExtractActiveParameters(parameters: null));
        }
Пример #2
0
        public void ExtractActiveParametersRemovesInactiveParameters()
        {
            var parameters = new List <IParameterNode>
            {
                new ValueNode <int>("unconditional", new IntegerDomain()),
                new ValueNode <double>("unconditional_2", new ContinuousDomain()),
                new ValueNode <int>("conditions_met", new IntegerDomain()),
                new ValueNode <int>("one_condition_met", new IntegerDomain()),
            };
            var conditionsMet = new List <EqualsCondition>
            {
                new EqualsCondition("unconditional", new IAllele[] { new Allele <int>(214) }),
                new EqualsCondition("unconditional_2", new IAllele[] { new Allele <double>(-4) }),
            };
            var oneConditionMet = new List <EqualsCondition>
            {
                new EqualsCondition("unconditional", new IAllele[] { new Allele <int>(214) }),
                new EqualsCondition("unconditional_2", new IAllele[] { new Allele <double>(-8) }),
            };
            var specification = new ParameterConfigurationSpaceSpecification(
                parameters,
                new Dictionary <string, List <EqualsCondition> > {
                { "conditions_met", conditionsMet }, { "one_condition_met", oneConditionMet }
            },
                new List <ForbiddenParameterCombination>());

            var parameterValues = new Dictionary <string, IAllele>
            {
                ["unconditional"]     = new Allele <int>(214),
                ["unconditional_2"]   = new Allele <double>(-4),
                ["conditions_met"]    = new Allele <int>(24),
                ["one_condition_met"] = new Allele <int>(23),
            };
            var activeParameters = specification.ExtractActiveParameters(parameterValues);

            Assert.Equal(
                3,
                activeParameters.Count);
            foreach (var expectedParameter in parameterValues.Where(p => !Equals("one_condition_met", p.Key)))
            {
                if (!activeParameters.TryGetValue(expectedParameter.Key, out var activeValue))
                {
                    Assert.True(false, $"{expectedParameter.Key} should be active.");
                }

                Assert.Equal(
                    expectedParameter.Value,
                    activeValue);
            }
        }