public void SinglePointCrossoverCrossTest() {
   SinglePointCrossover_Accessor target = new SinglePointCrossover_Accessor(new PrivateObject(typeof(SinglePointCrossover)));
   ItemArray<BinaryVector> parents;
   TestRandom random = new TestRandom();
   bool exceptionFired;
   // The following test checks if there is an exception when there are more than 2 parents
   random.Reset();
   parents = new ItemArray<BinaryVector>(new BinaryVector[] { new BinaryVector(5), new BinaryVector(6), new BinaryVector(4) });
   exceptionFired = false;
   try {
     BinaryVector actual;
     actual = target.Cross(random, parents);
   } catch (ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
   // The following test checks if there is an exception when there are less than 2 parents
   random.Reset();
   parents = new ItemArray<BinaryVector>(new BinaryVector[] { new BinaryVector(4) });
   exceptionFired = false;
   try {
     BinaryVector actual;
     actual = target.Cross(random, parents);
   } catch (ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
 }
示例#2
0
        public void SinglePointCrossoverCrossTest()
        {
            SinglePointCrossover_Accessor target = new SinglePointCrossover_Accessor(new PrivateObject(typeof(SinglePointCrossover)));
            ItemArray <BinaryVector>      parents;
            TestRandom random = new TestRandom();
            bool       exceptionFired;

            // The following test checks if there is an exception when there are more than 2 parents
            random.Reset();
            parents        = new ItemArray <BinaryVector>(new BinaryVector[] { new BinaryVector(5), new BinaryVector(6), new BinaryVector(4) });
            exceptionFired = false;
            try {
                BinaryVector actual;
                actual = target.Cross(random, parents);
            } catch (ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
            // The following test checks if there is an exception when there are less than 2 parents
            random.Reset();
            parents        = new ItemArray <BinaryVector>(new BinaryVector[] { new BinaryVector(4) });
            exceptionFired = false;
            try {
                BinaryVector actual;
                actual = target.Cross(random, parents);
            } catch (ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }