REVISION AND PRACTICE

Practice Problems with Worked Answers

2 min read
On this page 11 headings

1. Which boundary values should be checked for isPrime(num)?

Answer: 0 and 1.

2. For min(x, y), which tests cover both branches?

Answer: (3, 8) returns 3 through the True branch; (9, 4) returns 4 through the False branch.

3. What do {49, 100, 200} establish for num < 50 or num > 150?

Answer: They achieve multiple condition coverage: the first component is True for 49, both are False for 100, and the second is True for 200.

4. What is the difference between a driver and a stub?

Answer: A driver holds the non-local data used by the module under test; a stub is a dummy for a function the module calls. Top down uses stubs; bottom up uses drivers.

5. When does pytest.raises(ValueError) pass?

Answer: It passes when ValueError is raised inside the context.

6. Why does replacing the count with 10 on the second addition fail?

Answer: After two additions of 10, the count should be 20. Replacement leaves 10.

7. What is the Red–Green–Refactor order?

Answer: Write a failing test, implement enough to pass, then refactor while tests pass.

8. Which integration strategy starts with lower-level modules?

Answer: Bottom up integration; drivers supply the non-local data required by the modules.

9. Distinguish smoke, performance and stress testing.

Answer: Smoke testing checks basic functionality before system testing. Performance testing checks non-functional requirements. Stress testing is a type of performance testing beyond design capacity.

10. How is cyclomatic complexity calculated here?

Answer: Number of decision and loop statements + 1 = 3 + 1 = 4; at least four test cases.

11. Why is one passing is_prime(5) test insufficient?

Answer: A function that always returns True would pass. Test non-primes and boundaries too.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑