mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -26,29 +26,29 @@ public class CoordinateUtilTest {
|
||||
@Test
|
||||
public void wgs84ToGcj02Test() {
|
||||
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToGcj02(116.404, 39.915);
|
||||
Assertions.assertEquals(116.41024449916938D, coordinate.getLng(), 0);
|
||||
Assertions.assertEquals(39.91640428150164D, coordinate.getLat(), 0);
|
||||
Assertions.assertEquals(116.41024449916938D, coordinate.getLng(), 0.00000000000001D);
|
||||
Assertions.assertEquals(39.91640428150164D, coordinate.getLat(), 0.00000000000001D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gcj02ToWgs84Test() {
|
||||
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToWgs84(116.404, 39.915);
|
||||
Assertions.assertEquals(116.39775550083061D, coordinate.getLng(), 0);
|
||||
Assertions.assertEquals(39.91359571849836D, coordinate.getLat(), 0);
|
||||
Assertions.assertEquals(116.39775550083061D, coordinate.getLng(), 0.00000000000001D);
|
||||
Assertions.assertEquals(39.91359571849836D, coordinate.getLat(), 0.00000000000001D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wgs84toBd09Test() {
|
||||
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToBd09(116.404, 39.915);
|
||||
Assertions.assertEquals(116.41662724378733D, coordinate.getLng(), 0);
|
||||
Assertions.assertEquals(39.922699552216216D, coordinate.getLat(), 0);
|
||||
Assertions.assertEquals(116.41662724378733D, coordinate.getLng(), 0.00000000000001D);
|
||||
Assertions.assertEquals(39.922699552216216D, coordinate.getLat(), 0.00000000000001D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wgs84toBd09Test2() {
|
||||
// https://tool.lu/coordinate/
|
||||
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToBd09(122.99395597D, 44.99804071D);
|
||||
Assertions.assertEquals(123.00636516028885D, coordinate.getLng(), 0);
|
||||
Assertions.assertEquals(123.00636516028885D, coordinate.getLng(), 0.00000000000001D);
|
||||
// 不同jdk版本、不同架构jdk, 精度有差异,数值不完全相等,这里增加精度控制delta
|
||||
// 参考:从Java Math底层实现看Arm与x86的差异:https://yikun.github.io/2020/04/10/%E4%BB%8EJava-Math%E5%BA%95%E5%B1%82%E5%AE%9E%E7%8E%B0%E7%9C%8BArm%E4%B8%8Ex86%E7%9A%84%E5%B7%AE%E5%BC%82/
|
||||
Assertions.assertEquals(45.00636909189589D, coordinate.getLat(), 0.00000000000001D);
|
||||
@@ -57,22 +57,22 @@ public class CoordinateUtilTest {
|
||||
@Test
|
||||
public void bd09toWgs84Test() {
|
||||
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.bd09toWgs84(116.404, 39.915);
|
||||
Assertions.assertEquals(116.3913836995125D, coordinate.getLng(), 0);
|
||||
Assertions.assertEquals(39.907253214522164D, coordinate.getLat(), 0);
|
||||
Assertions.assertEquals(116.3913836995125D, coordinate.getLng(), 0.00000000000001D);
|
||||
Assertions.assertEquals(39.907253214522164D, coordinate.getLat(), 0.00000000000001D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gcj02ToBd09Test() {
|
||||
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToBd09(116.404, 39.915);
|
||||
Assertions.assertEquals(116.41036949371029D, coordinate.getLng(), 0);
|
||||
Assertions.assertEquals(39.92133699351022D, coordinate.getLat(), 0);
|
||||
Assertions.assertEquals(116.41036949371029D, coordinate.getLng(), 0.00000000000001D);
|
||||
Assertions.assertEquals(39.92133699351022D, coordinate.getLat(), 0.00000000000001D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bd09toGcj02Test() {
|
||||
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.bd09ToGcj02(116.404, 39.915);
|
||||
Assertions.assertEquals(116.39762729119315D, coordinate.getLng(), 0);
|
||||
Assertions.assertEquals(39.90865673957631D, coordinate.getLat(), 0);
|
||||
Assertions.assertEquals(116.39762729119315D, coordinate.getLng(), 0.00000000000001D);
|
||||
Assertions.assertEquals(39.90865673957631D, coordinate.getLat(), 0.00000000000001D);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -72,10 +72,10 @@ public class MapUtilTest {
|
||||
void mapTest() {
|
||||
// Add test like a foreigner
|
||||
final Map<Integer, String> adjectivesMap = MapUtil.<Integer, String>builder()
|
||||
.put(0, "lovely")
|
||||
.put(1, "friendly")
|
||||
.put(2, "happily")
|
||||
.build();
|
||||
.put(0, "lovely")
|
||||
.put(1, "friendly")
|
||||
.put(2, "happily")
|
||||
.build();
|
||||
|
||||
final Map<Integer, String> resultMap = MapUtil.map(adjectivesMap, (k, v) -> v + " " + PeopleEnum.values()[k].name().toLowerCase());
|
||||
|
||||
@@ -199,11 +199,11 @@ public class MapUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void sortJoinTest(){
|
||||
void sortJoinTest() {
|
||||
final Map<String, String> build = MapUtil.builder(new HashMap<String, String>())
|
||||
.put("key1", "value1")
|
||||
.put("key3", "value3")
|
||||
.put("key2", "value2").build();
|
||||
.put("key1", "value1")
|
||||
.put("key3", "value3")
|
||||
.put("key2", "value2").build();
|
||||
|
||||
final String join1 = MapUtil.sortJoin(build, StrUtil.EMPTY, StrUtil.EMPTY, false);
|
||||
Assertions.assertEquals("key1value1key2value2key3value3", join1);
|
||||
@@ -216,7 +216,7 @@ public class MapUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void ofEntriesTest(){
|
||||
void ofEntriesTest() {
|
||||
final Map<String, Integer> map = MapUtil.ofEntries(MapUtil.entry("a", 1), MapUtil.entry("b", 2));
|
||||
Assertions.assertEquals(2, map.size());
|
||||
|
||||
@@ -225,8 +225,8 @@ public class MapUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getIntTest(){
|
||||
Assertions.assertThrows(NumberFormatException.class, ()->{
|
||||
void getIntTest() {
|
||||
Assertions.assertThrows(NumberFormatException.class, () -> {
|
||||
final Map<String, String> map = MapUtil.ofEntries(MapUtil.entry("a", "d"));
|
||||
final Integer a = MapUtil.getInt(map, "a");
|
||||
Assertions.assertNotNull(a);
|
||||
@@ -234,7 +234,7 @@ public class MapUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getIntValueTest(){
|
||||
void getIntValueTest() {
|
||||
final Map<String, String> map = MapUtil.ofEntries(MapUtil.entry("a", "1"), MapUtil.entry("b", null));
|
||||
final int a = MapUtil.get(map, "a", int.class);
|
||||
Assertions.assertEquals(1, a);
|
||||
@@ -270,9 +270,9 @@ public class MapUtilTest {
|
||||
@Test
|
||||
void computeIfAbsentForJdk8Test() {
|
||||
// https://github.com/apache/dubbo/issues/11986
|
||||
final ConcurrentHashMap<String,Integer> map=new ConcurrentHashMap<>();
|
||||
final ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>();
|
||||
// // map.computeIfAbsent("AaAa", key->map.computeIfAbsent("BBBB",key2->42));
|
||||
MapUtil.computeIfAbsentForJdk8(map, "AaAa", key->map.computeIfAbsent("BBBB",key2->42));
|
||||
MapUtil.computeIfAbsentForJdk8(map, "AaAa", key -> map.computeIfAbsent("BBBB", key2 -> 42));
|
||||
|
||||
Assertions.assertEquals(2, map.size());
|
||||
Assertions.assertEquals(Integer.valueOf(42), map.get("AaAa"));
|
||||
@@ -303,11 +303,13 @@ public class MapUtilTest {
|
||||
public void issue3162Test() {
|
||||
final Map<String, Object> map = new HashMap<String, Object>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put("a", "1");
|
||||
put("b", "2");
|
||||
put("c", "3");
|
||||
}};
|
||||
}
|
||||
};
|
||||
final Map<String, Object> filtered = MapUtil.filter(map, "a", "b");
|
||||
Assertions.assertEquals(2, filtered.size());
|
||||
Assertions.assertEquals("1", filtered.get("a"));
|
||||
@@ -316,7 +318,7 @@ public class MapUtilTest {
|
||||
|
||||
@Test
|
||||
public void ofKvsLinkTest() {
|
||||
LinkedHashMap<String,Long> map2 = MapUtil.ofKvs(
|
||||
final Map<String, Long> map2 = MapUtil.ofKvs(true,
|
||||
"RED", 0xFF0000,
|
||||
"GREEN", 0x00FF00,
|
||||
"BLUE", 0x0000FF);
|
||||
|
Reference in New Issue
Block a user