|
|
@@ -1,25 +1,31 @@
|
|
|
package top.haijunit.train.test;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.aspectj.lang.annotation.Before;
|
|
|
-import org.junit.jupiter.api.BeforeAll;
|
|
|
-import org.junit.jupiter.api.BeforeEach;
|
|
|
-import org.junit.jupiter.api.DisplayName;
|
|
|
-import org.junit.jupiter.api.Test;
|
|
|
+import org.junit.jupiter.api.*;
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
import org.junit.jupiter.params.provider.CsvSource;
|
|
|
import org.junit.jupiter.params.provider.ValueSource;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import top.haijunit.common.utils.StreamUtils;
|
|
|
import top.haijunit.train.TrainServerMain;
|
|
|
+import top.haijunit.train.domain.constant.DirectionEnum;
|
|
|
import top.haijunit.train.domain.entity.SignStopEntity;
|
|
|
+import top.haijunit.train.domain.entity.TrainEntity;
|
|
|
import top.haijunit.train.service.SectionService;
|
|
|
import top.haijunit.train.simulation.domain.SectionItem;
|
|
|
+import top.haijunit.train.simulation.domain.TrainItem;
|
|
|
import top.haijunit.train.simulation.domain.TrainTravel;
|
|
|
+import top.haijunit.train.simulation.train.TrainComputerService;
|
|
|
+import top.haijunit.train.utils.NumberUtil;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.IntStream;
|
|
|
|
|
|
/**
|
|
|
* @author zhanghaijun
|
|
|
@@ -33,6 +39,8 @@ public class ComputerRouteTest {
|
|
|
|
|
|
@Autowired
|
|
|
private SectionService sectionService;
|
|
|
+ @Autowired
|
|
|
+ private TrainComputerService trainComputerService;
|
|
|
// 进路区段集合
|
|
|
private List<SectionItem> sectionItems;
|
|
|
|
|
|
@@ -40,8 +48,8 @@ public class ComputerRouteTest {
|
|
|
@BeforeEach
|
|
|
void localAllRoute() {
|
|
|
this.sectionItems = sectionService.getAllSection();
|
|
|
- this.sectionItems.forEach(item -> log.info("id:{}, 进路:{}, 区段名称:{}, 区段Id:{}, 上一个:{}, 下一个:{}, 道岔:{}, 折返:{}", item.getId(), item.getRouteName(), item.getSectionName(), item.getSectionId(), item.getPreId(), item.getNextId(), item.isSwitch(), item.isTurnBack()));
|
|
|
- log.info("------ 进路区段集合 ------");
|
|
|
+ // this.sectionItems.forEach(item -> log.info("id:{}, 进路:{}, 区段名称:{}, 区段Id:{}, 上一个:{}, 下一个:{}, 道岔:{}, 折返:{}", item.getId(), item.getRouteName(), item.getSectionName(), item.getSectionId(), item.getPreId(), item.getNextId(), item.isSwitch(), item.isTurnBack()));
|
|
|
+ // log.info("------ 进路区段集合 ------");
|
|
|
}
|
|
|
|
|
|
@DisplayName("列车行驶-上行")
|
|
|
@@ -69,6 +77,24 @@ public class ComputerRouteTest {
|
|
|
HashMap<Long, SignStopEntity> stopSignalMap = sectionService.getStopSignalMap();
|
|
|
TrainTravel trainTravel = new TrainTravel(this.sectionItems, stopSignalMap);
|
|
|
TrainTravel.TravelItem travel = trainTravel.travel(id, new BigDecimal(offset), new BigDecimal(distance));
|
|
|
- log.info("当前的位置, 方向:{}, 是否停车:{}, 区段:{}, 偏移量:{}", travel.getSection().getDirection().getDescribe(), travel.isStop(), travel.getSection().getSectionName(), travel.getOffset());
|
|
|
+ SectionItem section = travel.getSection();
|
|
|
+ log.info("当前的位置, 方向:{}, 是否停车:{}, 区段:{}, 偏移量:{}", section.getDirection().getDescribe(), travel.isStop(), section.getSectionName(), travel.getOffset());
|
|
|
+ Assertions.assertTrue(NumberUtil.isLess(travel.getOffset(), section.getSectionLength()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @DisplayName("计算MA")
|
|
|
+ @ParameterizedTest
|
|
|
+ @CsvSource({"108001-103009,50,3", "108001-103009,40,3", "108005-103018,50,3", "108005-103018,40,3"})
|
|
|
+ void computeMa(String id, Integer offset, Integer count) {
|
|
|
+ this.trainDistanceMaTest(id, offset, count);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void trainDistanceMaTest(String id, Integer offset, Integer count) {
|
|
|
+ int index = IntStream.range(0, this.sectionItems.size()).filter(i -> this.sectionItems.get(i).getId().equals(id)).findFirst().orElse(-1);
|
|
|
+ List<SectionItem> list = CollUtil.sub(this.sectionItems, index, index + count);
|
|
|
+ SectionItem sectionItem = this.sectionItems.stream().filter(item -> item.getId().equals(id)).findFirst().orElseThrow();
|
|
|
+ Assertions.assertTrue(NumberUtil.isLess(new BigDecimal(offset), sectionItem.getSectionLength()));
|
|
|
+ BigDecimal distanceMa = trainComputerService.getDistanceMa(list, sectionItem, new BigDecimal(offset), BigDecimal.ZERO);
|
|
|
+ log.error("MA计算, 当前区段: {}, 方向: {}, 偏移量: {}, 进路: {}, MA: {}", sectionItem.getSectionName(), sectionItem.getDirection().getDescribe(), offset, list.stream().map(item -> item.getSectionName() + "|" + item.getSectionLength()).collect(Collectors.joining(",")), distanceMa);
|
|
|
}
|
|
|
}
|