SWT301_-_FA_2023_-_PE12_1281.webp
N

SWT301_-_FA_2023_-_PE12_1281.webp

Question 2 (3 points): Assuming you are assigned to conduct the component test for the method below, please design and create the minimum component test cases (Unit Test case) needed to achieve 100% statement coverage and 100% decision coverage. (Use question 2 template).
The countCharacters method that counts the number of uppercase letters, lowercase letters,numeric characters, and special characters in a given input string. It returns a HashMap containing this information.
1
2
3 @
import java.util.HashMap;
public class Character Counter {
public static HashMap<String, Integer> countCharacters(String input) {
int upperCaseCount = 0;int lowerCaseCount = 0;
5
6
int numericCount = 0;
7
int specialCharCount = 0;
8
9
10
11
12
13
14
15
16
17
for (char c input.toCharArray()) {
if (Character.isUpperCase(c)) {
upper CaseCount++;
} else if (Character.isLowerCase(c)) {
lower CaseCount++;
} else if (Character.isDigit(c)) {
numericCount++;
} else {
specialCharCount++;
18
}
19
}
20
21
22
23
24
25
26
27
HashMap<String, Integer> character Counts = new HashMap<>();characterCounts.put("UpperCase", upperCaseCount);
characterCounts.put("LowerCase", lowerCaseCount);characterCounts.put("Numeric", numericCount);
characterCounts.put("SpecialCharacter", specialCharCount);
return characterCounts;
28
29
}
}
Zoom

+ 100%
Close
Chưa có bình luận nào.

Thông tin

Category
SWT301
Thêm bởi
Ngọc Trinh1
Ngày thêm
Lượt xem
1,930
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Image metadata

Filename
SWT301_-_FA_2023_-_PE12_1281.webp
File size
80.6 KB
Dimensions
1936px x 868px

Share this media

Back
Bên trên Bottom