use of com.opensimulationplatform.core.model.modeldescription.Variable in project osp-validator by open-simulation-platform.
the class VariableConnectionsValidatorTest method valid.
@Test
public void valid() {
SystemStructure systemStructure = new SystemStructure();
VariableConnection variableConnection = new VariableConnection();
Simulator simulatorA = new Simulator();
Variable variableA = new Variable();
Unit unitA = new Unit();
unitA.setExponent(Unit.Exponent.KILOGRAM, 1);
variableA.setName("variableA");
variableA.setUnit(unitA);
variableA.setType(Variable.Type.REAL);
variableA.setCausality(Variable.Causality.OUTPUT);
simulatorA.getModelDescription().getVariables().add(variableA);
variableConnection.setSimulatorA(simulatorA);
variableConnection.setVariableA(variableA);
Simulator simulatorB = new Simulator();
Variable variableB = new Variable();
Unit unitB = new Unit();
unitB.setExponent(Unit.Exponent.KILOGRAM, 1);
variableB.setName("variableB");
variableB.setUnit(unitB);
variableB.setType(Variable.Type.REAL);
variableB.setCausality(Variable.Causality.INPUT);
simulatorB.getModelDescription().getVariables().add(variableB);
variableConnection.setSimulatorB(simulatorB);
variableConnection.setVariableB(variableB);
systemStructure.getSimulators().add(simulatorA);
systemStructure.getSimulators().add(simulatorB);
systemStructure.getVariableConnections().add(variableConnection);
VariableConnectionsValidator validator = new VariableConnectionsValidator();
List<ValidationDiagnostic<VariableConnection>> diagnostics = validator.validate(systemStructure);
assertEquals(0, diagnostics.size());
}
use of com.opensimulationplatform.core.model.modeldescription.Variable in project osp-validator by open-simulation-platform.
the class VariableGroupsValidatorTest method invalid.
@Test
public void invalid() {
ModelDescription modelDescription = new ModelDescription();
Force f1 = new Force();
Variable v1 = new Variable();
Unit u1 = new Unit();
u1.setExponent(Unit.Exponent.KILOGRAM, 1);
v1.setUnit(u1);
v1.setName("v1");
v1.setType(Variable.Type.REAL);
v1.setCausality(Variable.Causality.OUTPUT);
Variable v2 = new Variable();
Unit u2 = new Unit();
u2.setExponent(Unit.Exponent.KILOGRAM, 2);
v2.setUnit(u2);
v2.setName("v2");
v2.setType(Variable.Type.REAL);
v2.setCausality(Variable.Causality.OUTPUT);
f1.setVariables(Arrays.asList(v1, v2));
f1.setName("f1");
Force f2 = new Force();
Variable v3 = new Variable();
v3.setUnit(u1);
v3.setName("v3");
v3.setType(Variable.Type.REAL);
v3.setCausality(Variable.Causality.OUTPUT);
Variable v4 = new Variable();
v4.setUnit(u1);
v4.setName("v4");
v4.setType(Variable.Type.INTEGER);
v4.setCausality(Variable.Causality.OUTPUT);
f2.setVariables(Arrays.asList(v3, v4));
f2.setName("f2");
Force f3 = new Force();
Variable v5 = new Variable();
v5.setUnit(u1);
v5.setName("v5");
v5.setType(Variable.Type.REAL);
v5.setCausality(Variable.Causality.OUTPUT);
Variable v6 = new Variable();
v6.setUnit(u1);
v6.setName("v6");
v6.setType(Variable.Type.REAL);
v6.setCausality(Variable.Causality.INPUT);
f3.setVariables(Arrays.asList(v5, v6));
f3.setName("f3");
modelDescription.getVariables().add(v1);
modelDescription.getVariables().add(v2);
modelDescription.getVariables().add(v3);
modelDescription.getVariables().add(v4);
modelDescription.getVariables().add(v5);
modelDescription.getVariables().add(v6);
modelDescription.getUnits().add(u1);
modelDescription.getUnits().add(u2);
modelDescription.getForces().add(f1);
modelDescription.getForces().add(f2);
modelDescription.getForces().add(f3);
VariableGroupsValidator v = new VariableGroupsValidator();
List<ValidationDiagnostic<VariableGroup>> diagnostics = v.validate(modelDescription);
assertEquals(3, diagnostics.size());
}
use of com.opensimulationplatform.core.model.modeldescription.Variable in project osp-validator by open-simulation-platform.
the class ElectromagneticPortValidatorTest method valid.
@Test
public void valid() {
ModelDescription modelDescription = new ModelDescription();
Variable v1 = new Variable();
v1.setCausality(Variable.Causality.OUTPUT);
Voltage voltage = new Voltage();
voltage.setVariables(Arrays.asList(v1));
Variable v2 = new Variable();
v2.setCausality(Variable.Causality.INPUT);
Current current = new Current();
current.setVariables(Arrays.asList(v2));
ElectromagneticPort electromagneticPort = new ElectromagneticPort();
electromagneticPort.setVoltage(voltage);
electromagneticPort.setCurrent(current);
modelDescription.getElectromagneticPorts().add(electromagneticPort);
ElectromagneticPortValidator electromagneticPortValidator = new ElectromagneticPortValidator();
List<ValidationDiagnostic<ElectromagneticPort>> diagnostics = electromagneticPortValidator.validate(modelDescription);
assertTrue(diagnostics.isEmpty());
}
use of com.opensimulationplatform.core.model.modeldescription.Variable in project osp-validator by open-simulation-platform.
the class ElectromagneticPortValidatorTest method invalid.
@Test
public void invalid() {
ModelDescription modelDescription = new ModelDescription();
Variable v1 = new Variable();
v1.setCausality(Variable.Causality.OUTPUT);
Voltage voltage = new Voltage();
voltage.setVariables(Arrays.asList(v1));
Variable v2 = new Variable();
v2.setCausality(Variable.Causality.OUTPUT);
Current current = new Current();
current.setVariables(Arrays.asList(v2));
ElectromagneticPort electromagneticPort = new ElectromagneticPort();
electromagneticPort.setVoltage(voltage);
electromagneticPort.setCurrent(current);
modelDescription.getElectromagneticPorts().add(electromagneticPort);
ElectromagneticPortValidator electromagneticPortValidator = new ElectromagneticPortValidator();
List<ValidationDiagnostic<ElectromagneticPort>> diagnostics = electromagneticPortValidator.validate(modelDescription);
assertEquals(1, diagnostics.size());
assertEquals(electromagneticPort, diagnostics.get(0).getValidatedObject());
}
use of com.opensimulationplatform.core.model.modeldescription.Variable in project osp-validator by open-simulation-platform.
the class VE_ElectromagneticPort_1_Test method invalid.
@Test
public void invalid() {
Variable v1 = new Variable();
v1.setCausality(Variable.Causality.OUTPUT);
v1.setUnit(new Unit());
v1.setType(Variable.Type.REAL);
Variable v2 = new Variable();
v2.setCausality(Variable.Causality.OUTPUT);
v2.setUnit(new Unit());
v2.setType(Variable.Type.REAL);
Variable v3 = new Variable();
v3.setCausality(Variable.Causality.OUTPUT);
v3.setUnit(new Unit());
v3.setType(Variable.Type.REAL);
Variable v4 = new Variable();
v4.setCausality(Variable.Causality.OUTPUT);
v4.setUnit(new Unit());
v4.setType(Variable.Type.REAL);
Voltage voltage = new Voltage();
voltage.setVariables(Arrays.asList(v1, v2));
Current current = new Current();
current.setVariables(Arrays.asList(v3, v4));
ElectromagneticPort electromagneticPort = new ElectromagneticPort();
electromagneticPort.setVoltage(voltage);
electromagneticPort.setCurrent(current);
builder.build(electromagneticPort);
builder.complete();
List<ValidationDiagnostic<ElectromagneticPort>> diagnostics = validationError.validate();
assertEquals(1, diagnostics.size());
ElectromagneticPort invalidElectromagneticPort = diagnostics.get(0).getValidatedObject();
assertEquals(electromagneticPort, invalidElectromagneticPort);
}
Aggregations