Caochris / SCOTIA

MIT License
5 stars 3 forks source link

Running xdoctests and fixing examples #10

Closed lee-t closed 3 months ago

lee-t commented 5 months ago

Examples can be executed as docstests which can help with testing the code to ensure reliability and reproducibility. To expedite this process I am adding the package xdoctest and adding its usage to the readme. I've rewritten the dbscan.py examples to work with this test framework and it now passes the tests:

(scotia) tyrone_lee@ccb:~/projects/SCOTIA$ python -m xdoctest scotia/dbscan.py

=====================================
_  _ ___  ____ ____ ___ ____ ____ ___
 \/  |  \ |  | |     |  |___ [__   |
_/\_ |__/ |__| |___  |  |___ ___]  |

=====================================

Start doctest_module('scotia/dbscan.py')
Listing tests
gathering tests
running 1 test(s)
====== <exec> ======
* DOCTEST : scotia/dbscan.py::dbscan_ff_cell:0, line 33 <- wrt source file
DOCTEST SOURCE
1 >>> pos_arr = np.array(pd.read_csv('./input_files/position.csv',index_col=0))
2 >>> idx_l, eps = dbscan_ff_cell(pos_arr,np.array(range(pos_arr.shape[0])),min_cluster_size=5,eps_l = list(range(10,50,1)))
3 >>> idx_l
  [array([ 0,  1,  2,  3,  5,  6,  7,  8, 14]), 
  array([ 4,  9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26])]
6 >>> eps
  35
DOCTEST STDOUT/STDERR
eps: 35
DOCTEST RESULT
* SUCCESS: scotia/dbscan.py::dbscan_ff_cell:0
====== </exec> ======
============
=== 1 passed in 10.05 seconds ===

I now leave the rest to @Caochris to complete the rest of the examples

A few notes on doctests: