Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import unittest
  2. import numpy
  3.  
  4. from numpy.testing import *
  5. set_package_path()
  6. from transformation import *
  7. restore_path()
  8.  
  9. class TestDeformationCreation(NumpyTestCase):
  10. def test_1DCreation(self):
  11. size = (10,)
  12. points = numpy.array(((2,), (8, )))
  13. displacements = [0, (-4,)]
  14.  
  15. field = denseDeformationFieldFromSparse(size, points, displacements)
  16.  
  17. for point,displacement in zip(points, displacements):
  18. assert_almost_equal(field[tuple(point.tolist())], displacement)
  19.  
  20. def test_2DCreation(self):
  21. size = (11, 11)
  22. points = numpy.array(((5., 6.), (5., 4.), (6., 5.), (4., 5.)))
  23. displacements = [(0, 1), (0, 1) , (0, -1), (0, -1)]
  24.  
  25. field = denseDeformationFieldFromSparse(size, points, displacements)
  26. for point,displacement in zip(points, displacements):
  27. assert_almost_equal(field[tuple(point.tolist())], displacement)
  28.  
  29. def test_2DCreation_bis(self):
  30. size = (10, 10)
  31. points = numpy.array(((5., 5.), (2., 8.), (8., 2.)))
  32. displacements = [0, (5, -4), (0, 2)]
  33.  
  34. field = denseDeformationFieldFromSparse(size, points, displacements)
  35. for point,displacement in zip(points, displacements):
  36. assert_almost_equal(field[tuple(point.tolist())], displacement)
  37.  
  38. def test_3DCreation(self):
  39. size = (10, 10, 10)
  40. points = numpy.array(((5., 5., 5.), (2., 8., 2.), (8., 2., 8.), (2., 2., 8.)))
  41. displacements = [0, (5, -4, 3), (0, 2, 0), -2]
  42.  
  43. field = denseDeformationFieldFromSparse(size, points, displacements)
  44.  
  45. for point,displacement in zip(points, displacements):
  46. assert_almost_equal(field[tuple(point.tolist())], displacement)
  47.  
  48. if __name__ == "__main__":
  49. unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement