!760 CompareUtilTest添加comparingIndexedTest的测试方法到v6.x

Merge pull request !760 from dazer007/v6-dev-compareUtilsTestAdd
This commit is contained in:
Looly 2022-08-23 01:25:23 +00:00 committed by Gitee
commit ceb6049614
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -32,4 +32,29 @@ public class CompareUtilTest {
list.sort(CompareUtil.comparingPinyin(e -> e, true));
Assert.assertEquals(list, descendingOrderResult);
}
@Test
public void comparingIndexedTest() {
List<String> data = ListUtil.of("1", "2", "3", "4", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
List<String> index = ListUtil.view("2", "1", "3", "4");
//错误排序压根没有生效...
data.sort(CompareUtil.comparingIndexed(e -> e, index));
System.out.println(data);
//[1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Assert.assertEquals(data, ListUtil.view("1", "2", "3", "4", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"));
//正确排序index.toArray()
data.sort(CompareUtil.comparingIndexed(e -> e, index.toArray()));
System.out.println(data);
//[5, 6, 7, 8, 9, 10, 2, 2, 1, 1, 3, 3, 4, 4]
Assert.assertEquals(data, ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"));
//正确排序array
String[] indexArray = new String[] {"2", "1", "3", "4"};
data.sort(CompareUtil.comparingIndexed(e -> e, indexArray));
System.out.println(data);
//[5, 6, 7, 8, 9, 10, 2, 2, 1, 1, 3, 3, 4, 4]
Assert.assertEquals(data, ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"));
}
}