COMP 2710 Software Construction Project 1 Implementation Test

  • Slides: 8
Download presentation
COMP 2710 Software Construction Project 1 – Implementation: Test Drivers Dr. Xiao Qin Auburn

COMP 2710 Software Construction Project 1 – Implementation: Test Drivers Dr. Xiao Qin Auburn University http: //www. eng. auburn. edu/[email protected] edu

Exercise 2: Write a test driver for professor() u_short professor(Player&); /* * Encounter a

Exercise 2: Write a test driver for professor() u_short professor(Player&); /* * Encounter a professor. Player loses a random * extra amount of time, but may slightly increase * intelligence. * Input: A Player variable containing all of a * player's current game stats. * Output: 0 success * 2 negative money * 3 negative intel * 4 negative time */ 1 -2

A test driver: professor. Test() void professor. Test(void) { Player test. Player; u_short error.

A test driver: professor. Test() void professor. Test(void) { Player test. Player; u_short error. Stats; /* Case 1: Enough money, intel, and time */ cout << “Test professor. Test() case 1: n”; test. Player. steps = 50; test. Player. time = 1000; test. Player. intel = 1000; test. Player. money = 1000; error. Stats = professor(test. Player); assert(test. Player. time < 1000); assert(test. Player. intel > 1000); assert(error. Stats == 0); 1 -3

A test driver: professor. Test() (cont. ) /* Abnormal cases */ /* Case 2:

A test driver: professor. Test() (cont. ) /* Abnormal cases */ /* Case 2: Player has negative money */ cout << “Test professor() case 2: n”; Player test. Player. money = -10; error. Stats = professor(test. Player); assert(error. Stats == 2); . . . } 1 -4

print. Error. Stats(int) Void print. Error. Stats(int error. Stats); /* This function shows error

print. Error. Stats(int) Void print. Error. Stats(int error. Stats); /* This function shows error information */ 1 -5

Exercise 3: Write a test driver for add. Highscore() u_short add. High. Score(score. Board&

Exercise 3: Write a test driver for add. Highscore() u_short add. High. Score(score. Board& s. Board, string name, //player name u_int score); //a high score /* * Encounter a professor. Player loses a random * extra amount of time, but may slightly increase * intelligence. * player's current game stats. * Output: 0 success * 1 insufficient memory */ 1 -6

A test driver: add. Highscore. Test() void add. High. Score. Test(void) { score. Board

A test driver: add. Highscore. Test() void add. High. Score. Test(void) { score. Board test. Board; test. Board->first == NULL; test. Board->max. Size = 5; /* scoreboard’s max size */ /* Note: error. Stats is not tested here */ add. High. Score(test. Board, “Qin”, 4); add. High. Score(test. Board, “Qin”, 7); add. High. Score(test. Board, “Qin”, 15); What is expected? add. High. Score(test. Board, “Qin”, 2); add. High. Score(test. Board, “Qin”, 18); add. High. Score(test. Board, “Qin”, 15); add. High. Score(test. Board, “Qin”, 29); add. High. Score(test. Board, “Qin”, 3); add. High. Score(test. Board, “Qin”, 87); add. High. Score(test. Board, “Qin”, 10); display. Score. Board(test. Board); 1 -7 }

See Dragons-Implementation. Sample Testing Result. pdf Copyright © 2008 Pearson Addison-Wesley. All rights reserved.

See Dragons-Implementation. Sample Testing Result. pdf Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1 -8