I have isolated a tricky numerical corner case for a package using randomly generated values. I tracked down the problem and fixed it, but want to add it to the tests too so that it does not happen again even if I refactor etc.
What are the best practices for adding array constants, eg a Float64 matrix, to the tests?
I could just add it on a single line, eg a 20x20 matrix becomes 8k character beast, but otherwise it is fine. Then it is local, but it is still clutter.
I could write to a dlm file and read it back, DelimitedFiles is a lightweight dependency.
I would serialize the matrix using the Serialization stdlib and keep the file along the test suite. It is a standard library, and it stores the exact values of the floating-point numbers. Moreover, the API is the simplest possible:
using Serialization
M_ = deserialize("matrix.bin")
The format is guaranteed to remain readable between julia versions:
The data format can change in minor (1.x) Julia releases, but files written by prior 1.x versions will remain readable.
If the dataset grows in size, there are a few packages meant to help supply larger data for testing. They include Downloads.jl, RemoteFiles.jl, DataDeps.jl, and Artifacts.jl. I feel like I’m forgetting one. The general idea is that your data has to be somewhere it can be publicly downloaded, and it will be moved into a package-specific area, in most cases. Maybe you could combine it with Scratch.jl, to make a scratch space for testing-only data.
Hope All Is Well - Drew