3 ms·
I was just looking at the unit tests I have in a game-related Rust program. "cargo test" runs these. So what did I test? - A complicated index of objects in a
by Animats 3y ago
I was just looking at the unit tests I have in a game-related Rust program. "cargo test" runs these. So what did I test?
- A complicated index of objects in a virtual world. The test creates some dummy objects, moves them around, and runs a consistency check on the data structures after each change. This has caught bugs in the past.
- A lock-by-string primitive, used when I don't want two threads working on the same URL.
- Serializers and deserializers, usually where some data comes in from the outside. Quoted strings in the test cases deserialize, reserialize, and check.
- There are geometry generators which generate spheres, boxes, cylinders, etc. Those all have unit tests.
- Some math functions, such as angle between two quaternions, and some computations around transformation matrices and the viewing frustrum that tell what's visible on screen.
- Some transformations on meshes.
- Some simple parsers.
Mostly things with algorithmic complexity, data format dependency, or non-trivial internal consistency.
Hard parts that the Rust compiler won't catch, and which are hard to debug in a larger context.
With those tests in place, and in 100% safe Rust, not much mysterious happens that's internal to the program.
External relationships with the game server are another matter. That's handled with lots of internal checks and logging.