UCL Logo

Problem Class Questions 2006
for COMP1008 (Object-Oriented Programming)

Week 9 (Starting 20th March)

These questions are about testing.

Q1. Select a method implementing a mathematical function like sin, cos, tan or log. For your method:

a) State the valid range of values the method can be applied to.

b) If the method is applied to a double value and returns a double value, what level of accuracy (decimal places) is sufficient when testing the method?

c) Put together a test data set (argument values and expected results) to test the method. Justify your choice of data and check you have covered boundary conditions.

d) How do you determine the expected results? How can you validate the accuracy of your source?

e) Determine an algorithm for computing your chosen function and write the method.

Q2. Consider class ArrayList from the Java class library. Outline how it can be tested following the JUnit unit testing approach.

a) What fixture object(s) should be used? (Hint: Think about boundary conditions that should be tested - empty, size one, size many.)

b) Write a set of test methods to test ArrayList using your fixture(s).

c) How many tests will you need to write to have confidence that ArrayList works properly?

Q3. Consider this class outline (instance variables and method bodies are not shown):

public class InsurancePolicy 
{
  public InsurancePolicy(String id) {...}
public String getPolicyID(){...}
public void setStartDate(Date startDate) {...}
public Date getStartDate() {...} public void setEndDate(Date endDate) {...}
public Date getEndDate() {...}
public void setValue(double value) {...} public double getValue() {...} public void setIsQuote(boolean isQuote) {...} public boolean isQuote() {...} public void setSchedule(Schedule schedule) {...} public Schedule getSchedule() {...} public Customer getCustomer() {...} public ArrayList getClaims() {...} public void addClaim(Claim claim) {...} public void removeClaim(Claim claim) {...} }

Write a JUnit test class to test class Policy. Provide basic versions of classes Schedule, Customer and Date to allow you to write your tests.

Q4. Consider this class outline:

class Greeter
{
  public void printGreeting()
  {
    printHello();
    printGoodbye();
  }


  public void printHello()
  {
    printMessage("Hello");
  }


  public void printGoodbye()
  {
    printMessage("Goodbye");
  }


  public void printMessage(String s)
  {
    System.out.println(s);
  }

}

How can this class be tested given that it has only void methods and prints on the screen?

Hint: Modify the class.

Last updated: September 2, 2006

Computer Science Department - University College London - Gower Street - London - WC1E 6BT - Telephone: +44 (0)20 7679 7214 - Copyright 1999-2006 UCL


 Search by Google