In general I am also going in order:
- Doc tests
tests in the same file where the tested entity is defined
tests as submodule of module where tested entity is defined, but in separate file
- separate module somewhere in project tree
I am going downside this list when i decide, that there are too many tests, or tests are to long/complex (especially for doctest). This is always fully subjective decision. The (4) I am using actually only, if tests are involving multiple not directly related entities (like system tests).
In your case I would either go for (2) or (3), with example implementation in the same file where I would locate tests.
However consider if your tests are actually tests. If they are really only examples, then I guess that idiomatic way is to create add examples in directory next to your
src, so they would be useable with
cargo run --example foo. Check this blog post: http://xion.io/post/code/rust-examples.html.