Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Tests/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3/InvertedGenerationalDistanceTest.cs @ 14536

Last change on this file since 14536 was 14121, checked in by mkommend, 8 years ago

#1087: Copied unit tests from branch and adapted path of multi-objective test function project file.

File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 InvertedGenerationalDistanceTest {
27
28    [TestMethod]
29    [ExpectedException(typeof(ArgumentException))]
30    [TestCategory("Problems.TestFunctions.MultiObjective")]
31    [TestProperty("Time", "short")]
32    public void InvertedGenerationalDistanceTestEmptyOptimalFront() {
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      InvertedGenerationalDistance.Calculate(front, referencefront, 1);
40    }
41
42    [TestMethod]
43    [ExpectedException(typeof(ArgumentException))]
44    [TestCategory("Problems.TestFunctions.MultiObjective")]
45    [TestProperty("Time", "short")]
46    public void InvertedGenerationalDistanceTestEmptyFront() {
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      InvertedGenerationalDistance.Calculate(front, referencefront, 1);
54    }
55
56    [TestMethod]
57    [TestCategory("Problems.TestFunctions.MultiObjective")]
58    [TestProperty("Time", "short")]
59    public void InvertedGenerationalDistanceTestSamePoint() {
60      double[] point = new double[2];
61      point[0] = 0.5;
62      point[1] = 0.5;
63      double[][] front = { point };
64      double[] point1 = new double[2];
65      point1[0] = 0.5;
66      point1[1] = 0.5;
67      double[][] referencefront = { point1 };
68      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
69      Assert.AreEqual(0, dist);
70    }
71
72    [TestMethod]
73    [TestCategory("Problems.TestFunctions.MultiObjective")]
74    [TestProperty("Time", "short")]
75    public void InvertedGenerationalDistanceTestSinglePoint() {
76      double[] point = new double[2];
77      point[0] = 0;
78      point[1] = 0;
79      double[][] front = { point };
80      double[] point2 = new double[2];
81      point2[0] = 1;
82      point2[1] = 1;
83      double[][] referencefront = { point2 };
84      double dist = InvertedGenerationalDistance.Calculate(front, referencefront, 1);
85      Assert.AreEqual(Math.Sqrt(2), dist);
86    }
87
88    [TestMethod]
89    [TestCategory("Problems.TestFunctions.MultiObjective")]
90    [TestProperty("Time", "short")]
91    public void InvertedGenerationalDistanceTestDifferentSizes() {
92      double[] point = new double[2];
93      point[0] = 0;
94      point[1] = 0;
95      double[] point1 = new double[2];
96      point1[0] = 1;
97      point1[1] = 0.5;
98      double[][] front = { point, point1 };
99      double[] point2 = new double[2];
100      point2[0] = 1;
101      point2[1] = 0;
102      double[][] referencefront = { point2 };
103      double dist = InvertedGenerationalDistance.Calculate(front, referencefront, 1);
104      Assert.AreEqual(0.5, dist);
105    }
106
107    [TestMethod]
108    [TestCategory("Problems.TestFunctions.MultiObjective")]
109    [TestProperty("Time", "short")]
110    public void InvertedGenerationalDistanceTestQuadratic() {
111      double[] point = new double[2];
112      point[0] = 0;
113      point[1] = 0;
114      double[] point1 = new double[2];
115      point1[0] = 0;
116      point1[1] = 1;
117      double[][] front = { point, point1 };
118      double[] point2 = new double[2];
119      point2[0] = 1;
120      point2[1] = 0;
121      double[] point3 = new double[2];
122      point3[0] = 1;
123      point3[1] = 1;
124      double[][] referencefront = { point2, point3 };
125      double dist = InvertedGenerationalDistance.Calculate(front, referencefront, 1);
126      Assert.AreEqual(1, dist);
127    }
128  }
129
130
131}
Note: See TracBrowser for help on using the repository browser.