Homework — tests in your app
YOUR app: give it a safety net.
Requirements:
- Create
<something>_test.gonext to yourmain.go, inpackage main, withimport "testing". - Write table-driven tests for at least two pure functions in your app — the ones that take input and return a result (a formatter, a validator, a small calculation). Skip functions that only read input or print; test the logic, not the menu.
- Cover the edges, not just the happy path: an empty string, a boundary number, a Lithuanian word where bytes ≠ characters.
- Run
go test -vand make everything pass.gofmtthe test file too.
Extra (worth doing once): deliberately break one function — change a > to a >=, or RuneCountInString back to len — run go test, and paste the failing output. Then fix it and paste the pass. That red→green pair is the proof your test actually guards something.
To submit: the _test.go file + a transcript of go test -v passing, and (from the Extra, if you did it) the one failing run that shows the test catching a real change.
Honest note. Tests aren't a ritual and they aren't free — you don't test everything, and you don't write tests before code as a rule. Test the parts that are easy to get subtly wrong and annoying to re-check by hand: text handling, boundaries, anything touching bytes vs characters. That's most of what a small CLI gets wrong, and now a machine watches it for you. Next lesson — the final one — we look under the hood at pointers, and how the pieces you've built share memory.