package cn.iocoder.yudao.module.mes.service.pd.knowledge; import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.util.Set; import static org.junit.jupiter.api.Assertions.*; class KnowledgeMatchTest { @Test void matchesOnlyWhenAllSpecifiedConditionsAreSatisfied() { var knowledge = new KnowledgeMatch.Criteria(10L, 20L, new BigDecimal("10"), new BigDecimal("35"), "EXPORT", Set.of("IEC-1", "IEC-2")); assertTrue(KnowledgeMatch.matches(knowledge, new KnowledgeMatch.Request(10L, 20L, new BigDecimal("10"), "EXPORT", Set.of("IEC-1", "IEC-2")))); assertFalse(KnowledgeMatch.matches(knowledge, new KnowledgeMatch.Request(10L, 20L, new BigDecimal("36"), "EXPORT", Set.of("IEC-1", "IEC-2")))); assertFalse(KnowledgeMatch.matches(knowledge, new KnowledgeMatch.Request(10L, 20L, new BigDecimal("20"), "DOMESTIC", Set.of("IEC-1", "IEC-2")))); assertFalse(KnowledgeMatch.matches(knowledge, new KnowledgeMatch.Request(10L, 20L, new BigDecimal("20"), "EXPORT", Set.of("IEC-1", "IEC-3")))); assertFalse(KnowledgeMatch.matches(knowledge, new KnowledgeMatch.Request(10L, null, new BigDecimal("20"), "EXPORT", Set.of("IEC-1", "IEC-2")))); assertFalse(KnowledgeMatch.matches(knowledge, new KnowledgeMatch.Request(11L, 20L, new BigDecimal("20"), "EXPORT", Set.of("IEC-1", "IEC-2")))); } @Test void unrestrictedKnowledgeMatchesWithoutInventingUnknownRequestValues() { var knowledge = new KnowledgeMatch.Criteria(null, null, null, null, "ALL", Set.of()); assertTrue(KnowledgeMatch.matches(knowledge, new KnowledgeMatch.Request(null, null, null, null, Set.of()))); var voltageRestricted = new KnowledgeMatch.Criteria(null, null, BigDecimal.ONE, null, "ALL", Set.of()); assertFalse(KnowledgeMatch.matches(voltageRestricted, new KnowledgeMatch.Request(null, null, null, null, Set.of()))); } }