Concept Explanation
Testing in Go works best when the code is predictable and the inputs are easy to reason about. In this lesson, you will practice checking behavior with small examples, choosing useful test cases, and thinking about what should happen when the input changes. The main skill here is not writing a huge test suite. It is learning how to prove that a simple program works for both normal data and awkward cases.
Where to Put the Code
- Define color and position variables at the top.
- Create shape drawing or placement logic in the middle.
- Render output (print, canvas, SVG, or styled block) at the end.
Command Reference
- Start with one normal case and one edge case instead of inventing many random tests.
- State the expected output before running the program so the check is intentional.
- Change one input at a time and notice whether the result still matches your expectation.
- Keep test cases small enough that you can verify them by inspection.
Step-by-step Guide
- Run the sample program and write down what each test input should return.
- Add a second case that checks a different branch of the logic.
- Try an edge case, such as equal numbers or zero, and confirm the behavior is still correct.
- Refactor only after the behavior is clear, then rerun the same checks.
- Finish by listing which inputs gave you the most confidence in the solution.
Practice Exercises
- Write a function that returns the smaller of two values and test it with three different pairs.
- Take a simple helper function and design one test for the common path and one for an edge case.
- Rewrite the example so the output clearly shows both the input and the expected result.
Coding Challenges
- Create a tiny manual test plan for a function with three possible outcomes.
- Design tests that would catch a bug caused by using the wrong comparison operator.
Mini Practice Tasks
- Add one edge case to the sample program.
- Write one comment that explains why a specific test case matters.
- Summarize in one line what the current tests are proving.
Common Mistake
Mixing x and y axes or using wrong coordinate origin causes shapes to appear in unexpected places.
Real-life Mini Challenge
Draw one square, one triangle, and one circle, then move X marker 2 steps right and 1 step down.