forked from OSSDP/Lab2-2022211862
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL2022211862_6_Test.java
More file actions
89 lines (82 loc) · 3.81 KB
/
L2022211862_6_Test.java
File metadata and controls
89 lines (82 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package org.example;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class L2022211862_6_Test {
// 测试目的:验证多个用户中存在子集关系
// 用例:favoriteCompanies = [["leetcode","google","facebook"],["google","microsoft"],["google","facebook"],["google"],["amazon"]]
// 预期输出:[0, 1, 4],因为用户2和用户3的清单是其他人的子集
@Test
public void testPeopleIndexes_withSubset() {
Solution6 solution = new Solution6();
List<List<String>> favoriteCompanies = Arrays.asList(
Arrays.asList("leetcode", "google", "facebook"),
Arrays.asList("google", "microsoft"),
Arrays.asList("google", "facebook"),
Arrays.asList("google"),
Arrays.asList("amazon")
);
List<Integer> expected = Arrays.asList(0, 1, 4);
List<Integer> result = solution.peopleIndexes(favoriteCompanies);
assertEquals(expected, result);
}
// 测试目的:验证所有用户清单都是独立的,没有子集关系
// 用例:favoriteCompanies = [["leetcode"],["google"],["facebook"],["amazon"]]
// 预期输出:[0, 1, 2, 3],因为没有任何子集关系
@Test
public void testPeopleIndexes_noSubset() {
Solution6 solution = new Solution6();
List<List<String>> favoriteCompanies = Arrays.asList(
Arrays.asList("leetcode"),
Arrays.asList("google"),
Arrays.asList("facebook"),
Arrays.asList("amazon")
);
List<Integer> expected = Arrays.asList(0, 1, 2, 3);
List<Integer> result = solution.peopleIndexes(favoriteCompanies);
assertEquals(expected, result);
}
// 测试目的:验证边界条件,输入为空列表
// 用例:favoriteCompanies = []
// 预期输出:[],因为没有用户
@Test
public void testPeopleIndexes_emptyList() {
Solution6 solution = new Solution6();
List<List<String>> favoriteCompanies = new ArrayList<>(); // 空列表的初始化
List<Integer> expected = new ArrayList<>();
List<Integer> result = solution.peopleIndexes(favoriteCompanies);
assertEquals(expected, result);
}
// 测试目的:验证边界条件,只有一个用户
// 用例:favoriteCompanies = [["leetcode"]]
// 预期输出:[0],因为没有其他用户的清单
@Test
public void testPeopleIndexes_singleUser() {
Solution6 solution = new Solution6();
List<List<String>> favoriteCompanies = Arrays.asList(
Arrays.asList("leetcode")
);
List<Integer> expected = Arrays.asList(0);
List<Integer> result = solution.peopleIndexes(favoriteCompanies);
assertEquals(expected, result);
}
// 测试目的:验证大输入集的处理能力(边界条件,100个用户)
// 用例:favoriteCompanies = 100个用户,每个用户的收藏清单不同,彼此没有子集关系
// 预期输出:[0, 1, ..., 99],因为没有子集关系
@Test
public void testPeopleIndexes_largeInput() {
Solution6 solution = new Solution6();
List<List<String>> favoriteCompanies = new ArrayList<>(); // 使用 ArrayList 进行初始化
for (int i = 0; i < 100; i++) {
favoriteCompanies.add(Arrays.asList("company" + i));
}
List<Integer> expected = new ArrayList<>();
for (int i = 0; i < 100; i++) {
expected.add(i);
}
List<Integer> result = solution.peopleIndexes(favoriteCompanies);
assertEquals(expected, result);
}
}