maxDistancesBasedMetric_test.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from regmaxsn.core.maxDistanceBasedMetric import calcMaxDistances, maxDistEMD, cdist_1d_centripetal
  2. import numpy as np
  3. def calcMaxDistances_test():
  4. """Testing the calculation of maximum distances"""
  5. testFiles = [
  6. "tests/testFiles/toy1.swc",
  7. "tests/testFiles/toy2.swc"
  8. ]
  9. maxDistances = calcMaxDistances(testFiles)
  10. assert np.allclose(maxDistances, np.array([73.37574531, 54.77225575, 53.85164807,
  11. 51.6139516, 55.71355311, 62.80127387,
  12. 62.80127387, 73.37574531]))
  13. def maxDistEMD_test():
  14. """Testing the calculation of EMD of maxDistances"""
  15. swcList1 = ["tests/testFiles/toy2.swc",
  16. "tests/testFiles/toy3.swc"]
  17. emd_val = maxDistEMD(swcList1)
  18. assert np.allclose(emd_val, 35.99999099999999)
  19. def cdist_1d_test():
  20. "Testing cdist_1d"
  21. temp = cdist_1d_centripetal([1, 2, 3], [1, 2], center=2)
  22. assert np.allclose(temp,
  23. np.array([[0, -1], [1, 0], [0, -1]]))
  24. if __name__ == "__main__":
  25. maxDistEMD_test()