Esempio n. 1
0
        /// <summary>
        /// Tries the find a <see cref="ForbiddenParameterCombination"/> which is met.
        /// </summary>
        /// <param name="genome">The genome specifying the parameter values.</param>
        /// <param name="combination">The found combination. May be <c>null</c>.</param>
        /// <returns><c>true</c> if a combination was found.</returns>
        private bool TryFindForbiddenCombination(Genome genome, out ForbiddenParameterCombination combination)
        {
            // Only check relevant rules, i.e. rules on active parameters.
            var activeParameters =
                this._parameterSpecification.ExtractActiveParameters(genome.GetFilteredGenes(this._parameterTree));

            combination = this._parameterSpecification.ForbiddenParameterCombinations
                          .FirstOrDefault(rule => rule.IsMet(activeParameters));
            return(combination != null);
        }
Esempio n. 2
0
        public void ToStringDescribesCompleteCombination()
        {
            var forbiddenParameters = new Dictionary <string, IAllele>
            {
                { "a", new Allele <int>(3) },
                { "b", new Allele <string>("bad") },
            };
            var combination = new ForbiddenParameterCombination(forbiddenParameters);

            Assert.Equal("{a=3, b=bad}", combination.ToString());
        }
Esempio n. 3
0
        public void IsMetReturnsFalseForMissingParameter()
        {
            var forbiddenParameters = new Dictionary <string, IAllele>
            {
                { "a", new Allele <int>(3) },
                { "b", new Allele <string>("bad") },
            };
            var combination = new ForbiddenParameterCombination(forbiddenParameters);

            this._parameters.Add("b", new Allele <string>("bad"));

            Assert.False(combination.IsMet(this._parameters), "Condition should not be met without 'b'.");
        }
Esempio n. 4
0
        public void IsMetReturnsTrueForForbiddenCombination()
        {
            var forbiddenParameters = new Dictionary <string, IAllele>
            {
                { "a", new Allele <int>(3) },
                { "b", new Allele <string>("bad") },
            };
            var combination = new ForbiddenParameterCombination(forbiddenParameters);

            this._parameters.Add("c", new Allele <int>(3));
            this._parameters.Add("a", new Allele <int>(3));
            this._parameters.Add("b", new Allele <string>("bad"));

            Assert.True(combination.IsMet(this._parameters), "Expected the condition to be met.");
        }
Esempio n. 5
0
 /// <summary>
 /// Checks whether a <see cref="ForbiddenParameterCombination"/> is as expected.
 /// </summary>
 /// <param name="expectedCombination">The expected combination.</param>
 /// <param name="actual">The actual combination.</param>
 private static void CheckForbiddenCombination(Dictionary <string, IAllele> expectedCombination, ForbiddenParameterCombination actual)
 {
     Assert.True(actual.IsMet(expectedCombination), "Combination is too strict.");
     foreach (var definition in expectedCombination)
     {
         var subset = new Dictionary <string, IAllele>(expectedCombination);
         subset.Remove(definition.Key);
         Assert.False(
             actual.IsMet(subset),
             $"Combination is not strict enough: Is also met without {definition.Key}.");
     }
 }