1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ezmorph.array;
18
19 import junit.framework.Test;
20 import junit.framework.TestSuite;
21 import junit.textui.TestRunner;
22 import net.sf.ezmorph.MorphException;
23 import net.sf.ezmorph.test.ArrayAssertions;
24
25
26
27
28 public class DoubleArrayMorpherTest extends AbstractArrayMorpherTestCase
29 {
30 public static void main( String[] args )
31 {
32 TestRunner.run( suite() );
33 }
34
35 public static Test suite()
36 {
37 TestSuite suite = new TestSuite( DoubleArrayMorpherTest.class );
38 suite.setName( "DoubleArrayMorpher Tests" );
39 return suite;
40 }
41
42 private DoubleArrayMorpher anotherMorpher;
43 private DoubleArrayMorpher anotherMorpherWithDefaultValue;
44 private DoubleArrayMorpher morpher;
45 private DoubleArrayMorpher morpherWithDefaultValue;
46
47 public DoubleArrayMorpherTest( String name )
48 {
49 super( name );
50 }
51
52
53
54 public void testMorph_doubleArray()
55 {
56 double[] expected = { 1d, 2d, 3d };
57 double[] actual = (double[]) morpher.morph( expected );
58 ArrayAssertions.assertEquals( expected, actual );
59 }
60
61 public void testMorph_doubleArray_threedims()
62 {
63 double[][][] expected = { { { 1 }, { 2 } }, { { 3 }, { 4 } } };
64 double[][][] actual = (double[][][]) morpher.morph( expected );
65 ArrayAssertions.assertEquals( expected, actual );
66 }
67
68 public void testMorph_doubleArray_twodims()
69 {
70 double[][] expected = { { 1, 2, 3 }, { 4, 5, 6 } };
71 double[][] actual = (double[][]) morpher.morph( expected );
72 ArrayAssertions.assertEquals( expected, actual );
73 }
74
75 public void testMorph_illegalArgument()
76 {
77 try{
78
79 morpher.morph( "" );
80 }
81 catch( MorphException expected ){
82
83 }
84 }
85
86 public void testMorph_null()
87 {
88 assertNull( morpher.morph( null ) );
89 }
90
91 public void testMorph_strings()
92 {
93 String[] expected = { "1", "2", "3.3" };
94 double[] actual = (double[]) morpher.morph( expected );
95 ArrayAssertions.assertEquals( new double[] { 1d, 2d, 3.3d }, actual );
96 }
97
98 public void testMorph_strings_twodims()
99 {
100 String[][] expected = { { "1", "2", "3.3" }, { "4", "5", "6.6" } };
101 double[][] actual = (double[][]) morpher.morph( expected );
102 ArrayAssertions.assertEquals( new double[][] { { 1d, 2d, 3.3d }, { 4d, 5d, 6.6 } }, actual );
103 }
104
105 public void testMorph_throwException()
106 {
107 try{
108 new DoubleArrayMorpher().morph( new String[] { null } );
109 fail( "Should have thrown an Exception" );
110 }
111 catch( MorphException expected ){
112
113 }
114 }
115
116 protected AbstractArrayMorpher getAnotherMorpher()
117 {
118 return anotherMorpher;
119 }
120
121 protected AbstractArrayMorpher getAnotherMorpherWithDefaultValue()
122 {
123 return anotherMorpherWithDefaultValue;
124 }
125
126 protected AbstractArrayMorpher getMorpher()
127 {
128 return morpher;
129 }
130
131 protected AbstractArrayMorpher getMorpherWithDefaultValue()
132 {
133 return morpherWithDefaultValue;
134 }
135
136 protected Class getMorphsToClass()
137 {
138 return double[].class;
139 }
140
141 protected void setUp() throws Exception
142 {
143 morpher = new DoubleArrayMorpher();
144 morpherWithDefaultValue = new DoubleArrayMorpher( 0 );
145 anotherMorpher = new DoubleArrayMorpher();
146 anotherMorpherWithDefaultValue = new DoubleArrayMorpher( 1 );
147 }
148 }