package Sy;import org.junit.Before;import org.junit.Test;import java.util.List;import java.util.Map;import java.util.stream.Collectors;import java.util.stream.Stream;import static org.junit.Assert.assertEquals;import static org.junit.Assert.assertTrue;public class Sy2Test {List<Student> studentList;@Beforepublic void before() {studentList = Stream.generate(Student::new).limit(10).collect(Collectors.toList());System.out.println(studentList);}@Testpublic void testAgeThan20() {System.out.println("年龄大于20");List<Student> result = Sy2.filterAgeThan20(studentList);assertTrue(result.stream().allMatch(s -> s.age > 20));}@Testpublic void testAgeThan20_1() {System.out.println("年龄大于20");List<Student> result = Sy2.filterAgeThan20_1(studentList);assertTrue(result.stream().allMatch(s -> s.age > 20));}@Testpublic void testMajorIsComputer() {System.out.println("专业是计科的学生");List<Student> result = Sy2.filterMajorIsComputer(studentList);assertTrue(result.stream().allMatch(s -> "计科".equals(s.major)));}@Testpublic void testMap() {List<String> result = Sy2.mapName(studentList);assertEquals(studentList.size(), result.size());for (int i=0; i<studentList.size(); i++) {assertEquals(studentList.get(i).name, result.get(i));}}@Testpublic void testGroupByMajor() {Map<String, List<Student>> result = Sy2.groupByMajor(studentList);assertTrue(result.size() > 0);for (String major : result.keySet()) {List<Student> ss = result.get(major);assertTrue(ss.stream().allMatch(s -> major.equals(s.major)));}}@Testpublic void testGroupByAge() {Map<Integer, List<Student>> result = Sy2.groupByAge(studentList);assertTrue(result.size() > 0);for (Integer age : result.keySet()) {List<Student> ss = result.get(age);assertTrue(ss.stream().allMatch(s -> age.equals(s.age)));}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。