package com.battery.business.service.report;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
import static org.mockito.Mockito.*;
|
import java.math.BigDecimal;
|
import java.util.*;
|
import com.alibaba.fastjson2.JSON;
|
import com.battery.business.domain.*;
|
import com.battery.business.service.*;
|
import org.junit.jupiter.api.Test;
|
|
class SpliceProjectCyclesTest {
|
@Test
|
void actualCyclesBecomeConsecutivePositionsWithFrozenProjectStatistics() {
|
var tests = mock(ITTestService.class);
|
var data = mock(ITestDataQueryService.class);
|
var groups = mock(ITBatteryGroupService.class);
|
var group = new TBatteryGroup(); group.setF("2");
|
when(groups.selectBatteryGroupById(9L)).thenReturn(group);
|
for (long id : List.of(1L, 2L)) {
|
var battery = new TTestBattery(); battery.setTestBatteryId(id); battery.setGroupId(9L);
|
battery.setBatteryNo("电池1"); battery.setFields(List.of());
|
var test = new TTest(); test.setTestId(id); test.setTestStatus("COMPLETED"); test.setBatteries(List.of(battery));
|
when(tests.selectTestById(id)).thenReturn(test);
|
var nos = id == 1 ? List.of(1, 3) : List.of(10, 11);
|
when(data.cycles(id)).thenReturn(nos.stream().map(no -> Map.<String,Object>of("batteryNo", "电池1", "cycleNo", no, "dischargeCapacity", new BigDecimal("0.004"))).toList());
|
when(data.steps(id)).thenReturn(nos.stream().flatMap(no -> List.of(
|
Map.<String,Object>of("batteryNo", "电池1", "cycleNo", no, "stepNo", 8),
|
Map.<String,Object>of("batteryNo", "电池1", "cycleNo", no, "stepNo", 1, "endVoltage", 4)).stream()).toList());
|
}
|
var service = new SpliceReportService(tests, data, null, null, groups);
|
var result = service.preview(List.of(new SpliceReportRequest.Selection(1L, 1L), new SpliceReportRequest.Selection(2L, 2L)));
|
assertEquals(List.of(1, 2, 3, 4), result.cycleNos());
|
assertEquals(Map.of("1", 1, "3", 2), result.segments().get(0).get("cyclePositions"));
|
assertEquals(Map.of("10", 3, "11", 4), result.segments().get(1).get("cyclePositions"));
|
assertEquals(List.of(10, 11), result.segments().get(1).get("originalCycleNos"));
|
var stat = JSON.parseObject(JSON.toJSONString(result.segments().get(0).get("statistics"))).getJSONObject("1");
|
assertEquals(0, new BigDecimal("2").compareTo(stat.getBigDecimal("dischargeCapacityF")));
|
assertNull(stat.get("finalVoltage1"), "末工步缺失不能回退到前一工步电压");
|
assertNull(stat.get("finalVoltage2"), "未定义公式不能补值");
|
verify(data, never()).records(anyLong());
|
group.setF("0");
|
var unavailable = service.preview(List.of(new SpliceReportRequest.Selection(1L, 1L), new SpliceReportRequest.Selection(2L, 2L)));
|
assertNull(JSON.parseObject(JSON.toJSONString(unavailable.segments().get(0).get("statistics"))).getJSONObject("1").get("dischargeCapacityF"));
|
}
|
}
|