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 |
|
---|
22 | using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
|
---|
23 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
24 |
|
---|
25 | namespace 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 | }
|
---|