Testing discipline vs folklore speedups

Beginner Accelerating numerics & developer hygiene
Created by Pavel · 29.04.2026 at 19:11 UTC

Unit tests lock behaviour while you refactor: changing a feature encoder should not silently shift training targets. Tests do not improve Big-O complexity—they improve confidence and iteration speed.

Confusing “we added tests” with “we made the algorithm asymptotically faster” is a category error. Likewise, micro-benchmarks without correctness checks optimise the wrong thing.

pytest is the de facto runner in many DS repos; property-based testing (hypothesis) finds edge cases random unit tests miss.

pytest docs: [1].


Sources

University approvals: 0
Tasks
Question 1

Systematic automated tests primarily:

Hint

Quality gate, not hardware boost.

Question 2

A model trains faster after you vectorise a loop, but validation AUC drops. What failed?

Hint

Optimisation needs regression checks.

Question 3

add(a, b) returns a + b but raises RuntimeError('no_bool') if either argument is bool (use type is bool).

Hint

Explicit type guard—bool is subclass of int.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Accelerating numerics & developer hygiene
  • Difficulty: Beginner
  • Completed: 0 users
Creator
Pavel
Pavel