create changelog entry
[debian/openrocket] / core / 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 net.sf.openrocket.optimization.general.Point;
8 import net.sf.openrocket.optimization.general.multidim.SearchPattern;
9
10 import org.junit.Test;
11
12 public class TestSearchPattern {
13         
14         @Test
15         public void testRegularSimplex() {
16                 for (int dim = 1; dim < 20; dim++) {
17                         List<Point> points = SearchPattern.regularSimplex(dim);
18                         assertEquals(dim, points.size());
19                         
20                         for (int i = 0; i < dim; i++) {
21                                 // Test dot product
22                                 for (int j = i + 1; j < dim; j++) {
23                                         double[] x = points.get(i).asArray();
24                                         double[] y = points.get(j).asArray();
25                                         double dot = 0;
26                                         for (int k = 0; k < dim; k++) {
27                                                 dot += x[k] * y[k];
28                                         }
29                                         assertEquals(0.5, dot, 0.000000001);
30                                 }
31                                 
32                                 // Test positive coordinates
33                                 for (int j = 0; j < dim; j++) {
34                                         assertTrue(points.get(i).get(j) >= 0);
35                                 }
36                                 
37                                 // Test length
38                                 assertEquals(1.0, points.get(i).length(), 0.000000001);
39                         }
40                 }
41         }
42         
43 }