1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
|
#! /usr/bin/env python
# System imports
from distutils.util import get_platform
import os
import sys
import unittest
# Import NumPy
import numpy as N
major, minor = [ int(d) for d in N.__version__.split(".")[:2] ]
if major == 0: BadListError = TypeError
else: BadListError = ValueError
# Add the distutils-generated build directory to the python search path and then
# import the extension module
libDir = "lib.%s-%s" % (get_platform(), sys.version[:3])
sys.path.insert(0,os.path.join("build", libDir))
import Matrix
######################################################################
class MatrixTestCase(unittest.TestCase):
####################################################
### Test functions that take arrays of type BYTE ###
def testScharDet(self):
"Test scharDet function"
matrix = [[6,7],[8,9]]
self.assertEquals(Matrix.scharDet(matrix), -2)
def testScharMax(self):
"Test scharMax function"
matrix = [[-6,5,-4],[3,-2,1]]
self.assertEquals(Matrix.scharMax(matrix), 5)
def testScharMaxNonContainer(self):
"Test scharMax function with None"
self.assertRaises(TypeError, Matrix.scharMax, None)
def testScharMaxWrongDim(self):
"Test scharMax function with a 1D array"
self.assertRaises(TypeError, Matrix.scharMax, [0, -1, 2, -3])
def testScharMin(self):
"Test scharMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.scharMin(matrix), 4)
def testScharScale(self):
"Test scharScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'b')
Matrix.scharScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testScharFloor(self):
"Test scharFloor function"
matrix = N.array([[10,-2],[-6,7]],'b')
Matrix.scharFloor(matrix,0)
N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]]))
def testScharCeil(self):
"Test scharCeil function"
matrix = N.array([[10,-2],[-6,7]],'b')
Matrix.scharCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]]))
def testScharLUSplit(self):
"Test scharLUSplit function"
lower, upper = Matrix.scharLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
#####################################################
### Test functions that take arrays of type UBYTE ###
def testUcharDet(self):
"Test ucharDet function"
matrix = [[7,6],[9,8]]
self.assertEquals(Matrix.ucharDet(matrix), 2)
def testUcharMax(self):
"Test ucharMax function"
matrix = [[6,5,4],[3,2,1]]
self.assertEquals(Matrix.ucharMax(matrix), 6)
def testUcharMaxNonContainer(self):
"Test ucharMax function with None"
self.assertRaises(TypeError, Matrix.ucharMax, None)
def testUcharMaxWrongDim(self):
"Test ucharMax function with a 1D array"
self.assertRaises(TypeError, Matrix.ucharMax, [0, 1, 2, 3])
def testUcharMin(self):
"Test ucharMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.ucharMin(matrix), 4)
def testUcharScale(self):
"Test ucharScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'B')
Matrix.ucharScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testUcharFloor(self):
"Test ucharFloor function"
matrix = N.array([[10,2],[6,7]],'B')
Matrix.ucharFloor(matrix,7)
N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]]))
def testUcharCeil(self):
"Test ucharCeil function"
matrix = N.array([[10,2],[6,7]],'B')
Matrix.ucharCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]]))
def testUcharLUSplit(self):
"Test ucharLUSplit function"
lower, upper = Matrix.ucharLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
#####################################################
### Test functions that take arrays of type SHORT ###
def testShortDet(self):
"Test shortDet function"
matrix = [[6,7],[8,9]]
self.assertEquals(Matrix.shortDet(matrix), -2)
def testShortMax(self):
"Test shortMax function"
matrix = [[-6,5,-4],[3,-2,1]]
self.assertEquals(Matrix.shortMax(matrix), 5)
def testShortMaxNonContainer(self):
"Test shortMax function with None"
self.assertRaises(TypeError, Matrix.shortMax, None)
def testShortMaxWrongDim(self):
"Test shortMax function with a 1D array"
self.assertRaises(TypeError, Matrix.shortMax, [0, -1, 2, -3])
def testShortMin(self):
"Test shortMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.shortMin(matrix), 4)
def testShortScale(self):
"Test shortScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'h')
Matrix.shortScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testShortFloor(self):
"Test shortFloor function"
matrix = N.array([[10,-2],[-6,7]],'h')
Matrix.shortFloor(matrix,0)
N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]]))
def testShortCeil(self):
"Test shortCeil function"
matrix = N.array([[10,-2],[-6,7]],'h')
Matrix.shortCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]]))
def testShortLUSplit(self):
"Test shortLUSplit function"
lower, upper = Matrix.shortLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
######################################################
### Test functions that take arrays of type USHORT ###
def testUshortDet(self):
"Test ushortDet function"
matrix = [[7,6],[9,8]]
self.assertEquals(Matrix.ushortDet(matrix), 2)
def testUshortMax(self):
"Test ushortMax function"
matrix = [[6,5,4],[3,2,1]]
self.assertEquals(Matrix.ushortMax(matrix), 6)
def testUshortMaxNonContainer(self):
"Test ushortMax function with None"
self.assertRaises(TypeError, Matrix.ushortMax, None)
def testUshortMaxWrongDim(self):
"Test ushortMax function with a 1D array"
self.assertRaises(TypeError, Matrix.ushortMax, [0, 1, 2, 3])
def testUshortMin(self):
"Test ushortMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.ushortMin(matrix), 4)
def testUshortScale(self):
"Test ushortScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'H')
Matrix.ushortScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testUshortFloor(self):
"Test ushortFloor function"
matrix = N.array([[10,2],[6,7]],'H')
Matrix.ushortFloor(matrix,7)
N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]]))
def testUshortCeil(self):
"Test ushortCeil function"
matrix = N.array([[10,2],[6,7]],'H')
Matrix.ushortCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]]))
def testUshortLUSplit(self):
"Test ushortLUSplit function"
lower, upper = Matrix.ushortLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
###################################################
### Test functions that take arrays of type INT ###
def testIntDet(self):
"Test intDet function"
matrix = [[6,7],[8,9]]
self.assertEquals(Matrix.intDet(matrix), -2)
def testIntMax(self):
"Test intMax function"
matrix = [[-6,5,-4],[3,-2,1]]
self.assertEquals(Matrix.intMax(matrix), 5)
def testIntMaxNonContainer(self):
"Test intMax function with None"
self.assertRaises(TypeError, Matrix.intMax, None)
def testIntMaxWrongDim(self):
"Test intMax function with a 1D array"
self.assertRaises(TypeError, Matrix.intMax, [0, -1, 2, -3])
def testIntMin(self):
"Test intMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.intMin(matrix), 4)
def testIntScale(self):
"Test intScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'i')
Matrix.intScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testIntFloor(self):
"Test intFloor function"
matrix = N.array([[10,-2],[-6,7]],'i')
Matrix.intFloor(matrix,0)
N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]]))
def testIntCeil(self):
"Test intCeil function"
matrix = N.array([[10,-2],[-6,7]],'i')
Matrix.intCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]]))
def testIntLUSplit(self):
"Test intLUSplit function"
lower, upper = Matrix.intLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
####################################################
### Test functions that take arrays of type UINT ###
def testUintDet(self):
"Test uintDet function"
matrix = [[7,6],[9,8]]
self.assertEquals(Matrix.uintDet(matrix), 2)
def testUintMax(self):
"Test uintMax function"
matrix = [[6,5,4],[3,2,1]]
self.assertEquals(Matrix.uintMax(matrix), 6)
def testUintMaxNonContainer(self):
"Test uintMax function with None"
self.assertRaises(TypeError, Matrix.uintMax, None)
def testUintMaxWrongDim(self):
"Test uintMax function with a 1D array"
self.assertRaises(TypeError, Matrix.uintMax, [0, 1, 2, 3])
def testUintMin(self):
"Test uintMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.uintMin(matrix), 4)
def testUintScale(self):
"Test uintScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'I')
Matrix.uintScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testUintFloor(self):
"Test uintFloor function"
matrix = N.array([[10,2],[6,7]],'I')
Matrix.uintFloor(matrix,7)
N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]]))
def testUintCeil(self):
"Test uintCeil function"
matrix = N.array([[10,2],[6,7]],'I')
Matrix.uintCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]]))
def testUintLUSplit(self):
"Test uintLUSplit function"
lower, upper = Matrix.uintLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
####################################################
### Test functions that take arrays of type LONG ###
def testLongDet(self):
"Test longDet function"
matrix = [[6,7],[8,9]]
self.assertEquals(Matrix.longDet(matrix), -2)
def testLongMax(self):
"Test longMax function"
matrix = [[-6,5,-4],[3,-2,1]]
self.assertEquals(Matrix.longMax(matrix), 5)
def testLongMaxNonContainer(self):
"Test longMax function with None"
self.assertRaises(TypeError, Matrix.longMax, None)
def testLongMaxWrongDim(self):
"Test longMax function with a 1D array"
self.assertRaises(TypeError, Matrix.longMax, [0, -1, 2, -3])
def testLongMin(self):
"Test longMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.longMin(matrix), 4)
def testLongScale(self):
"Test longScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'l')
Matrix.longScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testLongFloor(self):
"Test longFloor function"
matrix = N.array([[10,-2],[-6,7]],'l')
Matrix.longFloor(matrix,0)
N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]]))
def testLongCeil(self):
"Test longCeil function"
matrix = N.array([[10,-2],[-6,7]],'l')
Matrix.longCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]]))
def testLongLUSplit(self):
"Test longLUSplit function"
lower, upper = Matrix.longLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
#####################################################
### Test functions that take arrays of type ULONG ###
def testUlongDet(self):
"Test ulongDet function"
matrix = [[7,6],[9,8]]
self.assertEquals(Matrix.ulongDet(matrix), 2)
def testUlongMax(self):
"Test ulongMax function"
matrix = [[6,5,4],[3,2,1]]
self.assertEquals(Matrix.ulongMax(matrix), 6)
def testUlongMaxNonContainer(self):
"Test ulongMax function with None"
self.assertRaises(TypeError, Matrix.ulongMax, None)
def testUlongMaxWrongDim(self):
"Test ulongMax function with a 1D array"
self.assertRaises(TypeError, Matrix.ulongMax, [0, 1, 2, 3])
def testUlongMin(self):
"Test ulongMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.ulongMin(matrix), 4)
def testUlongScale(self):
"Test ulongScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'L')
Matrix.ulongScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testUlongFloor(self):
"Test ulongFloor function"
matrix = N.array([[10,2],[6,7]],'L')
Matrix.ulongFloor(matrix,7)
N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]]))
def testUlongCeil(self):
"Test ulongCeil function"
matrix = N.array([[10,2],[6,7]],'L')
Matrix.ulongCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]]))
def testUlongLUSplit(self):
"Test ulongLUSplit function"
lower, upper = Matrix.ulongLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
########################################################
### Test functions that take arrays of type LONGLONG ###
def testLongLongDet(self):
"Test longLongDet function"
matrix = [[6,7],[8,9]]
self.assertEquals(Matrix.longLongDet(matrix), -2)
def testLongLongMax(self):
"Test longLongMax function"
matrix = [[-6,5,-4],[3,-2,1]]
self.assertEquals(Matrix.longLongMax(matrix), 5)
def testLongLongMaxNonContainer(self):
"Test longLongMax function with None"
self.assertRaises(TypeError, Matrix.longLongMax, None)
def testLongLongMaxWrongDim(self):
"Test longLongMax function with a 1D array"
self.assertRaises(TypeError, Matrix.longLongMax, [0, -1, 2, -3])
def testLongLongMin(self):
"Test longLongMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.longLongMin(matrix), 4)
def testLongLongScale(self):
"Test longLongScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'q')
Matrix.longLongScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testLongLongFloor(self):
"Test longLongFloor function"
matrix = N.array([[10,-2],[-6,7]],'q')
Matrix.longLongFloor(matrix,0)
N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]]))
def testLongLongCeil(self):
"Test longLongCeil function"
matrix = N.array([[10,-2],[-6,7]],'q')
Matrix.longLongCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]]))
def testLongLongLUSplit(self):
"Test longLongLUSplit function"
lower, upper = Matrix.longLongLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
#########################################################
### Test functions that take arrays of type ULONGLONG ###
def testUlongLongDet(self):
"Test ulongLongDet function"
matrix = [[7,6],[9,8]]
self.assertEquals(Matrix.ulongLongDet(matrix), 2)
def testUlongLongMax(self):
"Test ulongLongMax function"
matrix = [[6,5,4],[3,2,1]]
self.assertEquals(Matrix.ulongLongMax(matrix), 6)
def testUlongLongMaxNonContainer(self):
"Test ulongLongMax function with None"
self.assertRaises(TypeError, Matrix.ulongLongMax, None)
def testUlongLongMaxWrongDim(self):
"Test ulongLongMax function with a 1D array"
self.assertRaises(TypeError, Matrix.ulongLongMax, [0, 1, 2, 3])
def testUlongLongMin(self):
"Test ulongLongMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.ulongLongMin(matrix), 4)
def testUlongLongScale(self):
"Test ulongLongScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'Q')
Matrix.ulongLongScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testUlongLongFloor(self):
"Test ulongLongFloor function"
matrix = N.array([[10,2],[6,7]],'Q')
Matrix.ulongLongFloor(matrix,7)
N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]]))
def testUlongLongCeil(self):
"Test ulongLongCeil function"
matrix = N.array([[10,2],[6,7]],'Q')
Matrix.ulongLongCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]]))
def testUlongLongLUSplit(self):
"Test ulongLongLUSplit function"
lower, upper = Matrix.ulongLongLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
#####################################################
### Test functions that take arrays of type FLOAT ###
def testFloatDet(self):
"Test floatDet function"
matrix = [[6,7],[8,9]]
self.assertEquals(Matrix.floatDet(matrix), -2)
def testFloatMax(self):
"Test floatMax function"
matrix = [[-6,5,-4],[3.14,-2.718,1]]
self.assertEquals(Matrix.floatMax(matrix), 5.0)
def testFloatMaxNonContainer(self):
"Test floatMax function with None"
self.assertRaises(TypeError, Matrix.floatMax, None)
def testFloatMaxWrongDim(self):
"Test floatMax function with a 1D array"
self.assertRaises(TypeError, Matrix.floatMax, [0.0, -1, 2.718, -3.14])
def testFloatMin(self):
"Test floatMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.floatMin(matrix), 4)
def testFloatScale(self):
"Test floatScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'f')
Matrix.floatScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testFloatFloor(self):
"Test floatFloor function"
matrix = N.array([[10,-2],[-6,7]],'f')
Matrix.floatFloor(matrix,0)
N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]]))
def testFloatCeil(self):
"Test floatCeil function"
matrix = N.array([[10,-2],[-6,7]],'f')
Matrix.floatCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]]))
def testFloatLUSplit(self):
"Test floatLUSplit function"
lower, upper = Matrix.floatLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
######################################################
### Test functions that take arrays of type DOUBLE ###
def testDoubleDet(self):
"Test doubleDet function"
matrix = [[6,7],[8,9]]
self.assertEquals(Matrix.doubleDet(matrix), -2)
def testDoubleMax(self):
"Test doubleMax function"
matrix = [[-6,5,-4],[3.14,-2.718,1]]
self.assertEquals(Matrix.doubleMax(matrix), 5.0)
def testDoubleMaxNonContainer(self):
"Test doubleMax function with None"
self.assertRaises(TypeError, Matrix.doubleMax, None)
def testDoubleMaxWrongDim(self):
"Test doubleMax function with a 1D array"
self.assertRaises(TypeError, Matrix.doubleMax, [0.0, -1, 2.718, -3.14])
def testDoubleMin(self):
"Test doubleMin function"
matrix = [[9,8],[7,6],[5,4]]
self.assertEquals(Matrix.doubleMin(matrix), 4)
def testDoubleScale(self):
"Test doubleScale function"
matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'d')
Matrix.doubleScale(matrix,4)
self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
def testDoubleFloor(self):
"Test doubleFloor function"
matrix = N.array([[10,-2],[-6,7]],'d')
Matrix.doubleFloor(matrix,0)
N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]]))
def testDoubleCeil(self):
"Test doubleCeil function"
matrix = N.array([[10,-2],[-6,7]],'d')
Matrix.doubleCeil(matrix,5)
N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]]))
def testDoubleLUSplit(self):
"Test doubleLUSplit function"
lower, upper = Matrix.doubleLUSplit([[1,2,3],[4,5,6],[7,8,9]])
self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True)
self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True)
######################################################################
if __name__ == "__main__":
# Build the test suite
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(MatrixTestCase))
# Execute the test suite
print "Testing 2D Functions of Module Matrix"
print "NumPy version", N.__version__
print
result = unittest.TextTestRunner(verbosity=2).run(suite)
sys.exit(len(result.errors) + len(result.failures))
|