3 ms·
> I've always wondered the best way to write tests for "This event should happen x% of the time." I use https://github.com/pkhuong/csm/blob/master/csm.py https
by pkhuong 4y ago
> I've always wondered the best way to write tests for "This event should happen x% of the time."
I use https://github.com/pkhuong/csm/blob/master/csm.py https://github.com/pkhuong/csm/blob/master/csm.py to set a known false alarm rate (e.g., one in a billion) and test that some event happens with probability in a range [lo, hi], with lo < expected < hi (e.g., expected +/- 0.01). The statistical test will run more iteration as needed. If that's too slow, you can either widen the range (most effective), or increase the expected rate of false alarms (not as effective, because the number of iteration scales logarithmically wrt false alarms).