Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A function ticket_price(age) gives 0 for ages under 5, 50 for ages 5 to 12, 100 for ages 13 to 59, and 70 for ages 60 and more. List the ages that you would test, and say why each one is there.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. One in each branch, both sides of every edge, and the ends and strange values.
| Age | Expected | Why |
|---|---|---|
| 0 | 0 | the smallest age |
| 4 | 0 | just below the first edge |
| 5 | 50 | at the first edge |
| 12 | 50 | just below the second edge |
| 13 | 100 | at the second edge |
| 59 | 100 | just below the third edge |
| 60 | 70 | at the third edge |
| 100 | 70 | a very old age |
| -1 | an error | a strange value: decide what should happen |
Check. The edges are 5, 13 and 60. A bug of < against <= shows at exactly those ages.
Answer: The table above: 0, 4, 5, 12, 13, 59, 60, 100 and a negative age.
Log in to join the discussion.
Loading…