Lab 5

Programming exercises.

  1. Rewrite Simple Billing program in Lab 4 with all test cases from lab2Q2. To handle errors more efficiently, the constructor accepts one String argument instead of numbers of data elements. This String argument must be parsed into different pieces of information expected to exist in that line. Each piece must be appropriately stored in the corresponding Client instance variable. If the parsing fails, the constructor should throw ValueError Exception, providing type of error such as "invalid name" or "invalid transaction code" as an argument to the exception. The parsing should fail if the String argument does not contain the exact number of items and each items of the expected format. For example, if a float was expected from the current token, and the token could not be parsed into a float number, ValueError should be thrown and an error message should be displayed in the console.

  2. By comparing output results of operations using the fractions.Fraction class in Python, write a new tester program to test Rational class from lab4 and report your testing. Write another tester program to sort a list of Rational objects using Python sorted() and sortAndSearchAPI function in Lab5 folder.

  3. Rewrite the palindrome checker program in Lab4 to use doctest module and docstring to assure the function is correct. Write a tester program using unittest module for testing.

  4. Rewrite the Loan Table program in Lab2. Add input validation to accept only valid loan amount, interest rate, and payment amount i.e. loan amount in the range of 1000 to 100000, interest rate from 0.1 to 100%, and maximum payment number less than 100. For those errors that should rise to the user, create meaningful error messages. Write a test plan and report your testing.

  5. Given currencyAPI in Lab5 tutorial folder, add exception handling to catch errors you find or anticipate e.g. user enters nothing or an invalid currency code. For those errors that should rise to the user, create meaningful error messages. Write a test plan and report your testing.