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..a79f5543e 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,10 @@ 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. + +

+ +> ## MIT2 labor *(2024.03.11.)* +> - -- +> **todolist** +> - [X] clone repoB 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..9accf33c9 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 @@ -1,12 +1,26 @@ package hu.bme.mit.train.controller; import hu.bme.mit.train.interfaces.TrainController; +import java.util.*; public class TrainControllerImpl implements TrainController { private int step = 0; private int referenceSpeed = 0; private int speedLimit = 0; + // Timer attribute to handle time-based changes + private Timer timer = new Timer("timer"); + + // the constructor of this class initiates a timertask that's "called" every passing second + public TrainControllerImpl() { + TimerTask tTask = new TimerTask() { + public void run() { + followSpeed(); + } + }; + + timer.schedule(tTask, 1000L); + } @Override public void followSpeed() { @@ -41,6 +55,11 @@ private void enforceSpeedLimit() { } } + @Override + public void emergencyBreak() { + referenceSpeed = 0; + } + @Override public void setJoystickPosition(int joystickPosition) { this.step = joystickPosition; 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..fd81f58cf --- /dev/null +++ b/train-controller/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +hu/bme/mit/train/controller/TrainControllerImpl.class +hu/bme/mit/train/controller/TrainControllerImpl$1.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..6063b4a14 --- /dev/null +++ b/train-controller/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/Desktop/mit2/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..cf594f068 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 @@ -10,4 +10,6 @@ public interface TrainController { void setJoystickPosition(int joystickPosition); + void emergencyBreak(); + } diff --git a/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainSensor.java b/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainSensor.java index 298173025..ed4f277b8 100644 --- a/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainSensor.java +++ b/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainSensor.java @@ -6,4 +6,13 @@ public interface TrainSensor { void overrideSpeedLimit(int speedLimit); + long getCurrentTime(); + + int getReferenceSpeed(); + + int getJoystickPosition(); + + void updateTable(); + + int getTableSize(); } 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..7152c1e0d --- /dev/null +++ b/train-interfaces/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +/home/cloud/Desktop/mit2/base/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainUser.java +/home/cloud/Desktop/mit2/base/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainSensor.java +/home/cloud/Desktop/mit2/base/train-interfaces/src/main/java/hu/bme/mit/train/interfaces/TrainController.java diff --git a/train-sensor/pom.xml b/train-sensor/pom.xml index 0b50214b9..7cc8fbcd3 100644 --- a/train-sensor/pom.xml +++ b/train-sensor/pom.xml @@ -36,5 +36,10 @@ 0.8.7 test + + com.google.guava + guava + 33.0.0-jre + \ No newline at end of file diff --git a/train-sensor/src/main/java/hu/bme/mit/train/sensor/TrainSensorImpl.java b/train-sensor/src/main/java/hu/bme/mit/train/sensor/TrainSensorImpl.java index 4a640d1dd..fe981bdea 100644 --- a/train-sensor/src/main/java/hu/bme/mit/train/sensor/TrainSensorImpl.java +++ b/train-sensor/src/main/java/hu/bme/mit/train/sensor/TrainSensorImpl.java @@ -4,15 +4,21 @@ import hu.bme.mit.train.interfaces.TrainSensor; import hu.bme.mit.train.interfaces.TrainUser; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; + public class TrainSensorImpl implements TrainSensor { private TrainController controller; private TrainUser user; private int speedLimit = 5; + public Table table; + public TrainSensorImpl(TrainController controller, TrainUser user) { this.controller = controller; this.user = user; + table = HashBasedTable.create(); } @Override @@ -26,4 +32,32 @@ public void overrideSpeedLimit(int speedLimit) { controller.setSpeedLimit(speedLimit); } + @Override + public long getCurrentTime() { + return System.currentTimeMillis(); + } + + @Override + public int getReferenceSpeed() { + return controller.getReferenceSpeed(); + } + + @Override + public int getJoystickPosition() { + return user.getJoystickPosition(); + } + + @Override + public void updateTable() { + long time = getCurrentTime(); + int refSpeed = getReferenceSpeed(); + int joystickPos = getJoystickPosition(); + + table.put(time, refSpeed, joystickPos); + } + + @Override + public int getTableSize() { + return table.size(); + } } 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..492fe9c1c --- /dev/null +++ b/train-sensor/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/Desktop/mit2/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..cd1714819 --- /dev/null +++ b/train-sensor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/Desktop/mit2/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..16e201776 --- /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..1399471ef --- /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.085 sec 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..58a2dee0d 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,27 @@ public void OverridingJoystickPositionToNegative_SetsReferenceSpeedToZero() { Assert.assertEquals(0, controller.getReferenceSpeed()); } + @Test + public void EmergencyBreak_Break() { + user.overrideJoystickPosition(4); + controller.followSpeed(); + user.overrideJoystickPosition(-5); + controller.followSpeed(); + + controller.emergencyBreak(); + Assert.assertEquals(0, controller.getReferenceSpeed()); + } + @Test + public void TableUpdate() { + user.overrideJoystickPosition(4); + controller.followSpeed(); + user.overrideJoystickPosition(2); + + int sizeOne = sensor.getTableSize(); + sensor.updateTable(); + int sizeTwo = sensor.getTableSize(); + + Assert.assertEquals(true, sizeTwo > sizeOne); + } } 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..2262469d3 --- /dev/null +++ b/train-system/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/Desktop/mit2/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..77bcec89f --- /dev/null +++ b/train-system/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/Desktop/mit2/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..466282144 --- /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..e0729b8a1 --- /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.091 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..d6b28481b --- /dev/null +++ b/train-user/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/cloud/Desktop/mit2/base/train-user/src/main/java/hu/bme/mit/train/user/TrainUserImpl.java