package countdown import ( "fmt" "io" "time" ) const ( finalWord = "Go!" countdownStart = 3 ) type Sleeper interface { Sleep() } type DefaultSleeper struct{} func (d *DefaultSleeper) Sleep() { time.Sleep(1 * time.Second) } func Countdown(out io.Writer, sleeper Sleeper) { // XXX: The sequence is not tested for i := countdownStart; i > 0; i-- { fmt.Fprintf(out, "%d\n", i) // This is difficult to test! sleeper.Sleep() } fmt.Fprint(out, finalWord) }