Skip to content

Commit

Permalink
Merge pull request #4 from szfp98/nandi
Browse files Browse the repository at this point in the history
Nandi
  • Loading branch information
szfp98 authored Mar 25, 2024
2 parents ed744c3 + 5e69a09 commit c7d8465
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

public interface TrainUser {

boolean alarmState = false;

int getJoystickPosition();

boolean getAlarmFlag();

void overrideJoystickPosition(int joystickPosition);

public boolean getAlarmState();

public void setAlarmState(boolean alarmState);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public int getSpeedLimit() {
public void overrideSpeedLimit(int speedLimit) {
this.speedLimit = speedLimit;
controller.setSpeedLimit(speedLimit);

if(speedLimit < 0 || speedLimit > 500 || speedLimit < controller.getReferenceSpeed() / 2) {
user.setAlarmState(true);
}
}

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

import TrainController;
import TrainSensorImpl;
import TrainUser;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.*;

public class TrainSensorTest {


TrainController mockTC;
TrainUser mockTU;
TrainsSensorImpl trainSensor;

@Before
public void before() {
mockTC = mock(TrainController.class);
mockTU = mock(TrainUser.class);
trainSensor = new TrainSensorImpl(mockTC, mockTU);
}

@Test
public void setAlarmState_TrainUser_Min() {
trainSensor.overrideSpeedLimit(-1);
verify(mockTU, times(1)).setAlarmState(true);
}

@Test
public void setAlarmState_TrainUser_Max() {
trainSensor.overrideSpeedLimit(501);
verify(mockTU, times(1)).setAlarmState(true);
}

@Test
public void setAlarmState_TrainUser_RelativeLimit() {
trainSensor.overrideSpeedLimit(3);
verify(mockTU, times(1)).setAlarmState(true);
}

@Test
public void setAlarmState_TrainUser_Between() {
trainSensor.overrideSpeedLimit(300);
verify(mockTU, times(0)).setAlarmState(false);
}
}
11 changes: 11 additions & 0 deletions train-user/src/main/java/hu/bme/mit/train/user/TrainUserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ public void overrideJoystickPosition(int joystickPosition) {
controller.followSpeed();
}

@Override
public boolean getAlarmState() {
return alarmState;
}

public void setAlarmState(boolean alarmState) {
alarmState = alarmState;
}



}

0 comments on commit c7d8465

Please sign in to comment.