๐งฎCalculator Test LabLAB
Calculator Test Lab
A calculator.go file provides four functions. Your job is to write comprehensive table-driven tests for all of them.
The calculator functions
What to implement
Write table-driven tests for all four functions:
- TestAdd โ at least 3 cases: two positives, two negatives, zero identity
- TestSub โ at least 3 cases: basic subtraction, negative result, subtracting zero
- TestMul โ at least 3 cases: positive, negative, multiply by zero
- TestDiv โ at least 3 cases including the error case when
b == 0
Each test must:
- Use a slice of struct test cases
- Check the returned value
- For
TestDiv, check both the float result and whether an error is returned forb == 0
Simulating go test in the Playground
Since the Go Playground doesn't run go test, call each test function manually from main using a *testing.T{}:
โ Enter (Mac) ยท Ctrl+Enter (Win/Linux)
โ Enter (Mac) ยท Ctrl+Enter (Win/Linux)