package com.trafficaudit.freightforecast.service; import com.trafficaudit.freightforecast.entity.FreightForecastAboveHistory; import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import java.io.InputStream; import java.util.HashSet; import java.util.List; import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; class FreightForecastAboveHistorySeedLoaderTest { @Test void loadsTheVerifiedOctoberHistorySeed() throws Exception { List rows; try (InputStream input = new ClassPathResource( "freight-forecast-above-history-2026-10.tsv").getInputStream()) { rows = FreightForecastAboveHistorySeedLoader.load(input); } assertEquals(636, rows.size()); assertEquals(2026, rows.get(0).getStatYear()); assertEquals("2026-10", rows.get(0).getThroughPeriod()); assertEquals(3, rows.stream() .filter(row -> Boolean.TRUE.equals(row.getCorrected())) .count()); assertEquals(4_843_359.17407395, rows.stream().mapToDouble(FreightForecastAboveHistory::getCumulativeForecast).sum() / 10000.0, 0.000001); assertEquals(4_843_322.66069326, rows.stream().mapToDouble(FreightForecastAboveHistory::getSourceCumulativeForecast).sum() / 10000.0, 0.000001); Set names = new HashSet<>(); for (FreightForecastAboveHistory row : rows) { assertTrue(names.add(row.getEnterpriseName())); assertTrue(row.getCity() != null && row.getCity().endsWith("\u5e02") || "\u6069\u65bd\u5dde".equals(row.getCity()) || "\u795e\u519c\u67b6\u6797\u533a".equals(row.getCity())); } } }