Docsity

workshop - 1 - first assignment, Lecture notes of Computer Programming

Toggle sidebar
bg1
SFT221 – Workshop 1
Learning Outcomes
• Understand the difference between testing and debugging.
• How to do simple software tests.
• How to do simple debugging.
• Appreciate the difficulty in testing and debugging.
Instructions
The following code contains a function to determine if a string starts with another string and a second
function to test if a string ends with another string. The developer wrote two tests for the functions and
concluded that they work.
Your job is to:
• Test the code to determine if it works correctly:
o Show the test code for every test and describe what you are testing.
o Present the result of the test and your interpretation of the result and an explanation of
how this result happened if the result was not what you expected.
o Inspect the code to find any bugs not revealed in testing.
• Debug the code:
o Use whatever tools you like to determine the cause of an errors you found in the code
regardless of the means you used to find the error.
o Fix the code and explain what the error was and how you fixed it.
Here is the code you will be working on.
pf3
pf4

Partial preview of the text

Download workshop - 1 - first assignment and more Lecture notes Computer Programming in PDF only on Docsity!

SFT221 – Workshop 1

Learning Outcomes

  • Understand the difference between testing and debugging.
  • How to do simple software tests.
  • How to do simple debugging.
  • Appreciate the difficulty in testing and debugging.

Instructions

The following code contains a function to determine if a string starts with another string and a second function to test if a string ends with another string. The developer wrote two tests for the functions and concluded that they work. Your job is to:

  • Test the code to determine if it works correctly: o Show the test code for every test and describe what you are testing. o Present the result of the test and your interpretation of the result and an explanation of how this result happened if the result was not what you expected. o Inspect the code to find any bugs not revealed in testing.
  • Debug the code: o Use whatever tools you like to determine the cause of an errors you found in the code regardless of the means you used to find the error. o Fix the code and explain what the error was and how you fixed it. Here is the code you will be working on.

#define _CRT_SECURE_NO_WARNINGS #include #include /**

  • Determine if the string s starts with the string prefix.
  • @param s - the string to see if it starts with prefix
  • @param prefix - the prefix to test
  • @returns true if the strings begins with the prefix. / int startsWith(const char s[], const char prefix[]) { char buf[ 40 ]; int i; int sz = strlen(prefix); for (i = 0; i < sz; i++) { buf[i] = s[i]; } buf[sz] = '\0'; return 0 == strcmp(buf, prefix); } /*
  • Determine if the string s ends with the string suffix.
  • @param s - the string to see if it ends with suffix
  • @param suffix - the suffix to test
  • @returns true if the strings ends with the suffix. */ int endsWith(const char s[], const char suffix[]) { int sz = strlen(suffix); int slen = strlen(s); return 0 == strcmp(s + slen - sz, suffix); } int main(void) { char s1[] = { "upended" }; char prefix[] = { "up" }; char suffix[] = { "ed" }; printf("%s does %s start with %s\n", s1, startsWith(s1, prefix)? "" : " not", prefix); printf("%s does %s end with %s\n", s1, endsWith(s1, suffix)? "" : " not", suffix); return 0; }

Marking Rubric

Comprehensiveness of test cases 10% Explanation of test results 10 % Explanation of bugs discovered by inspection 15% Discovered at least 4 bugs 20 % Quality of bug fixes 10% Explanation of how bug fix works 15% Reflection question 1 10% Reflection question 2 10 %