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 SpacingTest { |
---|
28 | |
---|
29 | |
---|
30 | [TestMethod] |
---|
31 | [ExpectedException(typeof(ArgumentException))] |
---|
32 | [TestCategory("Problems.TestFunctions")] |
---|
33 | [TestProperty("Time", "short")] |
---|
34 | public void EmptyFrontTest() { |
---|
35 | double[][] front = { }; |
---|
36 | |
---|
37 | Spacing.Calculate(front); |
---|
38 | } |
---|
39 | |
---|
40 | [TestMethod] |
---|
41 | [TestCategory("Problems.TestFunctions")] |
---|
42 | [TestProperty("Time", "short")] |
---|
43 | public void SamePointTest() { |
---|
44 | |
---|
45 | double[] point = new double[2]; |
---|
46 | point[0] = 0.5; |
---|
47 | point[1] = 0.5; |
---|
48 | |
---|
49 | double[] point1 = new double[2]; |
---|
50 | point1[0] = 0.5; |
---|
51 | point1[1] = 0.5; |
---|
52 | double[][] front = { point, point1 }; |
---|
53 | double dist = Spacing.Calculate(front); |
---|
54 | Assert.AreEqual(0, dist); |
---|
55 | } |
---|
56 | |
---|
57 | [TestMethod] |
---|
58 | [TestCategory("Problems.TestFunctions")] |
---|
59 | [TestProperty("Time", "short")] |
---|
60 | public void SinglePointTest() { |
---|
61 | double[] point = new double[2]; |
---|
62 | point[0] = 0; |
---|
63 | point[1] = 0; |
---|
64 | double[][] front = { point }; |
---|
65 | double dist = Spacing.Calculate(front); |
---|
66 | Assert.AreEqual(0, dist); |
---|
67 | } |
---|
68 | |
---|
69 | [TestMethod] |
---|
70 | [TestCategory("Problems.TestFunctions")] |
---|
71 | [TestProperty("Time", "short")] |
---|
72 | public void QuadraticTest() { |
---|
73 | double[] point = new double[2]; |
---|
74 | point[0] = 0; |
---|
75 | point[1] = 0; |
---|
76 | double[] point1 = new double[2]; |
---|
77 | point1[0] = 0; |
---|
78 | point1[1] = 1; |
---|
79 | |
---|
80 | double[] point2 = new double[2]; |
---|
81 | point2[0] = 1; |
---|
82 | point2[1] = 0; |
---|
83 | double[] point3 = new double[2]; |
---|
84 | point3[0] = 1; |
---|
85 | point3[1] = 1; |
---|
86 | double[][] front = { point, point1, point2, point3 }; |
---|
87 | double dist = Spacing.Calculate(front); |
---|
88 | Assert.AreEqual(0, dist); |
---|
89 | } |
---|
90 | |
---|
91 | [TestMethod] |
---|
92 | [TestCategory("Problems.TestFunctions")] |
---|
93 | [TestProperty("Time", "short")] |
---|
94 | public void RectangularTest() { |
---|
95 | double[] point = new double[2]; |
---|
96 | point[0] = 0; |
---|
97 | point[1] = 0; |
---|
98 | double[] point1 = new double[2]; |
---|
99 | point1[0] = 0; |
---|
100 | point1[1] = 1; |
---|
101 | |
---|
102 | double[] point2 = new double[2]; |
---|
103 | point2[0] = 2; |
---|
104 | point2[1] = 0; |
---|
105 | double[] point3 = new double[2]; |
---|
106 | point3[0] = 2; |
---|
107 | point3[1] = 1; |
---|
108 | double[][] front = { point, point1, point2, point3 }; |
---|
109 | double dist = Spacing.Calculate(front); |
---|
110 | Assert.AreEqual(0, dist); |
---|
111 | } |
---|
112 | |
---|
113 | /// <summary> |
---|
114 | /// deltoid with 3 points of the 1-unit-square and the northeastern point at 4,4 |
---|
115 | /// which gives d=(1,1,1,5) for minimal distances. Mean of d is 2 and variance of d is 3 |
---|
116 | /// Spacing is defined as the standarddeviation of d |
---|
117 | /// </summary> |
---|
118 | [TestMethod] |
---|
119 | [TestCategory("Problems.TestFunctions")] |
---|
120 | [TestProperty("Time", "short")] |
---|
121 | public void DeltoidTest() { |
---|
122 | double[] point = new double[2]; |
---|
123 | point[0] = 0; |
---|
124 | point[1] = 0; |
---|
125 | double[] point1 = new double[2]; |
---|
126 | point1[0] = 0; |
---|
127 | point1[1] = 1; |
---|
128 | |
---|
129 | double[] point2 = new double[2]; |
---|
130 | point2[0] = 1; |
---|
131 | point2[1] = 0; |
---|
132 | double[] point3 = new double[2]; |
---|
133 | point3[0] = 4; |
---|
134 | point3[1] = 4; |
---|
135 | double[][] front = { point, point1, point2, point3 }; |
---|
136 | double dist = Spacing.Calculate(front); |
---|
137 | Assert.AreEqual(Math.Sqrt(3), dist); |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | } |
---|