public void AddTermination_Null_Exception()
        {
            var target = new OrTermination();

            ExceptionAssert.IsThrowing(new ArgumentNullException("termination"), () =>
            {
                target.AddTermination(null);
            });
        }
        public void AddTermination_Null_Exception()
        {
            var target = new OrTermination();
            var actual = Assert.Catch <ArgumentNullException>(() =>
            {
                target.AddTermination(null);
            });

            Assert.AreEqual("termination", actual.ParamName);
        }
        public void HasReached_LessThan2Terminations_Exception()
        {
            var target = new OrTermination();

            target.AddTermination(Substitute.For <ITermination>());

            Assert.Catch <InvalidOperationException>(() =>
            {
                target.HasReached(Substitute.For <IGeneticAlgorithm>());
            }, "The OrTermination needs at least 2 terminations to perform. Please, add the missing terminations.");
        }
        public void HasReached_LessThan2Terminations_Exception()
        {
            var target = new OrTermination();

            target.AddTermination(MockRepository.GenerateMock <ITermination>());

            ExceptionAssert.IsThrowing(new InvalidOperationException("The OrTermination needs at least 2 terminations to perform. Please, add the missing terminations."), () =>
            {
                target.HasReached(MockRepository.GenerateMock <IGeneticAlgorithm>());
            });
        }
        public void HasReached_OnlyOneTerminationsHasReached_True()
        {
            var target = new OrTermination();
            var ga     = Substitute.For <IGeneticAlgorithm>();

            var t1 = Substitute.For <ITermination>();

            t1.HasReached(ga).ReturnsForAnyArgs(false);
            target.AddTermination(t1);

            var t2 = Substitute.For <ITermination>();

            t2.HasReached(ga).ReturnsForAnyArgs(true);
            target.AddTermination(t2);

            var t3 = Substitute.For <ITermination>();

            t3.HasReached(ga).ReturnsForAnyArgs(false);
            target.AddTermination(t3);

            Assert.IsTrue(target.HasReached(ga));
        }
        public void HasReached_OnlyOneTerminationsHasReached_True()
        {
            var target = new OrTermination();
            var ga     = MockRepository.GenerateMock <IGeneticAlgorithm>();

            var t1 = MockRepository.GenerateMock <ITermination>();

            t1.Expect(t => t.HasReached(ga)).IgnoreArguments().Return(false);
            target.AddTermination(t1);

            var t2 = MockRepository.GenerateMock <ITermination>();

            t2.Expect(t => t.HasReached(ga)).IgnoreArguments().Return(true);
            target.AddTermination(t2);

            var t3 = MockRepository.GenerateMock <ITermination>();

            t3.Expect(t => t.HasReached(ga)).IgnoreArguments().Return(false);
            target.AddTermination(t3);

            Assert.IsTrue(target.HasReached(ga));
        }