package com.ruoyi.web.modules.epidemic.support;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

/**
 * FXYZ-UT-001、003～005、007
 */
@DisplayName("RiskFactorWeightRules")
class RiskFactorWeightRulesTest
{

    @Test
    @DisplayName("FXYZ-UT-001 单项正数")
    void ut001_positiveWeight()
    {
        assertTrue(RiskFactorWeightRules.isPositiveWeight(new BigDecimal("0.2")));
        assertFalse(RiskFactorWeightRules.isPositiveWeight(new BigDecimal("-0.1")));
        assertFalse(RiskFactorWeightRules.isPositiveWeight(BigDecimal.ZERO));
    }

    @Test
    @DisplayName("FXYZ-UT-003 合计等于 1")
    void ut003_sumEqualsOne()
    {
        BigDecimal w = new BigDecimal("0.2");
        assertTrue(RiskFactorWeightRules.isSumEqualsOne(w, w, w, w, w));
        assertTrue(RiskFactorWeightRules.isSumEqualsOne(
                new BigDecimal("0.3"),
                new BigDecimal("0.25"),
                new BigDecimal("0.2"),
                new BigDecimal("0.15"),
                new BigDecimal("0.1")));
    }

    @Test
    @DisplayName("FXYZ-UT-004 合计不为 1")
    void ut004_sumNotOne()
    {
        BigDecimal w = new BigDecimal("0.2");
        assertFalse(RiskFactorWeightRules.isSumEqualsOne(w, w, w, w, new BigDecimal("0.3")));
        assertFalse(RiskFactorWeightRules.isSumEqualsOne(
                new BigDecimal("0.5"),
                new BigDecimal("0.5"),
                new BigDecimal("0.5"),
                new BigDecimal("0.5"),
                new BigDecimal("0.5")));
    }

    @Test
    @DisplayName("FXYZ-UT-005 容差边界")
    void ut005_tolerance()
    {
        BigDecimal w = new BigDecimal("0.20001");
        assertTrue(RiskFactorWeightRules.isSumEqualsOne(w, w, w, w, w));
        assertFalse(RiskFactorWeightRules.isSumEqualsOne(
                new BigDecimal("0.2"),
                new BigDecimal("0.2"),
                new BigDecimal("0.2"),
                new BigDecimal("0.2"),
                new BigDecimal("0.1998")));
    }

    @Test
    @DisplayName("FXYZ-UT-007 weightSum 计算")
    void ut007_calcSum()
    {
        assertEquals(new BigDecimal("1.0000"), RiskFactorWeightRules.calcSum(
                new BigDecimal("0.3"),
                new BigDecimal("0.25"),
                new BigDecimal("0.2"),
                new BigDecimal("0.15"),
                new BigDecimal("0.1")));
    }
}
