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
|
---|
21 | using System;
|
---|
22 | using HeuristicLab.Problems.TestFunctions.MultiObjective;
|
---|
23 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
24 |
|
---|
25 | namespace MultiObjectiveTestfunctionTests {
|
---|
26 | [TestClass]
|
---|
27 | public class InvertedGenerationalDistanceTest {
|
---|
28 |
|
---|
29 | [TestMethod]
|
---|
30 | [ExpectedException(typeof(ArgumentException))]
|
---|
31 | [TestCategory("Problems.TestFunctions")]
|
---|
32 | [TestProperty("Time", "short")]
|
---|
33 | public void EmptyOptimalFrontTest() {
|
---|
34 |
|
---|
35 | double[] point = new double[2];
|
---|
36 | point[0] = 0.5;
|
---|
37 | point[1] = 0.5;
|
---|
38 | double[][] front = { point };
|
---|
39 | double[][] referencefront = { };
|
---|
40 | InvertedGenerationalDistance.Calculate(front, referencefront, 1);
|
---|
41 | }
|
---|
42 |
|
---|
43 | [TestMethod]
|
---|
44 | [ExpectedException(typeof(ArgumentException))]
|
---|
45 | [TestCategory("Problems.TestFunctions")]
|
---|
46 | [TestProperty("Time", "short")]
|
---|
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 | InvertedGenerationalDistance.Calculate(front, referencefront, 1);
|
---|
55 | }
|
---|
56 |
|
---|
57 | [TestMethod]
|
---|
58 | [TestCategory("Problems.TestFunctions")]
|
---|
59 | [TestProperty("Time", "short")]
|
---|
60 | public void SamePointTest() {
|
---|
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")]
|
---|
75 | [TestProperty("Time", "short")]
|
---|
76 | public void SinglePointTest() {
|
---|
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 = InvertedGenerationalDistance.Calculate(front, referencefront, 1);
|
---|
86 | Assert.AreEqual(Math.Sqrt(2), dist);
|
---|
87 | }
|
---|
88 |
|
---|
89 | [TestMethod]
|
---|
90 | [TestCategory("Problems.TestFunctions")]
|
---|
91 | [TestProperty("Time", "short")]
|
---|
92 | public void DifferentSizesTest() {
|
---|
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 = InvertedGenerationalDistance.Calculate(front, referencefront, 1);
|
---|
105 | Assert.AreEqual(0.5, dist);
|
---|
106 | }
|
---|
107 |
|
---|
108 | [TestMethod]
|
---|
109 | [TestCategory("Problems.TestFunctions")]
|
---|
110 | [TestProperty("Time", "short")]
|
---|
111 | public void QuadraticTest() {
|
---|
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 = InvertedGenerationalDistance.Calculate(front, referencefront, 1);
|
---|
127 | Assert.AreEqual(1, dist);
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | }
|
---|