Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/LPConvexHullSortingTest.cs @ 10105

Last change on this file since 10105 was 10060, checked in by ascheibe, 11 years ago

#1886

  • added point calculation from distance matrices
  • added convex hull algorithm based on LP (work in progress)
  • added unit tests
File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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
22using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24
25namespace AlgorithmBehaviorUnitTests {
26  [TestClass]
27  public class LPConvexHullSortingTest {
28    [TestMethod]
29    public void TestSorting() {
30      int size = 4;
31      int dimension = 2;
32
33      double[][] points = new double[size][];
34      points[0] = new double[] { 2, 3 };
35      points[1] = new double[] { 6, 4 };
36      points[2] = new double[] { 12, 13 };
37      points[3] = new double[] { 21, 31 };
38
39      var result = LPHull.SortA(points);
40
41      for (int i = 0; i < size; i++) {
42        for (int j = 0; j < dimension; j++) {
43          Assert.AreEqual(points[i][j], result[size - i - 1][j]);
44        }
45      }
46    }
47
48    [TestMethod]
49    public void TestSortingNegative() {
50      int size = 4;
51      int dimension = 2;
52
53      double[][] points = new double[size][];
54      points[0] = new double[] { -6, -4 };
55      points[1] = new double[] { -2, -3 };
56      points[2] = new double[] { 12, 13 };
57      points[3] = new double[] { 21, 31 };
58
59      var result = LPHull.SortA(points);
60
61      for (int i = 0; i < size; i++) {
62        for (int j = 0; j < dimension; j++) {
63          Assert.AreEqual(points[i][j], result[size - i - 1][j]);
64        }
65      }
66    }
67
68    [TestMethod]
69    public void TestSortingMixed() {
70      int size = 4;
71
72      double[][] points = new double[size][];
73      points[0] = new double[] { -6, -4 };
74      points[2] = new double[] { 5, 13 };
75      points[1] = new double[] { -2, -3 };
76      points[3] = new double[] { 21, 31 };
77
78      var result = LPHull.SortA(points);
79
80      Assert.AreEqual(21, result[0][0]);
81      Assert.AreEqual(5, result[1][0]);
82      Assert.AreEqual(-2, result[2][0]);
83      Assert.AreEqual(-6, result[3][0]);
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.