Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceSpeedMod2 #321

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
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
***
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.organization>mestergyretelabmit3</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

<packaging>pom</packaging>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package hu.bme.mit.train.controller;

import javax.crypto.SecretKeyFactory;

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

public class TrainControllerImpl implements TrainController {
Expand All @@ -14,7 +16,11 @@ public void followSpeed() {
referenceSpeed = 0;
} else {
if(referenceSpeed+step > 0) {
referenceSpeed += step;
synchronized (this) {
referenceSpeed += step;
}
setChanged();
notifyObservers();
} else {
referenceSpeed = 0;
}
Expand All @@ -28,6 +34,7 @@ public int getReferenceSpeed() {
return referenceSpeed;
}


@Override
public void setSpeedLimit(int speedLimit) {
this.speedLimit = speedLimit;
Expand Down
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,4 @@ public void OverridingJoystickPositionToNegative_SetsReferenceSpeedToZero() {
controller.followSpeed();
Assert.assertEquals(0, controller.getReferenceSpeed());
}


}