Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/MultiObjectiveTestfunctionTests/SpacingTest.cs @ 13673

Last change on this file since 13673 was 13673, checked in by bwerth, 8 years ago

#1087 fixed bug in DTLZ1, DTLZ3 and DTLZ7

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