Write a program which estimates the cost of a telephone call, and design and implement unit tests
Fantastic news! We've Found the answer you've been seeking!
Question:
Write a program which estimates the cost of a telephone call, and design and implement unit tests for the program.
The phone company applies the following rules to a phone call to calculate the charge:
- The minimum before-tax charge of 59.400 cents applies to all calls to any destination up to 50km away and 89.000 cents for any destination further than 50km away.
- Calls are charged on a per-second basis at 0.759 cents per second (<= 50km) and 1.761 cents per second (> 50km)
- Off-peak seconds (from 19:00:00 to 06:59:59 the next day) are given a discount of 40% off (<= 50km) and 50% off (> 50km) off the above rate
- If the type of call was share-call AND the destination is more than 50km away, there is a discount of 50% off after any off-peak discount (minimum charge still applies). However, share-calls over shorter distances are not discounted.
- Finally, VAT of 14% is added to give the final cost.
Your program should ask for the following input:
- The starting time of the call (to be split up into hours, minutes and seconds)
- The duration of the call (to be split up into minutes and seconds)
- Whether the duration was more than 50km away
- Whether the call was share-call
Hint: you can prompt the user to input hours, minutes and seconds at once by asking for a format like HH:MM:SS and splitting the resulting string by the delimiter. You may assume that the user will enter valid input, and that no call will exceed 59 minutes and 59 seconds.
Your program should output the following information:
- The basic cost
- The off-peak discount
- The share-call discount
- The net cost
- The VAT
- The total cost
- Before you write the program, identify the equivalence classes and boundaries that you will need to use in equivalence testing and boundary analysis when writing black-box tests. This may help you to design the program itself, and not just the tests!
- Write the program. Remember that you will need to write unit tests for this program, and design it accordingly – the calculation that you need to test should be placed in some kind of unit, like a function, which can be imported from outside of the program and used independently of the rest of the code (like the user input)!
- Now implement the black-box tests which you have designed by writing a unit test module for your program. Run all the tests, and make sure that they pass! Then use the trace module to check how well your tests cover your function code.
Related Book For
Posted Date: