Ejemplo n.º 1
0
        public void AddConnectionMutation_Mutate_AddedConnection()
        {
            //ARRANGE
            var i = 0;

            _random.Next(Arg.Is <int>(2)).Returns(call =>
            {
                var ret = i;
                i       = i + 1;
                return(ret);
            });
            _random.NextDouble().ReturnsForAnyArgs(1.0);

            _innovationPointGenerator.GetNextInnovation().Returns(23);

            var genome = CreateGenome();

            var addConnectionMutator = new AddConnectionMutation(_innovationPointGenerator, _random, _config);

            //ACT
            var result = addConnectionMutator.Mutate(ref genome);

            //ASSERT
            Assert.IsTrue(result);

            Assert.AreEqual(1, genome.Connections.Count());

            Assert.AreEqual(1.0, genome.Connections.First().Value.Weight);
            Assert.AreEqual(23, genome.Connections.First().Value.Id);
        }
Ejemplo n.º 2
0
        public void AddConnectionMutation_Mutate_FailedToAddConnection()
        {
            //ARRANGE
            _random.Next(Arg.Is <int>(2)).Returns(1);
            _random.NextDouble().ReturnsForAnyArgs(1.0);

            var genome = CreateGenome();

            var addConnectionMutator = new AddConnectionMutation(_innovationPointGenerator, _random, _config);

            //ACT
            var result = addConnectionMutator.Mutate(ref genome);

            //ASSERT
            Assert.IsFalse(result);

            Assert.AreEqual(0, genome.Connections.Count());
        }