Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Tests/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3/GenerationalDistanceTest.cs @ 16189

Last change on this file since 16189 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21using System;
22using Microsoft.VisualStudio.TestTools.UnitTesting;
23
24namespace HeuristicLab.Problems.TestFunctions.MultiObjective.Tests {
25  [TestClass]
26  public class GenerationalDistanceTest {
27
28    [TestMethod]
29    [ExpectedException(typeof(ArgumentException))]
30    [TestCategory("Problems.TestFunctions.MultiObjective")]
31    [TestProperty("Time", "short")]
32    public void GenerationalDistanceTestEmptyOptimalFront() {
33
34      double[] point = new double[2];
35      point[0] = 0.5;
36      point[1] = 0.5;
37      double[][] front = { point };
38      double[][] referencefront = { };
39      GenerationalDistance.Calculate(front, referencefront, 1);
40    }
41
42    [TestMethod]
43    [ExpectedException(typeof(ArgumentException))]
44    [TestCategory("Problems.TestFunctions.MultiObjective")]
45    [TestProperty("Time", "short")]
46    public void GenerationalDistanceTestEmptyFront() {
47
48      double[] point = new double[2];
49      point[0] = 0.5;
50      point[1] = 0.5;
51      double[][] front = { };
52      double[][] referencefront = { point };
53      GenerationalDistance.Calculate(front, referencefront, 1);
54    }
55
56    [TestMethod]
57    [TestCategory("Problems.TestFunctions.MultiObjective")]
58    [TestProperty("Time", "short")]
59    public void GenerationalDistanceTestSamePoint() {
60
61      double[] point = new double[2];
62      point[0] = 0.5;
63      point[1] = 0.5;
64      double[][] front = { point };
65      double[] point1 = new double[2];
66      point1[0] = 0.5;
67      point1[1] = 0.5;
68      double[][] referencefront = { point1 };
69      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
70      Assert.AreEqual(0, dist);
71    }
72
73    [TestMethod]
74    [TestCategory("Problems.TestFunctions.MultiObjective")]
75    [TestProperty("Time", "short")]
76    public void GenerationalDistanceTestSinglePoint() {
77      double[] point = new double[2];
78      point[0] = 0;
79      point[1] = 0;
80      double[][] front = { point };
81      double[] point2 = new double[2];
82      point2[0] = 1;
83      point2[1] = 1;
84      double[][] referencefront = { point2 };
85      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
86      Assert.AreEqual(Math.Sqrt(2), dist);
87    }
88
89    [TestMethod]
90    [TestCategory("Problems.TestFunctions.MultiObjective")]
91    [TestProperty("Time", "short")]
92    public void GenerationalDistanceTestDifferentSizes() {
93      double[] point = new double[2];
94      point[0] = 0;
95      point[1] = 0;
96      double[] point1 = new double[2];
97      point1[0] = 1;
98      point1[1] = 0.5;
99      double[][] front = { point, point1 };
100      double[] point2 = new double[2];
101      point2[0] = 1;
102      point2[1] = 0;
103      double[][] referencefront = { point2 };
104      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
105      Assert.AreEqual(0.75, dist);
106    }
107
108    [TestMethod]
109    [TestCategory("Problems.TestFunctions.MultiObjective")]
110    [TestProperty("Time", "short")]
111    public void GenerationalDistanceTestQuadratic() {
112      double[] point = new double[2];
113      point[0] = 0;
114      point[1] = 0;
115      double[] point1 = new double[2];
116      point1[0] = 0;
117      point1[1] = 1;
118      double[][] front = { point, point1 };
119      double[] point2 = new double[2];
120      point2[0] = 1;
121      point2[1] = 0;
122      double[] point3 = new double[2];
123      point3[0] = 1;
124      point3[1] = 1;
125      double[][] referencefront = { point2, point3 };
126      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
127      Assert.AreEqual(1, dist);
128    }
129  }
130}
Note: See TracBrowser for help on using the repository browser.