#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using HeuristicLab.Problems.TestFunctions.MultiObjective; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace MultiObjectiveTestfunctionTests { [TestClass] public class InvertedGenerationalDistanceTest { [TestMethod] [ExpectedException(typeof(ArgumentException))] [TestCategory("Problems.TestFunctions")] [TestProperty("Time", "short")] public void EmptyOptimalFrontTest() { double[] point = new double[2]; point[0] = 0.5; point[1] = 0.5; double[][] front = { point }; double[][] referencefront = { }; InvertedGenerationalDistance.Calculate(front, referencefront, 1); } [TestMethod] [ExpectedException(typeof(ArgumentException))] [TestCategory("Problems.TestFunctions")] [TestProperty("Time", "short")] public void EmptyFrontTest() { double[] point = new double[2]; point[0] = 0.5; point[1] = 0.5; double[][] front = { }; double[][] referencefront = { point }; InvertedGenerationalDistance.Calculate(front, referencefront, 1); } [TestMethod] [TestCategory("Problems.TestFunctions")] [TestProperty("Time", "short")] public void SamePointTest() { double[] point = new double[2]; point[0] = 0.5; point[1] = 0.5; double[][] front = { point }; double[] point1 = new double[2]; point1[0] = 0.5; point1[1] = 0.5; double[][] referencefront = { point1 }; double dist = GenerationalDistance.Calculate(front, referencefront, 1); Assert.AreEqual(0, dist); } [TestMethod] [TestCategory("Problems.TestFunctions")] [TestProperty("Time", "short")] public void SinglePointTest() { double[] point = new double[2]; point[0] = 0; point[1] = 0; double[][] front = { point }; double[] point2 = new double[2]; point2[0] = 1; point2[1] = 1; double[][] referencefront = { point2 }; double dist = InvertedGenerationalDistance.Calculate(front, referencefront, 1); Assert.AreEqual(Math.Sqrt(2), dist); } [TestMethod] [TestCategory("Problems.TestFunctions")] [TestProperty("Time", "short")] public void DifferentSizesTest() { double[] point = new double[2]; point[0] = 0; point[1] = 0; double[] point1 = new double[2]; point1[0] = 1; point1[1] = 0.5; double[][] front = { point, point1 }; double[] point2 = new double[2]; point2[0] = 1; point2[1] = 0; double[][] referencefront = { point2 }; double dist = InvertedGenerationalDistance.Calculate(front, referencefront, 1); Assert.AreEqual(0.5, dist); } [TestMethod] [TestCategory("Problems.TestFunctions")] [TestProperty("Time", "short")] public void QuadraticTest() { double[] point = new double[2]; point[0] = 0; point[1] = 0; double[] point1 = new double[2]; point1[0] = 0; point1[1] = 1; double[][] front = { point, point1 }; double[] point2 = new double[2]; point2[0] = 1; point2[1] = 0; double[] point3 = new double[2]; point3[0] = 1; point3[1] = 1; double[][] referencefront = { point2, point3 }; double dist = InvertedGenerationalDistance.Calculate(front, referencefront, 1); Assert.AreEqual(1, dist); } } }