Aufgrund einer Wartung wird GitLab am 18.01. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 18.01. between 8:00 and 9:00 am.

Commit ab910201 authored by Ievgen Strepkov's avatar Ievgen Strepkov
Browse files

Completely translated the model and added the tests for each component

parent 8531b651
......@@ -3,19 +3,97 @@ package de.monticore.lang.monticar.generator;
import de.monticore.lang.monticar.generator.order.simulator.AbstractSymtab;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.nio.file.*;
import de.monticore.lang.monticar.generator.cpp.resolver.ResolverFactory;
import de.monticore.lang.monticar.generator.cpp.resolver.Resolver;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
public class SimulatorTSTest extends AbstractSymtab{
@Test
public void resolveModelDoorStatus() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol =
symtab.<ExpandedComponentInstanceSymbol>resolve("doors.doorStatus",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
@Test
public void resolveModelGameOverTrigger() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol =
symtab.<ExpandedComponentInstanceSymbol>resolve("feature.gameOverTrigger",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
@Test
public void resolveModelBrakeLightsControl() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol =
symtab.<ExpandedComponentInstanceSymbol>resolve("lights.brakeLightsControl",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
@Test
public void resolveModelIndicatorStatus() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol =
symtab.<ExpandedComponentInstanceSymbol>resolve("lights.indicatorStatus",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
@Test
public void resolveModelsLightTimer() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol =
symtab.<ExpandedComponentInstanceSymbol>resolve("lights.lightTimer",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
@Ignore
@Test
public void resolveModel() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts");
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol =
symtab.<ExpandedComponentInstanceSymbol>resolve("main.sDCS",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
@Test
public void resolveModelsConstantVelocity() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol =
symtab.<ExpandedComponentInstanceSymbol>resolve("movement.constantVelocity",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
@Test
public void resolveModelsSteeringControl() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol =
symtab.<ExpandedComponentInstanceSymbol>resolve("montiarc.constant_velocity",ExpandedComponentInstanceSymbol.KIND).orElse(null);
symtab.<ExpandedComponentInstanceSymbol>resolve("movement.steeringControl",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
......
package montiarc;
component Constant_velocity {
port
in (0km/h : 250km/h) velocity,
in (0s:1000s) time, // (0s:1ms:00 s)
out (-2m/s^2:2m/s^2) acceleration,
out (-180°:180°) steering;
implementation Math {
B cond = time < 1s;
acceleration = cond ? 0 m/s^2 : 2 m/s^2;
steering = 0°;
}
}
package montiarc;
import montiarc.atomic.*;
component Constant_velocity {
port
in (0km/h : 250km/h) velocity,
in (-oo:oo) time, // this is shit!, it must be (0s:1ms:00 s)
out (-2m/s^2:2m/s^2) acceleration,
out (-180°:180°) steering;
instance Less<N1> relationalOperator;
instance SwitchB<N1> switchBlock;
connect 0 /*Constant3*/-> steering;
connect switchBlock.out1 -> acceleration;
connect relationalOperator.out1 -> switchBlock.cond;
connect 2/*Constant2*/ -> switchBlock.in1; // this should give you a CoCo error
connect 0/*Constant1*/ -> switchBlock.in3; // this too (because 0 will be propagated to acceleration, but acceleration is not unit-less)
connect time -> relationalOperator.in1;
connect 1/*Constant*/ -> relationalOperator.in2;
/*
implementation Math {
B cond = time < 1s;
acceleration = cond ? 0 m/s^2 : 2 m/s^2;
steering = 0°;
}
*/
}
package montiarc.atomic;
component Less<T> {
port
in T in1,
in T in2,
out B out1;
implementation Math{
if in1 < in2{
out1 = true;
}
else{
out1 = false;
}
end
}
}
\ No newline at end of file
package montiarc.atomic;
component SwitchB<T> {
port
in T in1,
in B cond,
in T in3,
out T out1;
implementation Math{
if cond{
out1 = in1;
}
else {
out1 = in2;
}
end
}
}
\ No newline at end of file
package visualization.basics;
component And {
port
in Boolean in1,
in Boolean in2,
out Boolean out1;
}
\ No newline at end of file
package visualization.basics;
component Constant<T>(T value) {
port
out T out1;
}
\ No newline at end of file
package visualization.basics;
component Equals<T> {
port
in T in1,
in T in2,
out Boolean out1;
}
\ No newline at end of file
package visualization.basics;
component Greater<T> {
port
in T in1,
in T in2,
out Boolean out1;
}
\ No newline at end of file
package visualization.basics;
component GreaterEquals<T> {
port
in T in1,
in T in2,
out Boolean out1;
}
\ No newline at end of file
package visualization.basics;
component Less<T> {
port
in T in1,
in T in2,
out Boolean out1;
}
\ No newline at end of file
package visualization.basics;
component Mod<T> {
port
in T in1,
in T in2,
out T out1;
}
\ No newline at end of file
package visualization.basics;
component Not<T> {
port
in T in1,
out T out1;
}
\ No newline at end of file
package visualization.basics;
component Or<T> {
port
in Boolean in1,
in Boolean in2,
out Boolean out1;
}
\ No newline at end of file
package visualization.basics;
component PlusMinus<T> {
port
in T in1,
in T in2,
out T out1;
}
\ No newline at end of file
package visualization.basics;
component Sum<T> {
port
in T in1,
in T in2,
out T out1;
}
\ No newline at end of file
package visualization.basics;
component SwitchB<T> {
port
in T in1, //if
in Boolean cond, // condition
in T in3, //else
out T out1;
}
\ No newline at end of file
package visualization.doors;
import visualization.basics.Constant;
import visualization.basics.Equals;
import visualization.basics.Less;
component DoorStatus {
port
in (0km/h : 250km/h) velocity,
out Boolean status;
in (0km/h:250km/h) velocity,
out (0:1) status;
instance Constant<Double>(0.1) idle;
instance Less<Double> less;
implementation Math {
//if the velocity of the car is less than idle than doorStatus is true
connect velocity -> less.in1;
connect idle.out1 -> less.in2;
connect less.out1 -> status;
B test = velocity < 1 km/h
status = test;
}
}
\ No newline at end of file
package visualization.feature;
import visualization.basics.Constant;
import visualization.basics.Greater;
import visualization.basics.Less;
import visualization.basics.Or;
component GameOverTrigger {
port
in N x,
in N y,
out Boolean status;
// The boundaries of the 3D world
instance Constant<Double>(-150) leftBoundary;
instance Constant<Double>(150) rightBoundary;
instance Constant<Double>(200) aboveBoundary;
instance Constant<Double>(-200) belowBoundary;
instance Greater<Double> greater1;
instance Greater<Double> greater2;
instance Less<Double> less1;
instance Less<Double> less2;
instance Or<Boolean> or1;
instance Or<Boolean> or2;
instance Or<Boolean> or3;
in N1 x,
in N1 y,
out B status;
// if the car drives out of the world than the Trigger Status is true
connect x -> greater1.in1;
connect aboveBoundary.out1 -> greater1.in2;
connect x -> less1.in1;
connect belowBoundary.out1 -> less1.in2;
connect greater1.out1 -> or1.in1;
connect less1.out1 -> or1.in2;
implementation Math {
connect y -> greater2.in1;
connect rightBoundary.out1 -> greater2.in2;
connect y -> less2.in1;
connect leftBoundary.out1 -> less2.in2;
connect greater2.out1 -> or2.in1;
connect less2.out1 -> or2.in2;
// The boundaries of the 3D world
B aboveBnd = x > 200;
B belowBnd = x < -200;
B rightBnd = y > 150;
B leftBnd = y < -150;
connect or1.out1 -> or3.in1;
connect or2.out1 -> or3.in2;
connect or3.out1 -> status;
status = aboveBnd || belowBnd || rightBnd || leftBnd;
}
}
\ No newline at end of file
package visualization.lights;
component BrakeLightsControl {
port
in (0s:1000s) time,
out B status;
implementation Math {
// Turn brake lights on after 1 second
status = time > 1s;
}
}
\ No newline at end of file
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