package com.njcn.gather.tool.adddata.component;

import com.njcn.gather.tool.adddata.pojo.bo.AddDataTableDefinition;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

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

/**
 * 数值生成器测试。
 */
class AddDataValueGeneratorTest {

    @Test
    void shouldGenerateStableDataVRowWithExpectedColumnCount() throws Exception {
        AddDataTableRegistry registry = new AddDataTableRegistry();
        registry.afterPropertiesSet();
        AddDataTableDefinition definition = registry.getDefinition("data_v");
        AddDataValueGenerator generator = new AddDataValueGenerator();

        List<Object> row = generator.generateRow(definition, "f04a9d62e3d24e6580e4f32b40967505", LocalDateTime.of(2026, 4, 28, 10, 10, 0), "A");

        Assertions.assertEquals(definition.getColumns().size(), row.size());
        Assertions.assertEquals("A", row.get(definition.getColumns().indexOf("PHASIC_TYPE")));
        Double rms = (Double) row.get(definition.getColumns().indexOf("RMS"));
        Double rmsMax = (Double) row.get(definition.getColumns().indexOf("RMS_MAX"));
        Double rmsMin = (Double) row.get(definition.getColumns().indexOf("RMS_MIN"));
        Assertions.assertTrue(rmsMax >= rms);
        Assertions.assertTrue(rmsMin <= rms);
    }
}
