PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/groovylab/test/org/math/array/MatrixGetTest.groovy

http://groovylab.googlecode.com/
Groovy | 49 lines | 30 code | 12 blank | 7 comment | 0 complexity | 507d722b62c842f039c8997fb3900a19 MD5 | raw file
 1package org.math.array;
 2
 3import org.math.array.Matrix as Matrix
 4import org.math.array.DoubleArray as DoubleArray
 5
 6class MatrixGetTest extends GroovyTestCase {
 7	
 8	def vectorlist =   [1.0 ,2.0,3.0,4.0]
 9	def arraylist =  [[1.1,1.2,1.3,1.4,1.5],[2.1,2.2,2.3,2.4,2.5],[3.1,3.2,3.3,3.4,3.5],[4.1,4.2,4.3,4.4,4.5]]
10	
11	def vectordouble=DoubleArray.increment(4,1.0,1.0)
12	double[] beg = [1.1,1.2,1.3,1.4,1.5]
13	double[] pitch = [1.0,1.0,1.0,1.0,1.0]
14	def arraydouble=DoubleArray.increment(4,5,beg,pitch)
15	
16	void testNoRangeGet() {
17		def Avd=new Matrix(vectordouble)
18		assert Avd[2] ==2.0
19		
20		def Aad=new Matrix(arraydouble)
21		assert Aad[2][3] ==2.3
22		//println "Aad[2]="+(Aad[2]+"\n")
23		//println "new Matrix(arraydouble[1])="+(new Matrix(arraydouble[1])+"\n")
24		assert Aad[2] ==new Matrix(arraydouble[1])		
25	}
26	
27	
28	void testRangeGet() {
29		def Avd=new Matrix(vectordouble)
30		//println "Avd="+(Avd+"\n")
31		
32		assert Avd[1..2] ==new Matrix([1.0,2.0])
33		assert Avd[2..-1] ==new Matrix([2.0,3.0,4.0])
34		assert Avd[-2..-1] ==new Matrix([3.0,4.0])
35		assert Avd[-2..-3] ==new Matrix([3.0,2.0])
36		
37		
38		def Aad=new Matrix(arraydouble)
39		//println "Aad="+(Aad+"\n")
40		//println "Aad[1..2]="+(Aad[1..2]+"\n")
41		//println "Aad[1..2][3]="+(Aad[1..2][3]+"\n")
42		assert Aad[1..2][3] ==new Matrix([[1.3],[2.3]])
43		//println "Aad[1..2][2..3]="+(Aad[1..2][2..3]+"\n")
44		assert Aad[1..2][2..3] ==new Matrix([[1.2,1.3],[2.2,2.3]])
45		
46		assert Aad[2..-1][3] ==new Matrix([[2.3],[3.3],[4.3]])
47		assert Aad[2..-1][2..3]  ==new Matrix([[2.2,2.3],[3.2,3.3],[4.2,4.3]])
48	}
49}