|
28 | 28 | import java.util.Map;
|
29 | 29 | import java.util.stream.Stream;
|
30 | 30 |
|
| 31 | +import javax.measure.quantity.Dimensionless; |
| 32 | +import javax.measure.quantity.Power; |
| 33 | + |
31 | 34 | import org.eclipse.jdt.annotation.NonNullByDefault;
|
32 | 35 | import org.junit.jupiter.api.BeforeEach;
|
33 | 36 | import org.junit.jupiter.api.Test;
|
@@ -670,10 +673,13 @@ public void testComparingInputStateWithItem(GenericItem linkedItem, State inputS
|
670 | 673 |
|
671 | 674 | public static Stream<Arguments> testFunctions() {
|
672 | 675 | NumberItem powerItem = new NumberItem("Number:Power", "powerItem", UNIT_PROVIDER);
|
| 676 | + NumberItem percentItem = new NumberItem("Number:Dimensionless", "percentItem", UNIT_PROVIDER); |
673 | 677 | NumberItem decimalItem = new NumberItem("decimalItem");
|
674 | 678 | List<Number> numbers = List.of(1, 2, 3, 4, 5);
|
675 | 679 | List<Number> negatives = List.of(-1, -2, -3, -4, -5);
|
676 |
| - List<QuantityType> quantities = numbers.stream().map(n -> new QuantityType(n, Units.WATT)).toList(); |
| 680 | + List<QuantityType<Power>> quantities = numbers.stream().map(n -> new QuantityType<>(n, Units.WATT)).toList(); |
| 681 | + List<QuantityType<Dimensionless>> percentQuantities = numbers.stream() |
| 682 | + .map(n -> new QuantityType<>(n, Units.PERCENT)).toList(); |
677 | 683 | List<DecimalType> decimals = numbers.stream().map(DecimalType::new).toList();
|
678 | 684 | List<DecimalType> negativeDecimals = negatives.stream().map(DecimalType::new).toList();
|
679 | 685 |
|
@@ -715,14 +721,32 @@ public static Stream<Arguments> testFunctions() {
|
715 | 721 | Arguments.of(decimalItem, "$DELTA_PERCENT < 10", decimals, DecimalType.valueOf("0.91"), true), //
|
716 | 722 | Arguments.of(decimalItem, "$DELTA_PERCENT < 10", decimals, DecimalType.valueOf("0.89"), false), //
|
717 | 723 |
|
718 |
| - Arguments.of(decimalItem, "$DELTA_PERCENT < 10", negativeDecimals, DecimalType.valueOf("0"), false), // |
719 |
| - Arguments.of(decimalItem, "10 > $DELTA_PERCENT", negativeDecimals, DecimalType.valueOf("0"), false), // |
| 724 | + Arguments.of(decimalItem, "$DELTA_PERCENT < 10", negativeDecimals, DecimalType.valueOf("0"), false), |
| 725 | + // |
| 726 | + Arguments.of(decimalItem, "10 > $DELTA_PERCENT", negativeDecimals, DecimalType.valueOf("0"), false), |
| 727 | + // |
720 | 728 |
|
721 | 729 | Arguments.of(decimalItem, "< 10%", decimals, DecimalType.valueOf("1.09"), true), //
|
722 | 730 | Arguments.of(decimalItem, "< 10%", decimals, DecimalType.valueOf("1.11"), false), //
|
723 | 731 | Arguments.of(decimalItem, "< 10%", decimals, DecimalType.valueOf("0.91"), true), //
|
724 | 732 | Arguments.of(decimalItem, "< 10%", decimals, DecimalType.valueOf("0.89"), false), //
|
725 | 733 |
|
| 734 | + // Contrast a simple comparison against a Percent QuantityType vs delta percent check |
| 735 | + Arguments.of(percentItem, "> 5%", percentQuantities, QuantityType.valueOf("5.1 %"), true), // |
| 736 | + Arguments.of(percentItem, "$DELTA_PERCENT > 5", percentQuantities, QuantityType.valueOf("5.1 %"), |
| 737 | + false), // |
| 738 | + |
| 739 | + Arguments.of(percentItem, "> 5%", percentQuantities, QuantityType.valueOf("-10 %"), false), // |
| 740 | + Arguments.of(percentItem, "$DELTA_PERCENT > 5", percentQuantities, QuantityType.valueOf("-10 %"), true), // |
| 741 | + |
| 742 | + Arguments.of(percentItem, "< 200%", percentQuantities, QuantityType.valueOf("100 %"), true), // |
| 743 | + Arguments.of(percentItem, "$DELTA_PERCENT < 200", percentQuantities, QuantityType.valueOf("100 %"), |
| 744 | + false), // |
| 745 | + |
| 746 | + Arguments.of(percentItem, "< 200%", percentQuantities, QuantityType.valueOf("-100 %"), true), // |
| 747 | + Arguments.of(percentItem, "$DELTA_PERCENT < 200", percentQuantities, QuantityType.valueOf("-100 %"), |
| 748 | + false), // |
| 749 | + |
726 | 750 | Arguments.of(decimalItem, "1 == $MIN", decimals, DecimalType.valueOf("20"), true), //
|
727 | 751 | Arguments.of(decimalItem, "0 < $MIN", decimals, DecimalType.valueOf("20"), true), //
|
728 | 752 | Arguments.of(decimalItem, "$MIN > 0", decimals, DecimalType.valueOf("20"), true), //
|
|
0 commit comments