Solved How does the checker test a "live" countdown? JAJackStackOP 23 Oct, 10:50 edited The output depends on the current time, so how can it pass?
LILiamByte23 Oct, 16:21 Solutionreplies: 2Stage 2 is the trick: by making countdown(launch, now) take now as a parameter, the checker can pass a fixed time and get predictable output. That's exactly why the challenge is structured this way — testable time.
JAJackStackOP25 Oct, 10:08replies: 1Passing the clock in as a parameter. That's a really useful pattern.
NONoahLoops25 Oct, 16:46Same idea as the medical dispenser article — don't trust the clock blindly, control it.
Comments 4
Join the discussion CommentAlready have an account? Log in
Stage 2 is the trick: by making
countdown(launch, now)takenowas a parameter, the checker can pass a fixed time and get predictable output. That's exactly why the challenge is structured this way — testable time.Passing the clock in as a parameter. That's a really useful pattern.
Same idea as the medical dispenser article — don't trust the clock blindly, control it.
It's called dependency injection, in its simplest form.