enhanced motor handling, bug fixes, initial optimization code
[debian/openrocket] / test / net / sf / openrocket / optimization / TestSearchPattern.java
1 package net.sf.openrocket.optimization;
2
3 import static org.junit.Assert.*;
4
5 import java.util.List;
6
7 import org.junit.Test;
8
9 public class TestSearchPattern {
10         
11         @Test
12         public void testRegularSimplex() {
13                 for (int dim = 1; dim < 20; dim++) {
14                         List<Point> points = SearchPattern.regularSimplex(dim);
15                         assertEquals(dim, points.size());
16                         
17                         for (int i = 0; i < dim; i++) {
18                                 // Test dot product
19                                 for (int j = i + 1; j < dim; j++) {
20                                         double[] x = points.get(i).asArray();
21                                         double[] y = points.get(j).asArray();
22                                         double dot = 0;
23                                         for (int k = 0; k < dim; k++) {
24                                                 dot += x[k] * y[k];
25                                         }
26                                         assertEquals(0.5, dot, 0.000000001);
27                                 }
28                                 
29                                 // Test positive coordinates
30                                 for (int j = 0; j < dim; j++) {
31                                         assertTrue(points.get(i).get(j) >= 0);
32                                 }
33                                 
34                                 // Test length
35                                 assertEquals(1.0, points.get(i).length(), 0.000000001);
36                         }
37                 }
38         }
39         
40 }