I understand that tests that rely on random numbers/arrays can sometimes be tricky to write.

For the purpose of testing correctness, it is usually enough to use a larger threshold (say 1e-6, or 1e-8, etc) instead of eps. Incorrect implementation would violate the criteria by a large margin, while a correct implementation is extremely unlikely to break it.

The rationale is that the deviance caused by incorrect implementation is usually many orders of magnetite greater than the typical deviance caused by truncation or statistical fluctuation. We have a lot of latitude to choose a good threshold value that is not that brittle.