package com.njcn.gather.steady.checksquare.component;

import com.njcn.gather.steady.checksquare.pojo.vo.SteadyChecksquareSegmentVO;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

/**
 * 数据校验缺失区间计算测试。
 */
class SteadyChecksquareCalculatorTest {

    @Test
    void shouldMergeContinuousMissingSlots() {
        SteadyChecksquareCalculator calculator = new SteadyChecksquareCalculator();
        List<LocalDateTime> slots = Arrays.asList(
                LocalDateTime.of(2026, 5, 1, 0, 0),
                LocalDateTime.of(2026, 5, 1, 0, 1),
                LocalDateTime.of(2026, 5, 1, 0, 2),
                LocalDateTime.of(2026, 5, 1, 0, 3),
                LocalDateTime.of(2026, 5, 1, 0, 4)
        );

        List<SteadyChecksquareSegmentVO> segments = calculator.buildSegments(slots,
                new HashSet<LocalDateTime>(Arrays.asList(slots.get(0), slots.get(3))), 1);

        Assertions.assertEquals(4, segments.size());
        Assertions.assertEquals("MISSING", segments.get(1).getStatus());
        Assertions.assertEquals("2026-05-01 00:01:00", segments.get(1).getStartTime());
        Assertions.assertEquals("2026-05-01 00:02:00", segments.get(1).getEndTime());
        Assertions.assertEquals(Integer.valueOf(2), segments.get(1).getMissingPointCount());
        Assertions.assertEquals(Integer.valueOf(2), segments.get(1).getDurationMinutes());
    }
}
