对Word函数,运用修正条件/判定覆盖法进行测试用例设计。 。 void Word(int n, char *word) { void *cat; cat = malloc((sizeof(char) * n) + 1); char *initialword = cat; startWord(initialword, n); int number=8,a=0, num=0; char alphabet; while (number!=0&&strcmp(initialword,word)!=0) { printf("The word now looks like this: %s\n", initialword); if (number!= 1) { printf("You have %d guesses left.\n", number); } else { printf("You have only one guess left.\n"); } alphabet = LetterFromUser(); for (a= 0;word[a]!= '\0'; a++) { if (word[a] == alphabet) { initialword[a] = alphabet; num = a; number++; } else if (a == n - 1) { number--; } } if (word[num]== alphabet) { printf("That guess is correct.\n"); } else { printf("That are no %c's in the word.\n", alphabet); } } if (strcmp(initialword, word)== 0) { printf("You guessed the word: %s\n", word); printf("You win.\n"); } else { printf("You lose.\n"); } } 根据上述描述,实现修正条件判定覆盖的测试用例设计。
时间: 2024-04-05 09:29:44 浏览: 53
首先,我们需要确定程序的决策条件和边界条件。通过对程序代码的分析,我们可以得到以下决策条件和边界条件:
决策条件:
1. number != 0 && strcmp(initialword, word) != 0
2. word[a] == alphabet
3. word[a] != alphabet && a == n - 1
边界条件:
1. n = 0
2. n = 1
3. n = 2
4. word = ""
5. word = "a"
6. word = "ab"
7. word = "aa"
8. word = "abc"
9. word = "aaa"
10. word = "bbb"
根据修正条件判定覆盖法,我们需要设计的测试用例如下:
1. 当n=0时,测试number != 0 && strcmp(initialword, word) != 0
2. 当n=1时,测试number != 0 && strcmp(initialword, word) != 0
3. 当n=2时,测试number != 0 && strcmp(initialword, word) != 0
4. 当word=""时,测试number != 0 && strcmp(initialword, word) != 0
5. 当word="a"时,测试number != 0 && strcmp(initialword, word) != 0,word[a] == alphabet,word[a] != alphabet && a == n - 1
6. 当word="ab"时,测试number != 0 && strcmp(initialword, word) != 0,word[a] == alphabet,word[a] != alphabet && a == n - 1
7. 当word="aa"时,测试number != 0 && strcmp(initialword, word) != 0,word[a] == alphabet,word[a] != alphabet && a == n - 1
8. 当word="abc"时,测试number != 0 && strcmp(initialword, word) != 0,word[a] == alphabet,word[a] != alphabet && a == n - 1
9. 当word="aaa"时,测试number != 0 && strcmp(initialword, word) != 0,word[a] == alphabet,word[a] != alphabet && a == n - 1
10. 当word="bbb"时,测试number != 0 && strcmp(initialword, word) != 0,word[a] == alphabet,word[a] != alphabet && a == n - 1
11. 当number=0时,测试strcmp(initialword, word) != 0
12. 当strcmp(initialword, word)=0时,测试strcmp(initialword, word) == 0
以上测试用例可以覆盖所有决策条件和边界条件。
阅读全文