diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 000000000..f7367e0d4 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 diff --git a/README.md b/README.md index e26e034fc..4ac5eaa43 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,12 @@ The figure below illustrates this behavior using an example. 1. As the joystick remains at a positive value, the reference speed is incremented again. 1. However, it reaches the speed limit so in the next step it is not incremented even though the joystick still has a positive value. 1. Later, the joystick is set to a negative position for one time unit, making the reference speed to decrease as well. + + +[I'm an inline-style link](https://www.google.com) +Emphasis, aka italics, with *asterisks* or _underscores_. +# H1 + +Here is a simple footnote[^1]. + +Csonfliktus diff --git a/pom.xml b/pom.xml index 2be9fb5f5..2469dede9 100644 --- a/pom.xml +++ b/pom.xml @@ -21,13 +21,18 @@ + + com.google.guava + guava + 10.0.1 + junit junit 4.12 test - + org.mockito mockito-core 4.4.0 diff --git a/train-controller/src/main/java/hu/bme/mit/train/controller/TrainControllerImpl.java b/train-controller/src/main/java/hu/bme/mit/train/controller/TrainControllerImpl.java index 06649d278..b00cceb81 100644 --- a/train-controller/src/main/java/hu/bme/mit/train/controller/TrainControllerImpl.java +++ b/train-controller/src/main/java/hu/bme/mit/train/controller/TrainControllerImpl.java @@ -2,11 +2,16 @@ import hu.bme.mit.train.interfaces.TrainController; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; + + public class TrainControllerImpl implements TrainController { private int step = 0; private int referenceSpeed = 0; private int speedLimit = 0; + private Table Tachograph = HashBasedTable.create(); @Override public void followSpeed() { @@ -19,7 +24,7 @@ public void followSpeed() { referenceSpeed = 0; } } - + saveTachograph(); enforceSpeedLimit(); } @@ -46,4 +51,24 @@ public void setJoystickPosition(int joystickPosition) { this.step = joystickPosition; } + @Override + public void emergencyBrake() { + setSpeedLimit(0); + } + + @Override + public void saveTachograph(){ + Tachograph.put(speedLimit, referenceSpeed, step); + } + + @Override + public Table getTachograph(){ + return Tachograph; + } + + @Override + public int getSpeedLimit(){ + return speedLimit; + } + } diff --git a/train-controller/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/train-controller/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 000000000..7f5a1ef4a --- /dev/null +++ b/train-controller/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +hu/bme/mit/train/controller/TrainControllerImpl.class diff --git a/train-controller/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/train-controller/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 000000000..b13b01cc3 --- /dev/null +++ b/train-controller/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/base/train-controller/src/main/java/hu/bme/mit/train/controller/TrainControllerImpl.java diff --git a/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainController.java b/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainController.java index c8adca066..f3148980c 100644 --- a/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainController.java +++ b/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainController.java @@ -1,5 +1,7 @@ package hu.bme.mit.train.interfaces; +import com.google.common.collect.Table; + public interface TrainController { void followSpeed(); @@ -10,4 +12,10 @@ public interface TrainController { void setJoystickPosition(int joystickPosition); + void emergencyBrake(); + + void saveTachograph(); + Table getTachograph(); + int getSpeedLimit(); + } diff --git a/train-interfaces/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/train-interfaces/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 000000000..248759f35 --- /dev/null +++ b/train-interfaces/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +hu/bme/mit/train/interfaces/TrainController.class +hu/bme/mit/train/interfaces/TrainSensor.class +hu/bme/mit/train/interfaces/TrainUser.class diff --git a/train-interfaces/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/train-interfaces/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 000000000..ca4e03d48 --- /dev/null +++ b/train-interfaces/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +/home/cloud/base/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainUser.java +/home/cloud/base/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainController.java +/home/cloud/base/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainSensor.java diff --git a/train-sensor/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/train-sensor/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 000000000..5c6a37510 --- /dev/null +++ b/train-sensor/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +hu/bme/mit/train/sensor/TrainSensorImpl.class diff --git a/train-sensor/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/train-sensor/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 000000000..a99815748 --- /dev/null +++ b/train-sensor/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/base/train-sensor/src/main/java/hu/bme/mit/train/sensor/TrainSensorImpl.java diff --git a/train-sensor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/train-sensor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 000000000..0ad3f3de4 --- /dev/null +++ b/train-sensor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +hu/bme/mit/train/sensor/TrainSensorTest.class diff --git a/train-sensor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/train-sensor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 000000000..e2a796968 --- /dev/null +++ b/train-sensor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/base/train-sensor/src/test/java/hu/bme/mit/train/sensor/TrainSensorTest.java diff --git a/train-sensor/target/surefire-reports/TEST-hu.bme.mit.train.sensor.TrainSensorTest.xml b/train-sensor/target/surefire-reports/TEST-hu.bme.mit.train.sensor.TrainSensorTest.xml new file mode 100644 index 000000000..05ca7b83a --- /dev/null +++ b/train-sensor/target/surefire-reports/TEST-hu.bme.mit.train.sensor.TrainSensorTest.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/train-sensor/target/surefire-reports/hu.bme.mit.train.sensor.TrainSensorTest.txt b/train-sensor/target/surefire-reports/hu.bme.mit.train.sensor.TrainSensorTest.txt new file mode 100644 index 000000000..e7ebbbf62 --- /dev/null +++ b/train-sensor/target/surefire-reports/hu.bme.mit.train.sensor.TrainSensorTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: hu.bme.mit.train.sensor.TrainSensorTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.153 sec diff --git a/train-system/src/main/java/hu/bme/mit/train/system/RunnableImpl.java b/train-system/src/main/java/hu/bme/mit/train/system/RunnableImpl.java new file mode 100644 index 000000000..17f8012a9 --- /dev/null +++ b/train-system/src/main/java/hu/bme/mit/train/system/RunnableImpl.java @@ -0,0 +1,20 @@ +package hu.bme.mit.train.system; + +import hu.bme.mit.train.interfaces.TrainController; + +public class RunnableImpl implements Runnable{ + private TrainController controller; + public RunnableImpl(TrainController c){ + this.controller = c; + } + public Boolean r = true; + public void run(){ + while(r){ + controller.followSpeed(); + try{ + Thread.sleep(1000); + }catch(Exception e){ + } + } + } +} diff --git a/train-system/src/main/java/hu/bme/mit/train/system/TrainSystem.java b/train-system/src/main/java/hu/bme/mit/train/system/TrainSystem.java index 4ef42638b..6bf70e2de 100644 --- a/train-system/src/main/java/hu/bme/mit/train/system/TrainSystem.java +++ b/train-system/src/main/java/hu/bme/mit/train/system/TrainSystem.java @@ -13,6 +13,12 @@ public class TrainSystem { private TrainUser user = new TrainUserImpl(controller); private TrainSensor sensor = new TrainSensorImpl(controller, user); + public TrainSystem(){ + RunnableImpl r = new RunnableImpl(controller); + Thread t1 = new Thread(r); + t1.start(); + } + public TrainController getController() { return controller; } diff --git a/train-system/src/test/java/hu/bme/mit/train/system/TrainSystemTest.java b/train-system/src/test/java/hu/bme/mit/train/system/TrainSystemTest.java index 04ae3dac0..745880260 100644 --- a/train-system/src/test/java/hu/bme/mit/train/system/TrainSystemTest.java +++ b/train-system/src/test/java/hu/bme/mit/train/system/TrainSystemTest.java @@ -50,5 +50,19 @@ public void OverridingJoystickPositionToNegative_SetsReferenceSpeedToZero() { Assert.assertEquals(0, controller.getReferenceSpeed()); } + @Test + public void brakeTest(){ + controller.emergencyBrake(); + Assert.assertEquals(0, controller.getSpeedLimit()); + } + + @Test + public void tachoChecker(){ + user.overrideJoystickPosition(11); + controller.followSpeed(); + controller.saveTachograph(); + Assert.assertNotEquals(0,controller.getTachograph().size()); + } + } diff --git a/train-system/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/train-system/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 000000000..104d0eff5 --- /dev/null +++ b/train-system/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +hu/bme/mit/train/system/TrainSystem.class diff --git a/train-system/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/train-system/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 000000000..a872c23b6 --- /dev/null +++ b/train-system/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/base/train-system/src/main/java/hu/bme/mit/train/system/TrainSystem.java diff --git a/train-system/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/train-system/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 000000000..f347beb05 --- /dev/null +++ b/train-system/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +hu/bme/mit/train/system/TrainSystemTest.class diff --git a/train-system/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/train-system/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 000000000..656c56f34 --- /dev/null +++ b/train-system/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/base/train-system/src/test/java/hu/bme/mit/train/system/TrainSystemTest.java diff --git a/train-system/target/surefire-reports/TEST-hu.bme.mit.train.system.TrainSystemTest.xml b/train-system/target/surefire-reports/TEST-hu.bme.mit.train.system.TrainSystemTest.xml new file mode 100644 index 000000000..5d1c21783 --- /dev/null +++ b/train-system/target/surefire-reports/TEST-hu.bme.mit.train.system.TrainSystemTest.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/train-system/target/surefire-reports/hu.bme.mit.train.system.TrainSystemTest.txt b/train-system/target/surefire-reports/hu.bme.mit.train.system.TrainSystemTest.txt new file mode 100644 index 000000000..1fdf1cc7e --- /dev/null +++ b/train-system/target/surefire-reports/hu.bme.mit.train.system.TrainSystemTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: hu.bme.mit.train.system.TrainSystemTest +------------------------------------------------------------------------------- +Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.146 sec diff --git a/train-user/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/train-user/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 000000000..f84f69174 --- /dev/null +++ b/train-user/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +hu/bme/mit/train/user/TrainUserImpl.class diff --git a/train-user/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/train-user/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 000000000..8cd6208d2 --- /dev/null +++ b/train-user/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/base/train-user/src/main/java/hu/bme/mit/train/user/TrainUserImpl.java