软件工程代写|测试代写

3S03 Software Testing


The following scenario applies to all three questions below. Suppose you are building a 70s-style game like Breakout (trivia: Steve Wozniak and Steve Jobs were two of the original designers of this game back in the day). The objective of the game is to move a player horizontally at the bottom of the display to hit a
puck. The puck will bounce off the player, and the edges of the screen, at a particular velocity. The player should attempt to hit the puck in a way so that it collides with bricks at the top of the screen. There will be multiple rows of bricks (usually you start a game with around 8 rows, but as the game progresses and it gets harder, more rows can be added). Each collision between puck and bricks will destroy one or more bricks, depending on velocity and position. Once all bricks have been destroyed, the round is successfully finished (and a new round begins). If the player misses the puck and it drops off the bottom of the display, a puck is lost. The player has three pucks, and once all three have been lost, the player’s game is over.

Consider the class Velocity, used in Breakout, whose class interface is specified below. Velocity is used to track the velocity (speed + direction) of the puck that is currently in play. A velocity object represents the movement of a puck (or more generally, a sprite) on a playfield based on attributes of speed (expressed in playfield units per unit time) and a direction (expressed as an angle in degrees; 0 represents east or right; 90 designates north or up; and so on). The speed attribute is broken up into two components: speedX (speed in the x direction, i.e., left-right) and speedY (speed in the up-down direction). While the speed attribute is always non-negative, the components of a velocity’s speed can be negative. The value of speedX is negative if a velocity’s direction is heading left. The value of speedY is negative if the direction is down. Speed and Direction are abstract types that ultimately are defined as integer values.

public class Velocity {
private Speed speed, speedX, speedY;
private Direction direction;

public Velocity(); //constructor
public Velocity(Speed speed, Direction direction); //constructor

public Speed getSpeed();
public Speed getSpeedX(); // get speed in X direction
public Speed getSpeedY(); // get speed in Y direction
public Direction getDirection();

public void setSpeed(Speed speed);
public void setDirection(Direction direction);
public void reverse(); // reverse the direction of the puck!
public void reverseX(); // reverse the direction of the puck in x-axis
public void reverseY();

1. [10 marks] Using a table, specify a test plan for the Velocity class. Your test plan should state the following:

  • Any requirements for inspection/review of the class. Justify why you may need inspection/review.

  • Brief statement of objectives for specification-based testing for the class.

  • Brief statement of objectives for implementation-based testing for the class.

  • Brief statement of objectives for interaction-based testing (i.e., interactions between particular methods of the class)

    1. As a guideline, the test plan should be no more than a page long, and each part should be a short paragraph of text. Remember that you are focusing on objectives, not detailed descriptions of what your tests will look like!

      2. [25 marks] Based on what was discussed in lectures, in terms of contracts and contract-based specification, write preconditions and postconditions for each method of Velocity (including the two constructors). Also, write a class invariant: it specifies (as a boolean expression) properties that must be true for all instances of class Velocity. Hint: think about constraints on the attributes of Velocity and relationships between these attributes. Hint: some of the preconditions and postconditions are very simple, others are more complex!

      3. [15 marks] Informally define a set of test cases for the following methods of Velocity:

      • setDirection define exactly one test case

      • setSpeed define exactly one test case

      • reverse define 5 test cases

      • reverseX define 5 test cases
        Your tests may be written out in English, pseudocode, or JUnit, whichever you find easiest to use; if you are using English or pseudocode, please be sure that we can understand your answers. Each test case must specify the input to the test case and the expected outputs.