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
| package com.zy.common.utils;
|
| import com.alibaba.fastjson.JSONObject;
| import com.zy.common.model.NavigateNode;
| import org.junit.jupiter.api.Test;
| import org.springframework.test.util.ReflectionTestUtils;
|
| import java.util.List;
| import java.util.stream.Collectors;
|
| import static org.junit.jupiter.api.Assertions.assertEquals;
|
| class NavigateUtilsTest {
|
| @Test
| void normalizeStationPath_keepsLoopRevisitStationsWhileCompressingAdjacentDuplicates() {
| NavigateUtils navigateUtils = new NavigateUtils();
|
| @SuppressWarnings("unchecked")
| List<NavigateNode> normalizedPath = (List<NavigateNode>) ReflectionTestUtils.invokeMethod(
| navigateUtils,
| "normalizeStationPath",
| List.of(
| buildNode(121, 0, 0),
| buildNode(121, 0, 1),
| buildNode(124, 0, 2),
| buildNode(186, 0, 3),
| buildNode(189, 0, 4),
| buildNode(121, 0, 5),
| buildNode(124, 0, 6),
| buildNode(124, 0, 7),
| buildNode(125, 0, 8),
| buildNode(127, 0, 9)
| )
| );
|
| List<Integer> stationIdList = normalizedPath.stream()
| .map(node -> JSONObject.parseObject(node.getNodeValue()).getInteger("stationId"))
| .collect(Collectors.toList());
|
| assertEquals(List.of(121, 124, 186, 189, 121, 124, 125, 127), stationIdList);
| }
|
| private NavigateNode buildNode(int stationId, int x, int y) {
| NavigateNode node = new NavigateNode(x, y);
| node.setNodeValue("{\"stationId\":" + stationId + "}");
| return node;
| }
| }
|
|