Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/ConvexHullTest.cs @ 11144

Last change on this file since 11144 was 10222, checked in by ascheibe, 11 years ago

#1886

  • improved qhull wrapper
  • cleaned up unit tests
File size: 2.2 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 System;
23using System.Linq;
24using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
25using HeuristicLab.Common;
26using Microsoft.VisualStudio.TestTools.UnitTesting;
27
28namespace AlgorithmBehaviorUnitTests {
29  [TestClass]
30  public class ConvexHullTest {
31    [TestMethod]
32    public void TestConvexHullAlgorithms() {
33      int nrOfSamples = 50;
34      int dimension = 4;
35      double[][] inputs = CreateRandomData(nrOfSamples, dimension);
36
37      var lpResult = LPHull.Calculate(inputs);
38      var qhResult = QhullWrapper.Calculate(inputs.ToList());
39
40      foreach (var qhr in qhResult) {
41        bool found = false;
42        foreach (var lpr in lpResult) {
43          int i = 0;
44          for (i = 0; i < lpr.Count(); i++) {
45            if (!qhr[i].IsAlmost(lpr[i])) {
46              break;
47            }
48          }
49          if (i == lpr.Count()) {
50            found = true;
51            break;
52          }
53        }
54        Assert.IsTrue(found);
55      }
56    }
57
58    public static double[][] CreateRandomData(int n, int m) {
59      double[][] result = new double[n][];
60      Random rand = new Random();
61
62      for (int i = 0; i < n; i++) {
63        result[i] = new double[m];
64        for (int j = 0; j < m; j++) {
65          result[i][j] = (double)rand.Next(1, 60);
66        }
67      }
68      return result;
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.