use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.
the class VolumeFlowRateValidatorTest method valid.
@Test
public void valid() {
ModelDescription modelDescription = new ModelDescription();
VolumeFlowRate volumeFlowRate = new VolumeFlowRate();
Variable v1 = new Variable();
v1.setCausality(Variable.Causality.INPUT);
v1.setType(Variable.Type.REAL);
v1.setUnit(new Unit());
Variable v2 = new Variable();
v2.setCausality(v1.getCausality());
v2.setType(v1.getType());
v2.setUnit(v1.getUnit());
volumeFlowRate.setVariables(Arrays.asList(v1, v2));
modelDescription.getVolumeFlowRates().add(volumeFlowRate);
VolumeFlowRateValidator v = new VolumeFlowRateValidator();
List<ValidationDiagnostic<VolumeFlowRate>> diagnostics = v.validate(modelDescription);
assertTrue(diagnostics.isEmpty());
}
use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.
the class VE_VolumeFlowRate_3_Test method invalid.
@Test
public void invalid() {
VolumeFlowRate volumeFlowRate = new VolumeFlowRate();
Variable v1 = new Variable();
v1.setCausality(Variable.Causality.INPUT);
v1.setType(Variable.Type.REAL);
v1.setUnit(new Unit());
Variable v2 = new Variable();
v2.setCausality(v1.getCausality());
v2.setType(v1.getType());
Unit u = new Unit();
u.setExponent(Unit.Exponent.KILOGRAM, 1);
v2.setUnit(u);
volumeFlowRate.setVariables(Arrays.asList(v1, v2));
builder.build(volumeFlowRate);
builder.complete();
List<ValidationDiagnostic<VolumeFlowRate>> diagnostics = validationError.validate();
assertEquals(1, diagnostics.size());
VolumeFlowRate invalidObject = diagnostics.get(0).getValidatedObject();
List<Variable> variables = invalidObject.getVariables();
assertTrue(variables.contains(v1));
assertTrue(variables.contains(v2));
}
use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.
the class VariableTypeConverterTest method canConvert.
@Test
public void canConvert() {
ConverterContext converterContext = new ConverterContext();
Variable v = new Variable();
v.setName("variableName");
converterContext.modelDescription.getVariables().add(v);
Unit u = new Unit();
u.setName("unitName");
converterContext.modelDescription.getUnits().add(u);
VariableType variableType = new VariableType();
variableType.setRef(v.getName().get());
variableType.setUnit(u.getName().get());
VariableTypeConverter variableTypeConverter = new VariableTypeConverter(converterContext);
Variable variable = variableTypeConverter.convert(variableType);
assertEquals(v, variable);
assertEquals(u, variable.getUnit());
}
use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.
the class UnitTypeConverter method convert.
@Override
public Unit convert(UnitType unitType) {
Unit unit = new Unit();
unit.setName(unitType.getName());
Fmi2Unit.BaseUnit baseUnit = unitType.getBaseUnit();
unit.setFactor(baseUnit.getFactor());
unit.setOffset(baseUnit.getOffset());
unit.setExponent(KILOGRAM, baseUnit.getKg());
unit.setExponent(METER, baseUnit.getM());
unit.setExponent(SECOND, baseUnit.getS());
unit.setExponent(AMPERE, baseUnit.getA());
unit.setExponent(KELVIN, baseUnit.getK());
unit.setExponent(MOL, baseUnit.getMol());
unit.setExponent(CANDELA, baseUnit.getCd());
unit.setExponent(RADIAN, baseUnit.getRad());
unit.setExponent(PERCENT, baseUnit.getPercent());
return unit;
}
use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.
the class VE_AngularDisplacement_3_Test method valid.
@Test
public void valid() {
AngularDisplacement angularDisplacement = new AngularDisplacement();
Variable v1 = new Variable();
v1.setCausality(Variable.Causality.INPUT);
v1.setType(Variable.Type.REAL);
v1.setUnit(new Unit());
Variable v2 = new Variable();
v2.setCausality(v1.getCausality());
v2.setType(v1.getType());
v2.setUnit(v1.getUnit());
angularDisplacement.setVariables(Arrays.asList(v1, v2));
builder.build(angularDisplacement);
builder.complete();
List<ValidationDiagnostic<AngularDisplacement>> diagnostics = validationError.validate();
assertTrue(diagnostics.isEmpty());
}
Aggregations