use of javax.measure.quantity.Temperature in project smarthome by eclipse.
the class QuantityTypeArithmeticGroupFunctionTest method testMinFunctionQuantityTypeDifferentUnits.
@Test
public void testMinFunctionQuantityTypeDifferentUnits() {
items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("100 °C")));
items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
items.add(createNumberItem("TestItem3", Temperature.class, new QuantityType<Temperature>("113 °F")));
items.add(createNumberItem("TestItem4", Temperature.class, UnDefType.UNDEF));
items.add(createNumberItem("TestItem5", Temperature.class, new QuantityType<Temperature>("294.15 K")));
function = new QuantityTypeArithmeticGroupFunction.Min(Temperature.class);
State state = function.calculate(items);
assertEquals(new QuantityType<Temperature>("294.15 K"), state);
}
use of javax.measure.quantity.Temperature in project smarthome by eclipse.
the class QuantityTypeArithmeticGroupFunctionTest method testAvgFunctionQuantityType.
@Test
public void testAvgFunctionQuantityType() {
items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("100 °C")));
items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
items.add(createNumberItem("TestItem3", Temperature.class, new QuantityType<Temperature>("200 °C")));
items.add(createNumberItem("TestItem4", Temperature.class, UnDefType.UNDEF));
items.add(createNumberItem("TestItem5", Temperature.class, new QuantityType<Temperature>("300 °C")));
function = new QuantityTypeArithmeticGroupFunction.Avg(Temperature.class);
State state = function.calculate(items);
assertEquals(new QuantityType<Temperature>("200 °C"), state);
}
use of javax.measure.quantity.Temperature in project smarthome by eclipse.
the class CoreItemFactoryTest method createNumberItemWithDimension.
@Test
public void createNumberItemWithDimension() {
NumberItem numberItem = (NumberItem) coreItemFactory.createItem(CoreItemFactory.NUMBER + ":Temperature", "myNumberItem");
assertThat(numberItem.getDimension(), equalTo(Temperature.class));
}
use of javax.measure.quantity.Temperature in project smarthome by eclipse.
the class GroupItemTest method assertThatNumberGroupItemWithDimensionCalculatesCorrectState.
@SuppressWarnings("null")
@Test
public void assertThatNumberGroupItemWithDimensionCalculatesCorrectState() {
NumberItem baseItem = createNumberItem("baseItem", Temperature.class, UnDefType.NULL);
GroupFunctionDTO gfDTO = new GroupFunctionDTO();
gfDTO.name = "sum";
GroupFunction function = groupFunctionHelper.createGroupFunction(gfDTO, Collections.emptyList(), Temperature.class);
GroupItem groupItem = new GroupItem("number", baseItem, function);
groupItem.setUnitProvider(unitProvider);
NumberItem celsius = createNumberItem("C", Temperature.class, new QuantityType<Temperature>("23 °C"));
groupItem.addMember(celsius);
NumberItem fahrenheit = createNumberItem("F", Temperature.class, new QuantityType<Temperature>("23 °F"));
groupItem.addMember(fahrenheit);
NumberItem kelvin = createNumberItem("K", Temperature.class, new QuantityType<Temperature>("23 K"));
groupItem.addMember(kelvin);
QuantityType<?> state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class);
assertThat(state.getUnit(), is(Units.CELSIUS));
assertThat(state.doubleValue(), is(-232.15d));
celsius.setState(new QuantityType<Temperature>("265 °C"));
state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class);
assertThat(state.getUnit(), is(Units.CELSIUS));
assertThat(state.doubleValue(), is(9.85d));
}
use of javax.measure.quantity.Temperature in project smarthome by eclipse.
the class SmartHomeUnitsTest method testFahrenheit2Kelvin.
@Test
public void testFahrenheit2Kelvin() {
Quantity<Temperature> fahrenheit = Quantities.getQuantity(new BigDecimal("100"), ImperialUnits.FAHRENHEIT);
Quantity<Temperature> kelvin = fahrenheit.to(SmartHomeUnits.KELVIN);
assertThat(kelvin.getUnit(), is(SmartHomeUnits.KELVIN));
assertThat(kelvin.getValue().doubleValue(), is(closeTo(310.92777777777777778d, DEFAULT_ERROR)));
}
Aggregations