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 normalizedPath = (List) 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 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; } }