New created test class for Nexus6 with tests

main
CedricNew 2023-01-10 00:47:27 +01:00
parent f5f33c7a86
commit cc6c4ed822
1 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,107 @@
package tests;
import domain.Nexus6;
import domain.R2D2;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import utility.robot_exceptions.RobotException;
import static org.junit.jupiter.api.Assertions.*;
class Nexus6Test {
Nexus6 nexus6;
int id = 19281982;
String name = "Pris";
@BeforeEach
void setup(){
nexus6 = new Nexus6(name);
nexus6.triggerPowerSwitch();
}
@Test
void getId() {
assertEquals(id, nexus6.getId());
}
@Test
void getName() {
assertEquals(name, nexus6.getName());
}
@Test
void triggerPowerSwitch() {
assertTrue(nexus6.isPowerOn());
nexus6.triggerPowerSwitch();
assertFalse(nexus6.isPowerOn());
}
@Test
void R2D2SpeakTestEmpty() {
try{
String solution = nexus6.speak(new int[]{});
}catch(RobotException re){
assertEquals(0, "Pris ist in einem illegalen Zustand".compareTo(re.getMessage()));
}
}
@Test
void R2D2SpeakTestZeros() throws RobotException {
try{
String solution = nexus6.speak(new int[4]);
}catch(RobotException re){
assertEquals(0, "Pris ist in einem illegalen Zustand".compareTo(re.getMessage()));
}
}
@Test
void R2D2SpeakTestOneElement() throws RobotException {
try{
String solution = nexus6.speak(new int[]{1});
}catch(RobotException re){
assertEquals(0, "Pris ist in einem illegalen Zustand".compareTo(re.getMessage()));
}
}
@Test
void R2D2SpeakTestUnitElements() throws RobotException {
try{
String solution = nexus6.speak(new int[]{-1, 0, 1});
}catch(RobotException re){
assertEquals(0, "Pris ist in einem illegalen Zustand".compareTo(re.getMessage()));
}
}
@Test
void R2D2SpeakTestMagicNumberException() {
try{
String solution = nexus6.speak(new int[]{42});
}catch(RobotException re){
assertEquals(0, "Pris ist in einem illegalen Zustand".compareTo(re.getMessage()));
}
}
@Test
void speak(){
String solution = "12, 2, 4, 5, 12, 2, 4, 7, 56, 433, 23";
int[] input = {12, 2, 4, 5, 12, 2, 4, 7, 56, 433, 23};
try{
String array = nexus6.speak(input);
} catch(RobotException re) {
assertEquals(0, "Pris ist in einem illegalen Zustand".compareTo(re.getMessage()));
}
}
@Test
void think(){
int[] solution = { 2, 4, 4, 5, 7, 12, 23, 56, 433};
int[] input = { 4, 5, 12, 2, 4, 7, 56, 433, 23};
try{
int[] value = nexus6.think(input);
}catch(RobotException re){
assertEquals(0, "Pris ist in einem illegalen Zustand".compareTo(re.getMessage()));
}
}
}