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