Results of my master's thesis
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

78 linhas
1.8KB

  1. #!/usr/bin/python
  2. import unittest
  3. import baker
  4. import grid
  5. import numpy as np
  6. import scipy.spatial
  7. class TestSequenceFunctions(unittest.TestCase):
  8. def setUp(self):
  9. self.l = [[-1, 1], [-1, 0], [-1, 1], [0, -1], [0, 0], [0, 1], [1, -1], [1, 0], [1, 1]]
  10. self.approx_fmt = "%0.6f"
  11. def testGetPhis(self):
  12. X = [0,0]
  13. r = [[-1, -1], [0, 2], [1, -1]]
  14. result = baker.get_phis(X, r)
  15. result = [self.approx_fmt % i for i in result]
  16. right_answer = [self.approx_fmt % i for i in [1/3.0, 1/3.0, 1/3.0]]
  17. for a,b in zip(result, right_answer):
  18. self.assertEqual(a,b)
  19. def testGetPhis2(self):
  20. X = [0.5,0.25]
  21. r = [[0, 0], [1, 0], [1, 1]]
  22. result = baker.get_phis(X, r)
  23. right_answer = [0.5, 0.25, 0.25]
  24. for a,b in zip(result, right_answer):
  25. self.assertEqual(a,b)
  26. def testQlinear(self):
  27. X = [0.5, 0.25]
  28. r = [[0, 0], [1, 0], [1, 1]]
  29. q = [1, 0, 0]
  30. result = baker.qlinear(X, r, q)
  31. right_answer = 0.5
  32. self.assertEqual(result, right_answer)
  33. def testRunBaker(self):
  34. X = [0.5, 0.25]
  35. all_points = [
  36. [ 0, 0], # 0
  37. [ 1, 0], # 1
  38. [ 1, 1], # 2
  39. [ 0, 1], # 3
  40. [ 1,-1], # 4
  41. [ 0,-1], # 5
  42. [-1, 1], # 6
  43. [-1, 0], # 7
  44. [-1,-1], # 8
  45. ]
  46. q = [1, 0, 0, 0, 0, 0, 0, 0, 0]
  47. mesh = grid.grid(all_points, q)
  48. tree = scipy.spatial.KDTree(all_points)
  49. (final, exact) = baker.run_baker(X, mesh, tree)
  50. print final, exact
  51. result = 3
  52. right_answer = 3
  53. self.assertEqual(result, right_answer)
  54. if __name__ == '__main__':
  55. suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
  56. unittest.TextTestRunner(verbosity=2).run(suite)