@@ -173,35 +173,55 @@ def test_constructor(self):
173173
174174 def test_nonzero_lowerbound (self ):
175175 a = System .Array .CreateInstance (int , (5 ,), (5 ,))
176- for i in range (5 ): a [i ] = i
176+ for i in range (5 , 5 + a . Length ): a [i ] = i
177177
178- self .assertEqual (a [:2 ], System .Array [int ]((0 ,1 )))
179- self .assertEqual (a [2 :], System .Array [int ]((2 ,3 ,4 )))
180- self .assertEqual (a [2 :4 ], System .Array [int ]((2 ,3 )))
181- self .assertEqual (a [- 1 ], 4 )
178+ self .assertEqual (a [:7 ], System .Array [int ]((5 ,6 )))
179+ self .assertEqual (a [7 :], System .Array [int ]((7 ,8 ,9 )))
180+ self .assertEqual (a [7 :9 ], System .Array [int ]((7 ,8 )))
181+ self .assertEqual (a [- 1 :- 3 :- 1 ], System .Array [int ]((9 ,8 )))
182+ self .assertEqual (a [- 1 ], 9 )
182183
183- self .assertEqual (repr (a ), 'Array[int]((0, 1, 2, 3, 4 ), base: 5)' )
184+ self .assertEqual (repr (a ), 'Array[int]((5, 6, 7, 8, 9 ), base: 5)' )
184185
185186 a = System .Array .CreateInstance (int , (5 ,), (15 ,))
186187 b = System .Array .CreateInstance (int , (5 ,), (20 ,))
187188 self .assertEqual (a .Length , b .Length )
188189 for i in range (a .Length ):
189- self .assertEqual (a [i ], b [i ])
190+ self .assertEqual (a [i + 15 ], b [i + 20 ])
190191
191- ## 5-dimension
192+ a0 = System .Array .CreateInstance (int , 5 ) # regular, 0-based
193+ for i in range (5 ): a0 [i ] = i
194+
195+ a [17 :19 ] = a0 [2 :4 ]
196+ self .assertEqual (a [17 :19 ], System .Array [int ]((2 , 3 )))
197+
198+ self .assertEqual (a0 [3 :1 :- 1 ], System .Array [int ]((3 , 2 )))
199+ self .assertEqual (a [18 :16 :- 1 ], System .Array [int ]((3 , 2 )))
200+
201+ self .assertEqual (a0 [- 3 :- 1 ], System .Array [int ]((2 , 3 )))
202+ self .assertEqual (a [- 3 :- 1 ], System .Array [int ]((2 , 3 )))
203+
204+ a [18 :16 :- 1 ] = a0 [2 :4 ]
205+ self .assertEqual (a [17 :19 ], System .Array [int ]((3 , 2 )))
206+
207+ ## 5-dimension, 2-length/dim, progressive lowerbound
208+ a = System .Array .CreateInstance (int , (2 ,2 ,2 ,2 ,2 ), (1 ,2 ,3 ,4 ,5 ))
209+ self .assertEqual (a [1 ,2 ,3 ,4 ,5 ], 0 )
210+
211+ ## 5-dimension, 2-length/dim, progressive lowerbound
192212 a = System .Array .CreateInstance (int , (2 ,2 ,2 ,2 ,2 ), (1 ,2 ,3 ,4 ,5 ))
193- self .assertEqual (a [0 , 0 , 0 , 0 , 0 ], 0 )
213+ self .assertEqual (a [1 , 2 , 3 , 4 , 5 ], 0 )
194214
195215 for i in range (5 ):
196- index = [0 , 0 , 0 , 0 , 0 ]
197- index [i ] = 1
216+ index = [1 , 2 , 3 , 4 , 5 ]
217+ index [i ] + = 1
198218
199219 a [index [0 ], index [1 ], index [2 ], index [3 ], index [4 ]] = i
200220 self .assertEqual (a [index [0 ], index [1 ], index [2 ], index [3 ], index [4 ]], i )
201221
202222 for i in range (5 ):
203- index = [0 , 0 , 0 , 0 , 0 ]
204- index [i ] = 0
223+ index = [2 , 3 , 4 , 5 , 6 ]
224+ index [i ] -= 1
205225
206226 a [index [0 ], index [1 ], index [2 ], index [3 ], index [4 ]] = i
207227 self .assertEqual (a [index [0 ], index [1 ], index [2 ], index [3 ], index [4 ]], i )
@@ -218,6 +238,35 @@ def sliceArrayAssign(arr, index, val):
218238 self .assertRaises (NotImplementedError , sliceArrayAssign , a , - 200 , 1 )
219239 self .assertRaises (NotImplementedError , sliceArrayAssign , a , 1 , 1 )
220240
241+ def test_base1 (self ):
242+ # 1-based 2x2 matrix
243+ arr = System .Array .CreateInstance (str , (2 ,2 ), (1 ,1 ))
244+
245+ self .assertEqual (arr .GetLowerBound (0 ), 1 )
246+ self .assertEqual (arr .GetLowerBound (1 ), 1 )
247+ self .assertEqual (arr .GetUpperBound (0 ), 2 )
248+ self .assertEqual (arr .GetUpperBound (1 ), 2 )
249+
250+ arr .SetValue ("a_1,1" , System .Array [System .Int32 ]((1 ,1 )))
251+ arr .SetValue ("a_1,2" , System .Array [System .Int32 ]((1 ,2 )))
252+ arr .SetValue ("a_2,1" , System .Array [System .Int32 ]((2 ,1 )))
253+ arr .SetValue ("a_2,2" , System .Array [System .Int32 ]((2 ,2 )))
254+
255+ self .assertEqual (arr [1 , 1 ], "a_1,1" )
256+ self .assertEqual (arr [1 , 2 ], "a_1,2" )
257+ self .assertEqual (arr [2 , 1 ], "a_2,1" )
258+ self .assertEqual (arr [2 , 2 ], "a_2,2" )
259+
260+ arr [1 , 1 ] = "b_1,1"
261+ arr [1 , 2 ] = "b_1,2"
262+ arr [2 , 1 ] = "b_2,1"
263+ arr [2 , 2 ] = "b_2,2"
264+
265+ self .assertEqual (arr .GetValue (System .Array [System .Int32 ]((1 ,1 ))), "b_1,1" )
266+ self .assertEqual (arr .GetValue (System .Array [System .Int32 ]((1 ,2 ))), "b_1,2" )
267+ self .assertEqual (arr .GetValue (System .Array [System .Int32 ]((2 ,1 ))), "b_2,1" )
268+ self .assertEqual (arr .GetValue (System .Array [System .Int32 ]((2 ,2 ))), "b_2,2" )
269+
221270 def test_array_type (self ):
222271
223272 def type_helper (array_type , instance ):
0 commit comments