Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13729 was 13729, checked in by bwerth, 9 years ago

#1087 annotated unit tests

File size: 4.2 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    [TestCategory("Problems.TestFunctions")]
36    [TestProperty("Time", "short")]
37    public void EmptyOptimalFrontTest() {
38
39      double[] point = new double[2];
40      point[0] = 0.5;
41      point[1] = 0.5;
42      double[][] front = { point };
43      double[][] referencefront = { };
44      GenerationalDistance.Calculate(front, referencefront, 1);
45    }
46
47    [TestMethod]
48    [ExpectedException(typeof(ArgumentException))]
49    [TestCategory("Problems.TestFunctions")]
50    [TestProperty("Time", "short")]
51    public void EmptyFrontTest() {
52
53      double[] point = new double[2];
54      point[0] = 0.5;
55      point[1] = 0.5;
56      double[][] front = { };
57      double[][] referencefront = { point };
58      GenerationalDistance.Calculate(front, referencefront, 1);
59    }
60
61    [TestMethod]
62    [TestCategory("Problems.TestFunctions")]
63    [TestProperty("Time", "short")]
64    public void SamePointTest() {
65
66      double[] point = new double[2];
67      point[0] = 0.5;
68      point[1] = 0.5;
69      double[][] front = { point };
70      double[] point1 = new double[2];
71      point1[0] = 0.5;
72      point1[1] = 0.5;
73      double[][] referencefront = { point1 };
74      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
75      Assert.AreEqual(0, dist);
76    }
77
78    [TestMethod]
79    [TestCategory("Problems.TestFunctions")]
80    [TestProperty("Time", "short")]
81    public void SinglePointTest() {
82      double[] point = new double[2];
83      point[0] = 0;
84      point[1] = 0;
85      double[][] front = { point };
86      double[] point2 = new double[2];
87      point2[0] = 1;
88      point2[1] = 1;
89      double[][] referencefront = { point2 };
90      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
91      Assert.AreEqual(Math.Sqrt(2), dist);
92    }
93
94    [TestMethod]
95    [TestCategory("Problems.TestFunctions")]
96    [TestProperty("Time", "short")]
97    public void DifferentSizesTest() {
98      double[] point = new double[2];
99      point[0] = 0;
100      point[1] = 0;
101      double[] point1 = new double[2];
102      point1[0] = 1;
103      point1[1] = 0.5;
104      double[][] front = { point, point1 };
105      double[] point2 = new double[2];
106      point2[0] = 1;
107      point2[1] = 0;
108      double[][] referencefront = { point2 };
109      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
110      Assert.AreEqual(0.75, dist);
111    }
112
113    [TestMethod]
114    [TestCategory("Problems.TestFunctions")]
115    [TestProperty("Time", "short")]
116    public void QuadraticTest() {
117      double[] point = new double[2];
118      point[0] = 0;
119      point[1] = 0;
120      double[] point1 = new double[2];
121      point1[0] = 0;
122      point1[1] = 1;
123      double[][] front = { point, point1 };
124      double[] point2 = new double[2];
125      point2[0] = 1;
126      point2[1] = 0;
127      double[] point3 = new double[2];
128      point3[0] = 1;
129      point3[1] = 1;
130      double[][] referencefront = { point2, point3 };
131      double dist = GenerationalDistance.Calculate(front, referencefront, 1);
132      Assert.AreEqual(1, dist);
133    }
134
135
136
137  }
138
139
140}
Note: See TracBrowser for help on using the repository browser.