Commit 527b8c29 authored by Kai-Holger Brassel's avatar Kai-Holger Brassel
Browse files

Dimension for VolumetricFlowRate added plus some tests

parent 2d962f5e
Pipeline #4361 failed with stage
in 3 minutes and 11 seconds
...@@ -66,11 +66,11 @@ Some derived units of special interest for urban simulation like kW·h (encodes ...@@ -66,11 +66,11 @@ Some derived units of special interest for urban simulation like kW·h (encodes
| W·h | [L]²·[M]/[T]² | W·h | [L]²·[M]/[T]²
| kW·h | [L]²·[M]/[T]² | kW·h | [L]²·[M]/[T]²
| MW·h | [L]²·[M]/[T]² | MW·h | [L]²·[M]/[T]²
| m³/min | [L]³/[T] | m³/min | [L]³/[T] VolumetricFlowRate
| m³/h | [L]³/[T] | m³/h | [L]³/[T] VolumetricFlowRate
| m³/s | [L]³/[T] | m³/s | [L]³/[T] VolumetricFlowRate
| m³/d | [L]³/[T] | m³/d | [L]³/[T] VolumetricFlowRate
| l/min | [L]³/[T] | l/min | [L]³/[T] VolumetricFlowRate
Some units of special interest for urban simulation introduced with this plug-in: Some units of special interest for urban simulation introduced with this plug-in:
......
...@@ -16,6 +16,7 @@ import tech.units.indriya.function.LogConverter; ...@@ -16,6 +16,7 @@ import tech.units.indriya.function.LogConverter;
import tech.units.indriya.function.MultiplyConverter; import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit; import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.BaseUnit; import tech.units.indriya.unit.BaseUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit; import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.UnitDimension; import tech.units.indriya.unit.UnitDimension;
import tech.units.indriya.unit.Units; import tech.units.indriya.unit.Units;
...@@ -37,13 +38,14 @@ public class UrbanSimulationUnits extends AbstractSystemOfUnits { ...@@ -37,13 +38,14 @@ public class UrbanSimulationUnits extends AbstractSystemOfUnits {
AlternateUnit.of(Units.KILOGRAM, "kgCO₂eq").asType(CarbonEmission.class)); AlternateUnit.of(Units.KILOGRAM, "kgCO₂eq").asType(CarbonEmission.class));
public static final Unit<CarbonEmission> GRAM_CO2_EQUIVALENT = addUnit(KILOGRAM_CO2_EQUIVALENT.divide(1000)); public static final Unit<CarbonEmission> GRAM_CO2_EQUIVALENT = addUnit(KILOGRAM_CO2_EQUIVALENT.divide(1000));
public static final Unit<CarbonEmission> TON_CO2_EQUIVALENT = addUnit(KILOGRAM_CO2_EQUIVALENT.multiply(1000)); public static final Unit<CarbonEmission> TON_CO2_EQUIVALENT = addUnit(KILOGRAM_CO2_EQUIVALENT.multiply(1000));
public static final Unit<Dimensionless> PARTS_PER_MILLION = addUnit(new TransformedUnit<>(AbstractUnit.ONE, public static final Unit<Dimensionless> PARTS_PER_MILLION = addUnit(new TransformedUnit<>(AbstractUnit.ONE,
MultiplyConverter.ofRational(BigInteger.ONE, BigInteger.valueOf(1000000)))); MultiplyConverter.ofRational(BigInteger.ONE, BigInteger.valueOf(1000000))));
public static final Unit<Dimensionless> DECIBEL = addUnit(AbstractUnit.ONE.transform( public static final Unit<Dimensionless> DECIBEL = addUnit(AbstractUnit.ONE.transform(
new LogConverter(10).inverse().concatenate(MultiplyConverter.ofRational(BigInteger.ONE, BigInteger.TEN)))); new LogConverter(10).inverse().concatenate(MultiplyConverter.ofRational(BigInteger.ONE, BigInteger.TEN))));
public static final Unit<Intensity> IRRADIANCE = addUnit( public static final Unit<Intensity> IRRADIANCE = addUnit(
new AlternateUnit<Intensity>(Units.WATT.divide(Units.SQUARE_METRE), "W/m²")); new AlternateUnit<Intensity>(Units.WATT.divide(Units.SQUARE_METRE), "W/m²"));
public static final Unit<VolumetricFlowRate> VOLUMETRIC_FLOW = addUnit(
new ProductUnit<VolumetricFlowRate>(Units.CUBIC_METRE.divide(Units.SECOND))); // , "m³/s"
// To model costs I added monetary units quick and dirty as SI base units. // To model costs I added monetary units quick and dirty as SI base units.
// According to JavaDoc of AbstractUnit, monetary units should rather be // According to JavaDoc of AbstractUnit, monetary units should rather be
......
...@@ -13,10 +13,13 @@ import org.junit.jupiter.api.BeforeAll; ...@@ -13,10 +13,13 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import de.hftstuttgart.cityunits.model.CarbonEmission; import de.hftstuttgart.cityunits.model.CarbonEmission;
import de.hftstuttgart.cityunits.model.VolumetricFlowRate;
import de.hftstuttgart.cityunits.model.Intensity;
import de.hftstuttgart.cityunits.model.UrbanSimulationUnits; import de.hftstuttgart.cityunits.model.UrbanSimulationUnits;
import tech.units.indriya.quantity.Quantities; import tech.units.indriya.quantity.Quantities;
import tech.units.indriya.unit.Units; import tech.units.indriya.unit.Units;
// Quantities.getQuantity("1.50 €"); does not compile in Maven without cast to String ??? // Quantities.getQuantity("1.50 €"); does not compile in Maven without cast to String ???
// mvn install won't run this tests, since tycho (?) handles tests as integration tests, thus, mvn verify is required // mvn install won't run this tests, since tycho (?) handles tests as integration tests, thus, mvn verify is required
class QuantityTest { class QuantityTest {
...@@ -68,14 +71,25 @@ class QuantityTest { ...@@ -68,14 +71,25 @@ class QuantityTest {
} }
@Test @Test
void testCO2eq() { void testIrradiance() {
Quantity<CarbonEmission> q = Quantities.getQuantity((String) "5200.7 kgCO₂eq").asType(CarbonEmission.class); Quantity<Intensity> q = Quantities.getQuantity("1000 W/m²").asType(Intensity.class);
System.out.println(q); assertEquals("[M]/[T]³", q.getUnit().getDimension().toString(), "Wrong dimension!");
}
@Test
void testVolumetricFlows() {
Quantity<VolumetricFlowRate> q = Quantities.getQuantity("10800000 l/h").asType(VolumetricFlowRate.class);
assertEquals("[L]³/[T]", q.getUnit().getDimension().toString(), "Wrong dimension!");
assertEquals("3 m³/s", q.toSystemUnit().toString());
}
@Test
void testCO2eq() {
Quantity<CarbonEmission> q = Quantities.getQuantity((String) "5200.7 kg CO₂eq").asType(CarbonEmission.class);
assertEquals("[M]", q.getUnit().getDimension().toString(), "Wrong dimension!"); assertEquals("[M]", q.getUnit().getDimension().toString(), "Wrong dimension!");
assertTrue(q.isEquivalentTo(Quantities.getQuantity((String) "5.2007 tonCO₂eq").asType(CarbonEmission.class)),
"Wrong conversion from kg of CO₂eq to ton of CO₂eq!");
assertTrue(q.isEquivalentTo(Quantities.getQuantity((String) "5200700 gCO₂eq").asType(CarbonEmission.class)), assertTrue(q.isEquivalentTo(Quantities.getQuantity((String) "5200700 gCO₂eq").asType(CarbonEmission.class)),
"Wrong conversion from kg of CO₂eq to gram of CO₂eq!"); "Wrong conversion from kg of CO₂eq to gram of CO₂eq!");
assertTrue(q.isEquivalentTo(Quantities.getQuantity((String) "5.2007 tonCO₂eq").asType(CarbonEmission.class)),
"Wrong conversion from kg of CO₂eq to ton of CO₂eq!");
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment