Search in sources :

Example 76 with Unit

use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.

the class VE_Charge_1_Test method invalid.

@Test
public void invalid() {
    Charge charge = new Charge();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.INPUT);
    v1.setType(Variable.Type.REAL);
    v1.setUnit(new Unit());
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.OUTPUT);
    v2.setType(v1.getType());
    v2.setUnit(v1.getUnit());
    charge.setVariables(Arrays.asList(v1, v2));
    builder.build(charge);
    builder.complete();
    List<ValidationDiagnostic<Charge>> diagnostics = validationError.validate();
    assertEquals(1, diagnostics.size());
    Charge invalidObject = diagnostics.get(0).getValidatedObject();
    List<Variable> variables = invalidObject.getVariables();
    assertTrue(variables.contains(v1));
    assertTrue(variables.contains(v2));
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Charge(com.opensimulationplatform.core.model.modeldescription.variablegroup.charge.Charge) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Test(org.junit.Test)

Example 77 with Unit

use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.

the class VE_Charge_2_Test method invalid.

@Test
public void invalid() {
    Charge charge = new Charge();
    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(Variable.Type.INTEGER);
    v2.setUnit(v1.getUnit());
    charge.setVariables(Arrays.asList(v1, v2));
    builder.build(charge);
    builder.complete();
    List<ValidationDiagnostic<Charge>> diagnostics = validationError.validate();
    assertEquals(1, diagnostics.size());
    Charge invalidObject = diagnostics.get(0).getValidatedObject();
    List<Variable> variables = invalidObject.getVariables();
    assertTrue(variables.contains(v1));
    assertTrue(variables.contains(v2));
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Charge(com.opensimulationplatform.core.model.modeldescription.variablegroup.charge.Charge) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Test(org.junit.Test)

Example 78 with Unit

use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.

the class VE_VariableConnection_3_Test method valid.

@Test
public void valid() {
    Unit ua = new Unit();
    ua.setExponent(Unit.Exponent.KILOGRAM, 1);
    Unit ub = new Unit();
    ub.setExponent(Unit.Exponent.KILOGRAM, 1);
    Variable va = new Variable();
    va.setName("va");
    va.setType(Variable.Type.REAL);
    va.setCausality(Variable.Causality.INPUT);
    va.setUnit(ua);
    Variable vb = new Variable();
    vb.setName("vb");
    vb.setType(Variable.Type.INTEGER);
    vb.setCausality(Variable.Causality.INPUT);
    vb.setUnit(ub);
    VariableConnection vc = new VariableConnection();
    vc.setVariableA(va);
    vc.setVariableB(vb);
    vc.setSimulatorA(new Simulator());
    vc.setSimulatorB(new Simulator());
    builder.build(vc);
    builder.complete();
    List<ValidationDiagnostic<VariableConnection>> diagnostics = validationError.validate();
    assertTrue(diagnostics.isEmpty());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Example 79 with Unit

use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.

the class VariableConnectionsValidatorTest method invalid.

@Test
public void invalid() {
    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, 2);
    variableA.setName("variableA");
    variableA.setUnit(unitA);
    variableA.setType(Variable.Type.INTEGER);
    variableA.setCausality(Variable.Causality.INPUT);
    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(3, diagnostics.size());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Example 80 with Unit

use of com.opensimulationplatform.core.model.modeldescription.Unit in project osp-validator by open-simulation-platform.

the class VariableGroupsValidatorTest method valid.

@Test
public void valid() {
    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();
    v2.setUnit(u1);
    v2.setName("v2");
    v2.setType(Variable.Type.REAL);
    v2.setCausality(Variable.Causality.OUTPUT);
    f1.setVariables(Arrays.asList(v1, v2));
    f1.setName("f1");
    modelDescription.getVariables().add(v1);
    modelDescription.getVariables().add(v2);
    modelDescription.getUnits().add(u1);
    modelDescription.getForces().add(f1);
    VariableGroupsValidator v = new VariableGroupsValidator();
    List<ValidationDiagnostic<VariableGroup>> diagnostics = v.validate(modelDescription);
    assertEquals(0, diagnostics.size());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Force(com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Test(org.junit.Test)

Aggregations

Unit (com.opensimulationplatform.core.model.modeldescription.Unit)149 Variable (com.opensimulationplatform.core.model.modeldescription.Variable)145 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)137 Test (org.junit.Test)137 ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)35 Force (com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force)21 LinearVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity)16 Pressure (com.opensimulationplatform.core.model.modeldescription.variablegroup.pressure.Pressure)13 Torque (com.opensimulationplatform.core.model.modeldescription.variablegroup.torque.Torque)13 Voltage (com.opensimulationplatform.core.model.modeldescription.variablegroup.voltage.Voltage)13 AngularDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.angulardisplacement.AngularDisplacement)11 AngularVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.angularvelocity.AngularVelocity)11 Charge (com.opensimulationplatform.core.model.modeldescription.variablegroup.charge.Charge)11 Current (com.opensimulationplatform.core.model.modeldescription.variablegroup.current.Current)11 LinearDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.lineardisplacement.LinearDisplacement)11 Volume (com.opensimulationplatform.core.model.modeldescription.variablegroup.volume.Volume)11 VolumeFlowRate (com.opensimulationplatform.core.model.modeldescription.variablegroup.volumeflowrate.VolumeFlowRate)11 AngularAcceleration (com.opensimulationplatform.core.model.modeldescription.variablegroup.angularacceleration.AngularAcceleration)9 LinearAcceleration (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearacceleration.LinearAcceleration)9 LinearMechanicalPort (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort)7