Updated domain. Further explanation in README

main
Philipp3107 2022-12-08 23:34:47 +01:00
parent 77dd5b19f6
commit 3a856779f3
2 changed files with 64 additions and 1 deletions

View File

@ -5,30 +5,48 @@ public class R2D2 implements Robot{
private String name; private String name;
private boolean power; private boolean power;
/**
* Constructor
* @param id> int
* @param name> String
*/
public R2D2(int id, String name){ public R2D2(int id, String name){
this.id = id; this.id = id;
this.name = name; this.name = name;
power = false; power = false;
} }
/**
* @see domain.RobotControl
*/
@Override @Override
public int getId() { public int getId() {
return id; return id;
} }
/**
* @see domain.RobotControl
*/
@Override @Override
public String getName() { public String getName() {
return name; return name;
} }
/**
* @see domain.RobotControl
*/
@Override @Override
public void triggerPowerSwitch() { public void triggerPowerSwitch() {
if(power = false){ if(power == false){
power = true; power = true;
}else{ }else{
power = false; power = false;
} }
} }
/**
* @see domain.RobotControl
*/
@Override @Override
public boolean isPowerOn() { public boolean isPowerOn() {
return power; return power;

View File

@ -0,0 +1,45 @@
package domain;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class R2D2Test {
R2D2 Herbert;
int id = 0;
String name = "Herbert";
@BeforeEach
void setup(){
Herbert = new R2D2(id, name);
}
//Tests for basic functions
@Test
void getId() {
assertEquals(0, Herbert.getId());
}
@Test
void getName() {
assertEquals(name, Herbert.getName());
}
@Test
void triggerPowerSwitch() {
Herbert.triggerPowerSwitch();
assertTrue(Herbert.isPowerOn());
}
@Test
void isPowerOn() {
assertFalse(Herbert.isPowerOn());
Herbert.triggerPowerSwitch();
assertTrue(Herbert.isPowerOn());
}
}