Injecting a time provider lambda for deterministic tests
What this preview is
Injecting a time provider lambda for deterministic tests is a medium quant interview question on language knowledge in Cpp.
- Difficulty
- Medium
- Topic
- Language Knowledge
- Discipline
- Quant development
- Language
- Cpp
- Companies
- 0
Testing time-dependent code with dependency injection in C++
This is a medium-difficulty C++ question that tests your understanding of how to design code for testability by injecting time providers as function arguments or callable objects. Rather than hardcoding calls to the system clock, production code can accept a time provider—often a lambda or function pointer—allowing tests to control the clock deterministically.
The question asks you to trace through a code snippet that uses this pattern, requiring you to understand how lambdas capture variables, how function parameters can accept callables, and what the program outputs when a mocked or injected time source is used instead of real time. This skill is common in systems where timing, scheduling, or temporal logic must be verified without flakiness or real delays.
- Lambda capture semantics (by value vs. by reference)
- Callable types and function signatures in C++
- Dependency injection for testability
- Mock objects and deterministic control flow
Related practice
Unlock full access to getcracked
Join to unlock this question, detailed solutions, and our complete library of quant finance interview prep.