1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
package net.sourceforge.combean.test.mathprog.linalg; |
23 | |
|
24 | |
import junit.framework.TestCase; |
25 | |
import net.sourceforge.combean.interfaces.mathprog.linalg.SparseVector; |
26 | |
import net.sourceforge.combean.mathprog.linalg.SparseVectorWithConstantPattern; |
27 | |
import net.sourceforge.combean.mathprog.linalg.statics.SparseVectorConverter; |
28 | |
import net.sourceforge.combean.test.helpers.checks.Check; |
29 | |
|
30 | |
public class TestSparseVectorWithConstantPattern extends TestCase { |
31 | |
|
32 | |
public static void main(String[] args) { |
33 | 0 | junit.textui.TestRunner.run(TestSparseVectorWithConstantPattern.class); |
34 | 0 | } |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public TestSparseVectorWithConstantPattern(String arg0) { |
40 | 9 | super(arg0); |
41 | 9 | } |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
protected void setUp() throws Exception { |
47 | 9 | super.setUp(); |
48 | 9 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
protected void tearDown() throws Exception { |
54 | 9 | super.tearDown(); |
55 | 9 | } |
56 | |
|
57 | |
public final void testVectorWithConstantValue() { |
58 | 3 | SparseVector vec = |
59 | |
new SparseVectorWithConstantPattern(5, 2.0); |
60 | |
|
61 | 3 | assertEquals(5, vec.getDimension()); |
62 | 3 | assertEquals(5, vec.getNumIterations()); |
63 | |
|
64 | 3 | double[] v = SparseVectorConverter.convertToDoubleArray(vec); |
65 | 3 | final double[] expected = {2.0, 2.0, 2.0, 2.0, 2.0}; |
66 | 3 | Check.compareDoubleArrays(expected, v, 0.0); |
67 | 3 | } |
68 | |
|
69 | |
public final void testVectorWithConstantNonZeroBlock() { |
70 | 3 | SparseVector vec = |
71 | |
new SparseVectorWithConstantPattern(5, 2.0, 2, 3); |
72 | |
|
73 | 3 | assertEquals(5, vec.getDimension()); |
74 | 3 | assertEquals(2, vec.getNumIterations()); |
75 | |
|
76 | 3 | double[] v = SparseVectorConverter.convertToDoubleArray(vec); |
77 | 3 | final double[] expected = {0.0, 0.0, 2.0, 2.0, 0.0}; |
78 | 3 | Check.compareDoubleArrays(expected, v, 0.0); |
79 | 3 | } |
80 | |
|
81 | |
public final void testVectorWithConstantNonZeroProgression() { |
82 | 3 | SparseVector vec = |
83 | |
new SparseVectorWithConstantPattern(5, 2.0, 1, 3, 2); |
84 | |
|
85 | 3 | assertEquals(5, vec.getDimension()); |
86 | 3 | assertEquals(2, vec.getNumIterations()); |
87 | |
|
88 | 3 | double[] v = SparseVectorConverter.convertToDoubleArray(vec); |
89 | 3 | final double[] expected = {0.0, 2.0, 0.0, 2.0, 0.0}; |
90 | 3 | Check.compareDoubleArrays(expected, v, 0.0); |
91 | 3 | } |
92 | |
} |