Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/MultiObjectiveTestfunctionTests/GenerationalDistanceTest.cs @ 13673

Last change on this file since 13673 was 13673, checked in by bwerth, 8 years ago

#1087 fixed bug in DTLZ1, DTLZ3 and DTLZ7

File size: 3.7 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 HeuristicLab.Problems.MultiObjectiveTestFunctions;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24
25namespace MultiObjectiveTestfunctionTests {
26  [TestClass]
27  public class GenerationalDistanceTest {
28
29
30
31
32
33    [TestMethod]
34    [ExpectedException(typeof(ArgumentException))]
35    public void EmptyOptimalFrontTest() {
36
37      double[] point = new double[2];
38      point[0] = 0.5;
39      point[1] = 0.5;
40      double[][] front = { point };
41      double[][] referencefront = { };
42      GenerationalDistance.Calculate(front, referencefront, 1);
43    }
44
45    [TestMethod]
46    [ExpectedException(typeof(ArgumentException))]
47    public void EmptyFrontTest() {
48
49      double[] point = new double[2];
50      point[0] = 0.5;
51      point[1] = 0.5;
52      double[][] front = { };
53      double[][] referencefront = { point };
54      GenerationalDistance.Calculate(front, referencefront, 1);
55    }
56
57    [TestMethod]
58    public void SamePointTest() {
59
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    public void SinglePointTest() {
74      double[] point = new double[2];
75      point[0] = 0;
76      point[1] = 0;
77      double[][] front = { point };
78      double[] point2 = new double[2];
79      point2[0] = 1;
80      point2[1] = 1;
81      double[][] referencefront = { point2 };
82      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
83      Assert.AreEqual(Math.Sqrt(2), dist);
84    }
85
86    [TestMethod]
87    public void DifferentSizesTest() {
88      double[] point = new double[2];
89      point[0] = 0;
90      point[1] = 0;
91      double[] point1 = new double[2];
92      point1[0] = 1;
93      point1[1] = 0.5;
94      double[][] front = { point, point1 };
95      double[] point2 = new double[2];
96      point2[0] = 1;
97      point2[1] = 0;
98      double[][] referencefront = { point2 };
99      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
100      Assert.AreEqual(0.75, dist);
101    }
102
103    [TestMethod]
104    public void QuadraticTest() {
105      double[] point = new double[2];
106      point[0] = 0;
107      point[1] = 0;
108      double[] point1 = new double[2];
109      point1[0] = 0;
110      point1[1] = 1;
111      double[][] front = { point, point1 };
112      double[] point2 = new double[2];
113      point2[0] = 1;
114      point2[1] = 0;
115      double[] point3 = new double[2];
116      point3[0] = 1;
117      point3[1] = 1;
118      double[][] referencefront = { point2, point3 };
119      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
120      Assert.AreEqual(1, dist);
121    }
122
123
124
125  }
126
127
128}
Note: See TracBrowser for help on using the repository browser.