CP4P_Testing_Activity_Answers

docx

School

Seneca College *

*We aren’t endorsed by this school

Course

101

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

14

Uploaded by SargentWater35178

Report
Computer Principles for Programmers SDLC – Testing See the topic's slides, the activity instructions, and the Programming Test Cases.docx The number of rows in the tables below are for convenience; they do not indicate the number of cases expected. Test Cases for the Black box program Description + / − Purpose Data Input Expected Output Actual output if unexpected Success? Comments I will start with a simple positive test on a simple input and the length of string is even. String: helloworld Ask for position character PASS Nominal Function + To obtain the character which is located in the middle Position: 5 'o' PASS CPR101 Summer 2023 Week 10 Page 1 of 14
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Input Expected Output Actual output if unexpected Success? Comments Repeat Nominal Function + To obtain the character which is in the middle Position: 5 'o' PASS I try it again because in the pdf said "verify repeatability. Just because it works the first time does not necessarily mean it works the next time." Edge Case: + Examine the first position in the string Position: 1 'h' 'l' FAIL The program returned “l” instead of 'h' at position 1. This program cannot handle the minimum range of position in this string, and it is better to fix it. Edge Case: + I try to examine the last position in the string Position: 10 'd' ' ' FAIL The program returned ' ' (empty space) instead of 'd' at position 10. It does not CPR101 Summer 2023 Week 10 Page 2 of 14
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Input Expected Output Actual output if unexpected Success? Comments work because it cannot handle the maximum range of position in this string and the program should change the logic of the program. I made an additional test case for exiting the loop. If we enter 0 the program should stop and try for another string, but it does not finish and ask again for position. + Exit the loop of getting position and enter the new string Position: 0 A position input of zero will end that prompting loop and return to prompt for a new string. 'e' FAIL I think the programmer should change the validation of this program. Because when we enter zero it repeats the program to get a new position. It shows, the developer does not handle this situation. CPR101 Summer 2023 Week 10 Page 3 of 14
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Input Expected Output Actual output if unexpected Success? Comments I will start with a simple positive test on a simple input and the length of string is odd. String: IamFaezeEghlimaIamstudentinSeneca Nominal Function + To obtain the character which is in the middle Position: 16 'I' 'm' FAIL It does not work for strings with odd lengths, but it works for strings that have even lengths. I think the developer could not handle these strings. Because it did not handle the length of string / 2 for finding the right position. CPR101 Summer 2023 Week 10 Page 4 of 14
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Input Expected Output Actual output if unexpected Success? Comments Edge Case: + To obtain the character which is in the first Position: 1 'I' 'm' FAIL The program returned ' ' (empty space) instead of 'd' at position 10. It does not work because it cannot handle the maximum range of position in this string and the program should change the logic of the program. CPR101 Summer 2023 Week 10 Page 5 of 14
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Input Expected Output Actual output if unexpected Success? Comments Edge Case: + To obtain the character which is in the last Position: 33 'a' ' ' FAIL The program returned ' ' (empty space) instead of 'd' at position 33. It does not work because it cannot handle the maximum range of position in this string and the program should change the logic of the program. Another test for different positions. + To obtain the character which is in another position Position: 4 'F' 'e' FAIL The program cannot handle the right position in the string. Another test for different positions. + To obtain the character which is in another position Position: 30 'n' 'c' FAIL The program cannot handle the right position in the string. CPR101 Summer 2023 Week 10 Page 6 of 14
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Input Expected Output Actual output if unexpected Success? Comments I will start with string which include numbers String: 1234567899650232 Edge Case: Single- character string with valid position. I try to examine the last position in the string - minimum edge condition. Negative case, first position less 1, less 2 Position: -2 Error But I get ' ' FAIL The developer did not handle the exception and the program cannot return desire output. If we enter the negative values, it should return error ask for new position, but it did not work correctly. CPR101 Summer 2023 Week 10 Page 7 of 14
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Input Expected Output Actual output if unexpected Success? Comments Edge Case: - maximum edge condition: Negative case, last position plus 2 Position: 18 Error But I get ' ' FAIL For returning the correct position of character in a string, the programmers must handle this situation. They must restrict the user to input values within the range. If they do not enter the correct values, the program must generate error and ask for another input. The developer should put a validation and if the user enters the value grater that length of string, it CPR101 Summer 2023 Week 10 Page 8 of 14
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Input Expected Output Actual output if unexpected Success? Comments I try to start a test case with a string that ends in special characters. String: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$ %^&*()+-=[]\{}|<>?/;'": Edge Case: + Positive case, first position of string Position: 80 : It gives ' ' (empty string) FAIL It goes back to the situation that a developer could not handle to return the exact position for showing the character. Write a test case for the one before the last character. + Positive case, one before the last character Position: 79 " It gives a symbol FAIL I think in this program, the developer did not handle the special character and cannot handle to show them to user correctly. CPR101 Summer 2023 Week 10 Page 9 of 14
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Computer Principles for Programmers SDLC – Testing Test Cases for the White box program. Description + / − Purpose Data Inputs for X and O Expected Output Actual output if unexpected Success? Comments Start program Record initial condition n/a 1 2 3 4 5 6 7 8 9 To copy a grid from terminal, hold [ Alt ] while click & drag to select. Nominal test + check recording of alternating moves to open grid positions X > 1 O > 2 X 2 3 4 5 6 7 8 9 X O 3 4 5 6 7 8 9 Edge test case - Player tries to mark a position outside the valid range (less than 1 or greater than 9). X > 10 O > 0 X O 3 4 5 6 7 8 9 X O 3 4 5 6 7 8 9 PASS It generates an Error because the developer handles this. The input must be between 1 and 9. Instead of 10, use grid position 1 – 9 Instead of 0, use grid position 1 - 9 With correct input and without any cheating the program can potential run successfully. + check for display the correct winner X > 5 O > 3 X O 3 4 X 6 7 8 9 X O O 4 X 6 7 8 9 PASS I give these values to see it can indicate the correct winner or not. And I think after showing the winner the program should end. + check for display the correct winner X > 9 O > 7 X O O 4 X 6 7 8 X X O O 4 X 6 O 8 9 CPR101 Summer 2023 Week 10 Page 10 of 14
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Inputs for X and O Expected Output Actual output if unexpected Success? Comments Advantage for one of the player - Player attempts to mark an already occupied position on the board. X > 2 O > 9 X O O 4 X 6 7 8 X X O O 4 X 6 O 8 9 X X O 4 X 6 7 8 X X O O 4 X 6 7 8 O FAIL The program should generate an error. It should indicate error message that the position is already occupied. We have to change this piece of code in this way: if (numConverted == 1 && input[inputIndex] == '\0' ) { if (gridPosition >= 1 && gridPosition <= 9) { if ( tttBoard [gridPositio n] != 'X' && tttBoard [gridPosition ] != 'O' ) { tttBoard [gridPosition ] = player ; } else { printf( "Position already occupied. Please choose another position.\n" ); } } else { printf( "Instead of %d, use grid position 1 - 9\n" , gridPosition); } CPR101 Summer 2023 Week 10 Page 11 of 14
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Inputs for X and O Expected Output Actual output if unexpected Success? Comments Disadvantage for one of the player who lost their turn - Player enters a non-numeric value instead of a grid position. X > x O > k X X O 4 X 6 7 8 X X O O 4 X 6 7 8 O FAIL It works and show the error, but it changes the turn. For example, If it is X's turn, when the player X enter “d”, after printing Error it gives turn to player O. This is a disadvantage for players. Because it causes players to lose in some situations Start program Record initial condition n/a 1 2 3 4 5 6 7 8 9 Start progra m Record initial condition n/a CPR101 Summer 2023 Week 10 Page 12 of 14
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Computer Principles for Programmers SDLC – Testing Description + / − Purpose Data Inputs for X and O Expected Output Actual output if unexpected Success? Comments The advantage for player one is to make themselves the winner. - Player exploits a problem in scanf() vulnerability X > 1 3 5 4 9 7 O > Error X 2 O O X 6 7 8 X FAIL The program should handle input lengths larger than the buffer size without causing buffer overflow vulnerabilities. When the first player enters numbers of position, except the first one, the rest of the numbers remain in the buffer and the compiler consider them as choices for player 2. So, it is an advantage for player 1 and a disadvantage for player 2. For fixing the problem after getting input we must clear the buffer. It should Read input character by character to avoid buffer overflow. We must add this piece of code to this program: char input[ BUFFER_SIZE ]; int inputIndex = 0; char ch; while (inputIndex < BUFFER_SIZE - 1) { ch = getchar(); if (ch == EOF || ch CPR101 Summer 2023 Week 10 Page 13 of 14
Computer Principles for Programmers SDLC – Testing CPR101 Summer 2023 Week 10 Page 14 of 14