예제 #1
0
        public static FireworkExplosion CreateFireworkExplosion(Firework epicenter)
        {
            Dictionary <FireworkType, int> sparks = Substitute.For <Dictionary <FireworkType, int> >();
            FireworkExplosion explosion           = Substitute.For <FireworkExplosion>(epicenter, 1, Amplitude, sparks);

            return(explosion);
        }
예제 #2
0
        public void MutateFirework_PassEachParameterAsNullAndOtherIsCorrect_ArgumentNullExceptionThrown(
            MutableFirework mutableFirework, FireworkExplosion explosion, String expectedParamName)
        {
            ISparkGenerator            generator = CreateAttractRepulseSparkGenerator();
            AttractRepulseSparkMutator mutator   = new AttractRepulseSparkMutator(generator);

            ArgumentException exception = Assert.Throws <ArgumentNullException>(() => mutator.MutateFirework(ref mutableFirework, explosion));

            Assert.Equal(expectedParamName, exception.ParamName);
        }
예제 #3
0
        public void MutateFirework_PassValidParameters_ShouldChangeFireworkState()
        {
            Range             range      = new Range(-10, 10);
            IList <Dimension> dimensions = new List <Dimension>();

            dimensions.Add(new Dimension(range));
            dimensions.Add(new Dimension(range));
            dimensions.Add(new Dimension(range));

            IDictionary <Dimension, double> coordinatesBefore = new Dictionary <Dimension, double>();
            IDictionary <Dimension, double> coordinatesAfter  = new Dictionary <Dimension, double>();

            foreach (Dimension dimension in dimensions)
            {
                coordinatesBefore.Add(dimension, 0);
                coordinatesAfter.Add(dimension, 1);
            }

            MutableFirework mutableFirework = new MutableFirework(FireworkType.SpecificSpark, 0, coordinatesBefore);
            MutableFirework mutateFirework  = new MutableFirework(FireworkType.SpecificSpark, 1, coordinatesAfter); //present state mutable firework after mutate

            FireworkExplosion explosion = CreateFireworkExplosion(mutableFirework);
            ISparkGenerator   generator = CreateAttractRepulseSparkGenerator();

            generator.CreateSpark(explosion).Returns(mutateFirework);
            AttractRepulseSparkMutator mutator = Substitute.For <AttractRepulseSparkMutator>(generator);

            mutator.MutateFirework(ref mutableFirework, explosion);

            Assert.NotNull(mutableFirework);
            Assert.Equal(mutableFirework.BirthStepNumber, mutateFirework.BirthStepNumber);
            Assert.Equal(mutableFirework.Quality, mutateFirework.Quality);
            double dimensionValueBefore;
            double dimensionValueAfter;

            foreach (Dimension dimension in dimensions)
            {
                mutableFirework.Coordinates.TryGetValue(dimension, out dimensionValueBefore);
                mutateFirework.Coordinates.TryGetValue(dimension, out dimensionValueAfter);
                Assert.Equal(dimensionValueBefore, dimensionValueAfter);
            }
        }
예제 #4
0
        /// <summary>
        /// Changes the <paramref name="firework"/>.
        /// </summary>
        /// <param name="firework">The <see cref="MutableFirework"/> to be changed.</param>
        /// <param name="explosion">The <see cref="FireworkExplosion"/> that
        /// contains explosion characteristics.</param>
        /// <exception cref="System.ArgumentNullException"> if <paramref name="firework"/>
        /// or <paramref name="explosion"/> is <c>null</c>.</exception>
        public void MutateFirework(ref MutableFirework firework, FireworkExplosion explosion)
        {
            if (firework == null)
            {
                throw new ArgumentNullException(nameof(firework));
            }

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

            Debug.Assert(this.generator != null, "Generator is null");

            Firework newState = this.generator.CreateSpark(explosion);

            Debug.Assert(newState != null, "New state is null");

            firework.Update(newState);
        }
예제 #5
0
        public void CreateSpark_MustReturnNotNullFirework()
        {
            const int          expectedBirthStepNumber = 1;
            const FireworkType expectedFireworkType    = FireworkType.SpecificSpark;

            Solution          bestSolution = Substitute.For <Solution>(0);
            IList <Dimension> dimensions   = Substitute.For <IList <Dimension> >();

            System.Random randomizer = Substitute.For <System.Random>();
            ContinuousUniformDistribution distribution = Substitute.For <ContinuousUniformDistribution>(AbstractSourceData.Amplitude - AbstractSourceData.Delta, AbstractSourceData.Amplitude + AbstractSourceData.Delta);
            Firework                       epicenter   = Substitute.For <Firework>(expectedFireworkType, expectedBirthStepNumber - 1);
            IEnumerable <double>           qualities   = Substitute.For <IEnumerable <double> >();
            Dictionary <FireworkType, int> sparks      = Substitute.For <Dictionary <FireworkType, int> >();
            FireworkExplosion              explosion   = Substitute.For <FireworkExplosion>(epicenter, expectedBirthStepNumber, AbstractSourceData.Amplitude, sparks);

            AttractRepulseSparkGenerator sparkGenerator = new AttractRepulseSparkGenerator(bestSolution, dimensions, distribution, randomizer);

            Firework spark = sparkGenerator.CreateSpark(explosion);

            Assert.NotNull(spark);
            Assert.Equal(expectedFireworkType, spark.FireworkType);
            Assert.Equal(expectedBirthStepNumber, spark.BirthStepNumber);
        }