Skip to content
Open

Work3 #320

35 changes: 35 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Train Speed Controller

This is a sample application for the verification laboratory.

B valtozat - This is a sample application for the verification laboratory.

## Getting started

Expand Down Expand Up @@ -62,3 +63,15 @@ 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.


###### H6 Header

[I am an inline style link with title](https://google.com "Google")

piton = "Python syntax highlighting"
print piton

***
Asterisks
***
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

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

import java.util.Timer;

public class TrainControllerImpl implements TrainController {

private int step = 0;
private int referenceSpeed = 0;
private int speedLimit = 0;


@Override
public void followSpeed() {
Thread.sleep(20000);
////

if (referenceSpeed < 0) {
referenceSpeed = 0;
} else {
Expand All @@ -23,6 +29,8 @@ public void followSpeed() {
enforceSpeedLimit();
}



@Override
public int getReferenceSpeed() {
return referenceSpeed;
Expand All @@ -46,4 +54,5 @@ public void setJoystickPosition(int joystickPosition) {
this.step = joystickPosition;
}


}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package hu.bme.mit.train.interfaces;

import java.time.LocalDateTime;

public interface TrainSensor {

int getSpeedLimit();

void overrideSpeedLimit(int speedLimit);

void dangerDetection(boolean hazard);

public void logTachograph();

public int getLogSize();

}
17 changes: 17 additions & 0 deletions train-sensor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,22 @@
<version>0.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>hu.bme.mit.train</groupId>
<artifactId>hu.bme.mit.train.controller</artifactId>
<version>0.5.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
<dependency>
<groupId>hu.bme.mit.train</groupId>
<artifactId>hu.bme.mit.train.user</artifactId>
<version>0.5.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
import hu.bme.mit.train.interfaces.TrainSensor;
import hu.bme.mit.train.interfaces.TrainUser;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;

public class TrainSensorImpl implements TrainSensor {

Table<LocalDateTime, Integer, Integer> tachograph = HashBasedTable.create();

private TrainController controller;
private TrainUser user;
private int speedLimit = 5;
private boolean danger = false;

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

@Override
public void dangerDetection(boolean hazard) {
if (hazard == true) {
danger = true;
overrideSpeedLimit(0);
}
}

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

public int getLogSize() {
return tachograph.size();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package hu.bme.mit.train.sensor;

import junit.framework.TestCase;

public class TrainSensorImplTest extends TestCase {

public void testGetSpeedLimit() {
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
package hu.bme.mit.train.sensor;

import hu.bme.mit.train.controller.TrainControllerImpl;
import hu.bme.mit.train.interfaces.TrainController;
import hu.bme.mit.train.interfaces.TrainSensor;
import hu.bme.mit.train.interfaces.TrainUser;
import hu.bme.mit.train.user.TrainUserImpl;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.*;


public class TrainSensorTest {

private TrainController controller = new TrainControllerImpl();
private TrainUser user = new TrainUserImpl(controller);
private int speedLimit = 5;
private boolean danger = false;
TrainSensor sensor = new TrainSensorImpl(controller, user);

@Before
public void before() {
// TODO Add initializations
controller = new TrainControllerImpl();
speedLimit = 5;
danger = false;
}

@Test
public void DangerousSituation() {
danger = true;
sensor.dangerDetection(danger);
}

@Test
public void ThisIsAnExampleTestStub() {
// TODO Delete this and add test cases based on the issues
public void Test7() {
sensor.logTachograph();
Assert.assertEquals(1, sensor.getLogSize());
}
}