test_py.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import unittest
  2. import numpy as np
  3. from scattnlay import scattnlay, mie, mie_mp
  4. test_cases = [
  5. # x, {Re(m), Im(m)}, Qext, Qsca, test_name
  6. [0.099, 0.75+0j, 7.417859e-06, 7.417859e-06], # ,'a'],
  7. [0.101, 0.75+0j, 8.033538e-06, 8.033538e-06], # ,'b'],
  8. [10, 0.75+0j, 2.232265, 2.232265], # ,'c'],
  9. [0.055, 1.5+1j, 0.10149104, 1.131687e-05], # ,'g'],
  10. [0.056, 1.5+1j, 0.1033467, 1.216311e-05], # ,'h'],
  11. [1, 10+10j, 2.532993, 2.049405], # ,'k'],
  12. [100, 1.33+1e-5j, 2.101321, 2.096594], # ,'e'],
  13. [100, 1.5+1j, 2.097502, 1.283697], # ,'i'],
  14. [1000, 0.75+0j, 1.997908, 1.997908], # ,'d'],
  15. [100, 10+10j, 2.071124, 1.836785], # ,'l'],
  16. [10000, 1.33+1e-5j, 2.004089, 1.723857], # ,'f'],
  17. [10000, 1.5+1j, 2.004368, 1.236574], # ,'j'],
  18. [10000, 10+10j, 2.005914, 1.795393], # ,'m'],
  19. ]
  20. class TestStringMethods(unittest.TestCase):
  21. def test_bulk(self):
  22. tol = 3e-7
  23. for solver in [mie, mie_mp]:
  24. if solver is None:
  25. continue
  26. for case in test_cases:
  27. solver.SetLayersSize(case[0])
  28. solver.SetLayersIndex(case[1])
  29. solver.RunMieCalculation()
  30. Qext = solver.GetQext()
  31. Qsca = solver.GetQsca()
  32. self.assertTrue((case[2]-Qext)/Qext < tol)
  33. self.assertTrue((case[3]-Qsca)/Qsca < tol)
  34. if __name__ == '__main__':
  35. unittest.main()