Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3/SpacingTest.cs @ 14385

Last change on this file since 14385 was 14121, checked in by mkommend, 8 years ago

#1087: Copied unit tests from branch and adapted path of multi-objective test function project file.

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