Changeset 6441 for branches/numpy/anuga/utilities/test_numerical_tools.py
- Timestamp:
- Mar 4, 2009, 8:26:22 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/numpy/anuga/utilities/test_numerical_tools.py
r6410 r6441 466 466 # t(num.array('abc', num.float), False) 467 467 468 ## 469 # @brief Test to see if ensure_numeric() behaves as we expect. 470 # @note Under Numeric ensure_numeric() *always* returned a copy. 471 # Under numpy it copies only when it has to. 472 def test_ensure_numeric_copy(self): 473 ##### 474 # Make 'points' a _list_ of coordinates. 475 # Should be changed by ensure_numeric(). 476 ##### 477 points = [[1.,2.], [3.,4.], [5.,6.]] 478 points_id = id(points) 479 480 points_new = ensure_numeric(points, num.float) 481 points_new_id = id(points_new) 482 483 msg = 'ensure_numeric() should return a copy of a list' 484 self.failUnless(points_new_id != points_id, msg) 485 486 # should never change it's input parameter 487 msg = "ensure_numeric() changed it's input parameter" 488 self.failUnless(points_id == id(points), msg) 489 490 ##### 491 # Make 'points' a _tuple_ of coordinates. 492 # Should be changed by ensure_numeric(). 493 ##### 494 points = ((1.,2.), (3.,4.), (5.,6.)) 495 points_id = id(points) 496 497 points_new = ensure_numeric(points, num.int) 498 points_new_id = id(points_new) 499 500 msg = 'ensure_numeric() should return a copy of a list' 501 self.failUnless(points_new_id != points_id, msg) 502 503 # should never change it's input parameter 504 msg = "ensure_numeric() changed it's input parameter" 505 self.failUnless(points_id == id(points), msg) 506 507 ##### 508 # Make 'points' a numeric array of float coordinates. 509 # Should NOT be changed by ensure_numeric(). 510 ##### 511 points = num.array([[1.,2.], [3.,4.], [5.,6.]], num.float) 512 points_id = id(points) 513 514 points_new = ensure_numeric(points, num.float) 515 points_new_id = id(points_new) 516 517 msg = 'ensure_numeric() should return the original input' 518 self.failUnless(points_new_id == points_id, msg) 519 520 # should never change it's input parameter 521 msg = "ensure_numeric() changed it's input parameter" 522 self.failUnless(points_id == id(points), msg) 523 524 ##### 525 # Make 'points' a numeric array of int coordinates. 526 # Should be changed by ensure_numeric(). 527 ##### 528 points = num.array([[1,2], [3,4], [5,6]], num.int) 529 points_id = id(points) 530 531 points_new = ensure_numeric(points, num.float) 532 points_new_id = id(points_new) 533 534 msg = 'ensure_numeric() should return a copy of the input' 535 self.failUnless(points_new_id != points_id, msg) 536 537 # should never change it's input parameter 538 msg = "ensure_numeric() changed it's input parameter" 539 self.failUnless(points_id == id(points), msg) 540 541 ##### 542 # Make 'points' a numeric array of int coordinates. 543 # Should NOT be changed by ensure_numeric(, num.int). 544 ##### 545 points = num.array([[1,2], [3,4], [5,6]], num.int) 546 points_id = id(points) 547 548 points_new = ensure_numeric(points, num.int) 549 points_new_id = id(points_new) 550 551 msg = 'ensure_numeric() should return the original input' 552 self.failUnless(points_new_id == points_id, msg) 553 554 # should never change it's input parameter 555 msg = "ensure_numeric() changed it's input parameter" 556 self.failUnless(points_id == id(points), msg) 557 468 558 ################################################################################ 469 559
Note: See TracChangeset
for help on using the changeset viewer.