Module 1 · Exercise 1 · ~30 min · Real Go code
Six small exercises in a real Go module. Make the failing tests pass. Each drill targets a concept from Module 1.
The code lives at exercise-01-type-drills/ alongside this HTML. Open that directory in your terminal:
cd module-01-go-mental-model/exercises/exercise-01-type-drills
go test -v ./...
Implement the TODOs in drills.go. Re-run until all green.
| File | What it is |
|---|---|
go.mod | Module declaration. Tells Go this directory is a project. |
drills.go | Six drill skeletons. Each panics until you implement it. |
drills_test.go | Tests that exercise the drills. Don't change. |
README.md | Quick reference for what each drill teaches. |
GoodSignal() so it returns a true nil error. BadSignal() demonstrates the trap and is left intentionally broken.String() method.go test fails to find your module, you're probably not in the right directory. pwd first.go test -run TestCounter -v. Useful when isolating one drill.go vet ./... catches common mistakes — copying a Mutex, suspicious Println, etc. Run it occasionally.return e to return nil. Now both words of the interface are zero, and err == nil behaves correctly.You should see something like:
=== RUN TestDrill1_Zeros
--- PASS: TestDrill1_Zeros (0.00s)
=== RUN TestAppendToNilSlice
--- PASS: TestAppendToNilSlice (0.00s)
... (8 more)
PASS
ok example.com/typedrills 0.123s
Mark complete and move to Exercise 2 — method sets and interface satisfaction.