Skip to content
42 changes: 42 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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:
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- 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 --no-transfer-progress

# 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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ 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.


# CONFLICT RESOLVED

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut et tristique nibh. Aenean sagittis semper nisi quis dapibus. Proin metus felis, sollicitudin id diam ut, mattis scelerisque nibh. Mauris a nisl vel quam mattis malesuada sed vel augue. Praesent eu orci justo. Phasellus volutpat ligula sed leo lobortis, ac interdum ligula finibus.

1. First
2. Second
3. Third

- alma
- banan
- citrom
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import hu.bme.mit.train.interfaces.TrainController;

import java.util.concurrent.TimeUnit;
import java.lang.Thread;

public class TrainControllerImpl implements TrainController {

private int step = 0;
Expand Down Expand Up @@ -46,4 +49,25 @@ public void setJoystickPosition(int joystickPosition) {
this.step = joystickPosition;
}

@Override
public void emergencyBreak() {
this.referenceSpeed = 0;
}

@Override
public void setReferenceSpeed(){
Thread t = new Thread(() -> {
while(true){
try {
followSpeed();
TimeUnit.SECONDS.sleep(1);
} catch (Exception e) {

}

}
});
t.start();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public interface TrainController {

void setJoystickPosition(int joystickPosition);

void emergencyBreak();

void setReferenceSpeed();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ public interface TrainSensor {

void overrideSpeedLimit(int speedLimit);

public void addLog();

public int getLogSize();

}
5 changes: 5 additions & 0 deletions train-sensor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@
<version>0.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.0.0-jre</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
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;
import java.time.*;

public class TrainSensorImpl implements TrainSensor {

private TrainController controller;
private TrainUser user;
private int speedLimit = 5;
private Table<LocalDateTime, Integer, Integer> tachograph = HashBasedTable.create();

public TrainSensorImpl(TrainController controller, TrainUser user) {
this.controller = controller;
Expand All @@ -26,4 +31,13 @@ public void overrideSpeedLimit(int speedLimit) {
controller.setSpeedLimit(speedLimit);
}

@Override
public void addLog(){
this.tachograph.put(LocalDateTime.now(), user.getJoystickPosition(), controller.getReferenceSpeed());
}

@Override
public int getLogSize(){
return this.tachograph.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,33 @@ public void OverridingJoystickPositionToNegative_SetsReferenceSpeedToZero() {
Assert.assertEquals(0, controller.getReferenceSpeed());
}

@Test
public void MaintainSpeed() {
user.overrideJoystickPosition(4);
controller.followSpeed();
Assert.assertEquals(4, controller.getReferenceSpeed());
user.overrideJoystickPosition(0);
controller.followSpeed();
Assert.assertEquals(4, controller.getReferenceSpeed());
}

@Test
public void EmergencyBreakPressed(){
user.overrideJoystickPosition(5);
controller.followSpeed();
Assert.assertEquals(5, controller.getReferenceSpeed());

controller.emergencyBreak();
Assert.assertEquals(0, controller.getReferenceSpeed());

}

@Test
public void TachogrpahTest(){
Assert.assertEquals(sensor.getLogSize(), 0);
sensor.addLog();
Assert.assertEquals(sensor.getLogSize(), 1);
}


}