mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix test
This commit is contained in:
parent
e8a50775d0
commit
82fb4e22b1
@ -38,22 +38,28 @@ public class CompareUtilTest {
|
|||||||
List<String> data = ListUtil.of("1", "2", "3", "4", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
|
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");
|
List<String> index = ListUtil.view("2", "1", "3", "4");
|
||||||
|
|
||||||
//错误,排序压根没有生效...
|
|
||||||
data.sort(CompareUtil.comparingIndexed(e -> e, index));
|
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]
|
//[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"));
|
Assert.assertEquals(ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void comparingIndexedTest2() {
|
||||||
|
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");
|
||||||
|
|
||||||
//正确排序,index.toArray()
|
//正确排序,index.toArray()
|
||||||
data.sort(CompareUtil.comparingIndexed(e -> e, 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]
|
//[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"));
|
Assert.assertEquals(ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"), data);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void comparingIndexedTest3() {
|
||||||
|
List<String> data = ListUtil.of("1", "2", "3", "4", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
|
||||||
|
String[] indexArray = new String[] {"2", "1", "3", "4"};
|
||||||
|
|
||||||
//正确排序,array
|
//正确排序,array
|
||||||
String[] indexArray = new String[] {"2", "1", "3", "4"};
|
|
||||||
data.sort(CompareUtil.comparingIndexed(e -> e, indexArray));
|
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]
|
//[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"));
|
Assert.assertEquals(data, ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user