Merge branch 'Selectionsort_R2D2'

# Conflicts:
#	bin/C3PO.class
#	bin/Nexus6.class
#	bin/R2D2.class
#	src/C3PO.java
#	src/Nexus6.java
#	src/R2D2.java
master
azadehobenland 2023-01-09 23:34:34 +01:00
commit c6ec1df92a
50 changed files with 664 additions and 324 deletions

View File

@ -3,9 +3,36 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.7.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.7.0/junit-jupiter-5.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.7.0/junit-platform-commons-1.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.7.0/junit-jupiter-params-5.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.7.0/junit-jupiter-engine-5.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.7.0/junit-platform-engine-1.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,107 +0,0 @@
import tpe.exceptions.roboter.Robot;
import tpe.exceptions.roboter.exceptions.RobotException;
import java.util.Arrays;
import java.util.stream.Collectors;
public class C3PO implements Robot {
private int id;
private String name;
private boolean isPowerOn;
/**
* @return id of the robot
*/
@Override
public int getId() {
return id;
}
/**
* @return name of the robot
*/
@Override
public String getName() {
return name;
}
/**
* @return isPorwerOn true if it's false
*/
@Override
public void triggerPowerSwitch() {
if(isPowerOn==false){
isPowerOn=true;
}else{
isPowerOn=false;
}
}
//tes test
/**
* @return isPowerOn
*/
@Override
public boolean isPowerOn() {
return isPowerOn;
}
/**
* creating a RobotException getLastException
*/
@Override
public RobotException getLastException() {
return null;
}
/**
* speak method that returns the sorted and formated numbers from the array zahlen
* @param int[] zahlen Array of numbers for sorting
* @return sorted and formated numbers
*/
@Override
public String speak(int[] zahlen) throws RobotException {
var sortiert = think(zahlen);
return arrayFormatieren(sortiert);
}
/**
* method to format the outcome
* Returns a Stream consisting of the elements of this stream,each boxed to an Integer
* and maps it into a String
* each element of the Stream is separated by ","
* @param int[] zahlen Array of numbers to sort
* @return formated outcome
*/
private String arrayFormatieren(int[] zahlen){
var ergebnis = Arrays.stream(zahlen)
.boxed()
.map(String::valueOf)
.collect(Collectors.joining(";"));
return ergebnis;
}
/**
* method that sorts the array zahlen with the Selectionsort-Algorithmin in descending order
* @param int[] zahlen Array of numbers for sorting
* @return array of numbers in descending order
*/
@Override
public int[] think(int[] zahlen) throws RobotException {
int n = zahlen.length;
for (int i = 1; i < n; ++i) {
int key = zahlen[i];
int j = i - 1;
while (j >= 0 && zahlen[j] < key) {
zahlen[j + 1] = zahlen[j];
j = j - 1;
}
zahlen[j + 1] = key;
}
return zahlen;
}
}

View File

@ -1,90 +0,0 @@
import tpe.exceptions.roboter.Robot;
import tpe.exceptions.roboter.exceptions.RobotException;
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
import java.util.Arrays;
import java.util.stream.Collectors;
public class Nexus6 implements Robot {
private int id = 19281982;
private String name = "pris";
private boolean isPowerOn = false;
//creating an instance of Nexus
private static Nexus6 instance = new Nexus6();
//constructor of Nexus
private Nexus6() {
}
//instance of Nexus is null
public static Nexus6 getInstance() {
if (instance == null)
instance = new Nexus6();
return instance;
}
//returns id
@Override
public int getId() {
return id;
}
//returns name
@Override
public String getName() {
return name;
}
//isPowerOn must be false
@Override
public void triggerPowerSwitch() {
if(isPowerOn==false){
isPowerOn=false;
}else{
isPowerOn=false;
}
}
//retruns isPowerOn
@Override
public boolean isPowerOn() {
return isPowerOn;
}
//creating a RobotException
@Override
public RobotException getLastException() {
return null;
}
@Override
public String speak(int[] zahlen) /*throws RobotIllegalStateException */{
var sortiert = think(zahlen);
return arrayFormatieren(sortiert);
}
private String arrayFormatieren(int[] zahlen){
var ergebnis = Arrays.stream(zahlen)
.boxed()
.map(String::valueOf)
.collect(Collectors.joining(","));
return ergebnis;
}
@Override
public int[] think(int[] zahlen) /*throws RobotIllegalStateException*/ {
int n = zahlen.length;
for (int i = 1; i < n; ++i) {
int key = zahlen[i];
int j = i - 1;
while (j >= 0 && zahlen[j] < key) {
zahlen[j + 1] = zahlen[j];
j = j - 1;
}
zahlen[j + 1] = key;
}
return zahlen;
}
}

View File

@ -1,105 +0,0 @@
import tpe.exceptions.roboter.Robot;
import tpe.exceptions.roboter.exceptions.RobotException;
import java.util.Arrays;
import java.util.stream.Collectors;
public class R2D2 implements Robot {
private int id;
private String name;
private boolean isPowerOn;
/**
* @return id of the robot
*/
@Override
public int getId() {
return id;
}
/**
* @return name of the robot
*/
@Override
public String getName() {
return name;
}
/**
* @return isPorwerOn true if it's false
*/
@Override
public void triggerPowerSwitch() {
if(isPowerOn==false){
isPowerOn=true;
}else{
isPowerOn=false;
}
}
/**
* @return isPowerOn
*/
@Override
public boolean isPowerOn() {
return isPowerOn;
}
/**
* creating a RobotException getLastException
*/
@Override
public RobotException getLastException() {
return null;
}
/**
* speak method that returns the sorted and formated numbers from the array zahlen
* @param int[] zahlen Array of numbers for sorting
* @return sorted and formated numbers
*/
@Override
public String speak(int[] zahlen) throws RobotException {
var sortiert = think(zahlen);
return arrayFormatieren(sortiert);
}
/**
* method to format the outcome
* Returns a Stream consisting of the elements of this stream,each boxed to an Integer
* and maps it into a String
* each element of the Stream is separated by ","
* @param int[] zahlen Array of numbers to sort
* @return formated outcome
*/
private String arrayFormatieren(int[] zahlen){
var ergebnis = Arrays.stream(zahlen)
.boxed()
.map(String::valueOf)
.collect(Collectors.joining(","));
return ergebnis;
}
/**
* method that sorts the array zahlen with the Selectionsort-Algorithmin in ascending order
* @param int[] zahlen Array of numbers for sorting
* @return array of numbers in ascending order
*/
@Override
public int[] think(int[] zahlen) throws RobotException {
int n = zahlen.length;
for (int i = 1; i < n; ++i) {
int key = zahlen[i];
int j = i - 1;
while (j >= 0 && zahlen[j] > key) {
zahlen[j + 1] = zahlen[j];
j = j - 1;
}
zahlen[j + 1] = key;
}
return zahlen;
}
}

View File

@ -0,0 +1,108 @@
package roboter;
import roboter.exceptions.RobotException;
import roboter.exceptions.RobotIllegalStateException;
import roboter.exceptions.RobotMagicValueException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class C3PO implements Robot {
private int id;
private String name;
private boolean isPowerOn = true;
ArrayList<RobotException> exceptionList=new ArrayList<>();
public C3PO(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public int getId() {
return id;
}
@Override
public String getName() {
return name;
}
@Override
public void triggerPowerSwitch() {
if (isPowerOn == false) {
isPowerOn = true;
} else {
isPowerOn = false;
}
}
//tes test
@Override
public boolean isPowerOn() {
return isPowerOn;
}
@Override
public RobotException getLastException() {
if (!exceptionList.isEmpty()){
return exceptionList.get(exceptionList.size() - 1);
}
return null;
}
@Override
public String speak(int[] zahlen) throws RobotException, RobotMagicValueException {
if(!isPowerOn){
var ex=new RobotIllegalStateException(this);
exceptionList.add(ex);
throw ex;
}
if (Arrays.stream(zahlen).anyMatch(value -> value ==42)){
var exc= new RobotMagicValueException(this);
exceptionList.add(exc);
throw exc;
}
var sortiert = think(zahlen);
return arrayFormatieren(sortiert);
}
private String arrayFormatieren(int[] zahlen) throws RobotMagicValueException {
var ergebnis = Arrays.stream(zahlen)
.boxed()
.map(String::valueOf)
.collect(Collectors.joining(";"));
return ergebnis;
}
@Override
public int[] think(int[] zahlen) throws RobotException {
if(!isPowerOn){
var ex=new RobotIllegalStateException(this);
exceptionList.add(ex);
throw ex;
}
if (Arrays.stream(zahlen).anyMatch(value -> value ==42)){
var exc= new RobotMagicValueException(this);
exceptionList.add(exc);
throw exc;
}
int n = zahlen.length;
for (int i = 1; i < n; ++i) {
int key = zahlen[i];
int j = i - 1;
while (j >= 0 && zahlen[j] > key) {
zahlen[j + 1] = zahlen[j];
j = j - 1;
}
zahlen[j + 1] = key;
}
return zahlen;
}
}

View File

@ -0,0 +1,79 @@
package roboter;
import roboter.exceptions.RobotException;
import roboter.exceptions.RobotIllegalStateException;
import roboter.exceptions.RobotException;
import java.util.ArrayList;
public class Nexus6 implements Robot {
private int id = 19281982;
private String name = "pris";
private boolean isPowerOn = false;
ArrayList<RobotException> exceptionList=new ArrayList<>();
private static Nexus6 instance = new Nexus6();
private Nexus6() {
}
public static Nexus6 getInstance() {
if (instance == null) {
instance = new Nexus6();
}
return instance;
}
@Override
public int getId() {
return id;
}
@Override
public String getName() {
return name;
}
@Override
public void triggerPowerSwitch() {
}
@Override
public boolean isPowerOn() {
return isPowerOn;
}
@Override
public RobotException getLastException() {
if (!exceptionList.isEmpty()){
return exceptionList.get(exceptionList.size() - 1);
}
return null;
}
@Override
public String speak(int[] zahlen) throws RobotIllegalStateException {
var newException = new RobotIllegalStateException(this);
exceptionList.add(newException);
throw newException;
}
@Override
public int[] think(int[] zahlen) throws RobotIllegalStateException {
var newException2=new RobotIllegalStateException(this);
exceptionList.add(newException2);
throw newException2;
}
}

View File

@ -0,0 +1,105 @@
package roboter;
import roboter.exceptions.RobotException;
import roboter.exceptions.RobotIllegalStateException;
import roboter.exceptions.RobotMagicValueException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
public class R2D2 implements Robot {
private int id;
private String name;
private boolean isPowerOn=true;
ArrayList<RobotException> exceptionList=new ArrayList<>();
public R2D2(int id, String name){
this.id=id;
this.name=name;
}
@Override
public int getId() {
return id;
}
@Override
public String getName() {
return name;
}
@Override
public void triggerPowerSwitch() {
if(isPowerOn==false){
isPowerOn=true;
}else{
isPowerOn=false;
}
}
@Override
public boolean isPowerOn() {
return isPowerOn;
}
@Override
public RobotException getLastException() {
if (!exceptionList.isEmpty()){
return exceptionList.get(exceptionList.size() - 1);
}
return null;
}
@Override
public String speak(int[] zahlen) throws RobotException, RobotMagicValueException {
if(!isPowerOn){
var ex=new RobotIllegalStateException(this);
exceptionList.add(ex);
throw ex;
}
if (Arrays.stream(zahlen).anyMatch(value -> value ==42)){
var exc= new RobotMagicValueException(this);
exceptionList.add(exc);
throw exc;
}
var sortiert = think(zahlen);
return arrayFormatieren(sortiert);
}
private String arrayFormatieren(int[] zahlen){
var ergebnis = Arrays.stream(zahlen)
.boxed()
.map(String::valueOf)
.collect(Collectors.joining(","));
return ergebnis;
}
@Override
public int[] think(int[] zahlen) throws RobotException, RobotMagicValueException {
if(!isPowerOn){
var ex=new RobotIllegalStateException(this);
exceptionList.add(ex);
throw ex;
}
if (Arrays.stream(zahlen).anyMatch(value -> value ==42)){
var exc= new RobotMagicValueException(this);
exceptionList.add(exc);
throw exc;
}
for (int i = 0; i < zahlen.length - 1; i++) {
for (int j = i + 1; j < zahlen.length; j++) {
if (zahlen[i] > zahlen[j]) {
int temp = zahlen[i];
zahlen[i] = zahlen[j];
zahlen[j] = temp;
}
}
}
return zahlen;
}
}

View File

@ -1,6 +1,6 @@
/* (c) 2012 Thomas Smits */
package tpe.exceptions.roboter;
package roboter;
/**
* Interface für Roboter.

View File

@ -1,7 +1,8 @@
package tpe.exceptions.roboter;
package roboter;
import tpe.exceptions.roboter.exceptions.RobotException;
import roboter.exceptions.RobotException;
import roboter.exceptions.RobotException;
/**
* Das Interface repräsentiert einen einfachen Roboter mit seinen Funktionen.

View File

@ -0,0 +1,29 @@
package roboter;
public class RobotFactory {
private static int R2D2Id=0;
private static int C2POId=10000;
/**
* Dies ist eine Factory methode, mit der man einen Roboter
* mit einem bestimmten typ und namen generieren lassen kann
* @param typ Typ vom Roboter
* @param name Name vom Roboter
* @return ein Roboter Objekt
*/
public static Robot getRobot(Typ typ,String name){
switch (typ){
case R2D2:
return new R2D2(R2D2Id++,name);
case C3PO:
return new C3PO(C2POId++,name);
case Nexus6:
return Nexus6.getInstance();
}
return null;
}
}

View File

@ -1,9 +1,9 @@
package tpe.exceptions.roboter;
package roboter;
import tpe.exceptions.roboter.exceptions.RobotException;
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
import roboter.exceptions.RobotException;
import roboter.exceptions.RobotIllegalStateException;
import roboter.exceptions.RobotMagicValueException;
/**
* Das Interface repräsentiert den Befehlssatz eines einfachen Roboters.
@ -35,7 +35,7 @@ public interface RobotInstructions {
* @throws RobotException wenn der Roboter in einem ungültigen Zustand ist,
* oder das Array nicht seinen Vorstellungen entspricht.
*/
public String speak(int[] zahlen) throws RobotException;
public String speak(int[] zahlen) throws RobotException, RobotMagicValueException;
/**
* Sortiert ein Array von Zahlen. Die Reihenfolge hängt von dem Typ des
@ -46,5 +46,5 @@ public interface RobotInstructions {
* @throws RobotException wenn der Roboter in einem ungültigen Zustand ist,
* oder das Array nicht seinen Vorstellungen entspricht.
*/
public int[] think(int[] zahlen) throws RobotException;
public int[] think(int[] zahlen) throws RobotException, RobotMagicValueException;
}

View File

@ -0,0 +1,5 @@
package roboter;
public enum Typ {
R2D2,C3PO,Nexus6
}

View File

@ -0,0 +1,7 @@
package roboter.exceptions;
public class RobotException extends Exception{
public RobotException(String errormessage) {
super(errormessage);
}
}

View File

@ -0,0 +1,11 @@
package roboter.exceptions;
import roboter.Robot;
import roboter.exceptions.*;
public class RobotIllegalStateException extends RobotException {
public RobotIllegalStateException(Robot roboter) {
super("Fehler von : " + roboter.getName());
}
}

View File

@ -0,0 +1,9 @@
package roboter.exceptions;
import roboter.Robot;
public class RobotMagicValueException extends RobotException {
public RobotMagicValueException(Robot robot) {
super(robot.getName());
}
}

View File

@ -0,0 +1,68 @@
package test.java.roboter;
import org.junit.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DynamicNode;
import roboter.exceptions.RobotException;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Properties;
public class C3POTest <SystemOutRule, OutputCapture> {
private final ByteArrayOutputStream out = new ByteArrayOutputStream();
private final ByteArrayOutputStream err = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;
private final PrintStream originalErr = System.err;
@Before
public void setStreams() {
System.setOut(new PrintStream(out));
System.setErr(new PrintStream(err));
}
@After
public void restoreInitialStreams() {
System.setOut(originalOut);
System.setErr(originalErr);
}
@Test
public void sortieren() throws RobotException {
var list = new int[]{12,6,7,10,18,2};
Robot robot= RobotFactory.getRobot(Typ.C3PO,"roboter2");
Assert.assertEquals("18,12,10,7,6,2",robot.speak(list));
var list1 = new int[] {17,10,19,1,4,2,7};
Assert.assertEquals("19,17,10,7,4,2,1", robot.speak(list));
var list2 = new int[] {3,17,7,20,5,15,8};
Assert.assertEquals("20,17,15,8,7,5,3", robot.speak(list));
var list3 = new int[] {13,8,5,12,1,9,7};
Assert.assertEquals("13,12,9,8,7,5,1", robot.speak(list));
var list4 = new int[] {18,4,21,7,3,2,9};
Assert.assertEquals("21,18,9,7,4,3,2", robot.speak(list));
var list5 = new int[] {13,23,8,4,22,6};
Assert.assertEquals("23,22,13,8,6,4", robot.speak(list));
var list6 = new int[] {10,9,8,7,6,5};
Assert.assertEquals("10,9,8,7,6,5", robot.speak(list));
var list7 = new int[] {1,2,3,5,4,6};
Assert.assertEquals("6,5,4,3,2,1", robot.speak(list));
var list8 = new int[] {20,19,18,17,16,15};
Assert.assertEquals("20,19,18,17,16,15", robot.speak(list));
var list9 = new int[] {15,1,13,10,7,4};
Assert.assertEquals("15,13,10,7,4,1", robot.speak(list));
var list10 = new int[] {10,15,11,8,5,6,};
Assert.assertEquals("15,11,10,8,6,5", robot.speak(list));
}
}

View File

@ -0,0 +1,20 @@
package roboter;
import org.junit.Assert;
import org.junit.Test;
import roboter.exceptions.RobotException;
public class C3PoSortierungTest {
@Test
public void sortieren() throws RobotException {
var list = new int[]{12,6,7,10,18,2};
Robot robot= RobotFactory.getRobot(Typ.C3PO,"roboter2");
assert robot != null;
Assert.assertEquals("2;6;7;10;12;18",robot.speak(list));
}
}

View File

@ -0,0 +1,54 @@
package roboter;
import org.junit.Assert;
import org.junit.Test;
import roboter.exceptions.RobotIllegalStateException;
public class ExceptionTest {
@Test
public void testNexus6Speak(){
Nexus6 robot = Nexus6.getInstance();
Assert.assertThrows(RobotIllegalStateException.class,()->{
robot.speak(new int[]{1,2,3,4});
});
Assert.assertThrows(RobotIllegalStateException.class,()->{
robot.think(new int[]{1,2,3,4});
});
}
@Test
public void powerOffSpeak(){
Robot robot=RobotFactory.getRobot(Typ.C3PO,"dfg");
robot.triggerPowerSwitch();
Assert.assertThrows(RobotIllegalStateException.class,()->{
robot.speak(new int[8]);
});
Robot robot2=RobotFactory.getRobot(Typ.R2D2,"dfg");
robot2.triggerPowerSwitch();
Assert.assertThrows(RobotIllegalStateException.class,()->{
robot2.speak(new int[8]);
});
Assert.assertThrows(RobotIllegalStateException.class,()->{
robot.think(new int[8]);
});
Assert.assertThrows(RobotIllegalStateException.class,()->{
robot2.think(new int[8]);
});
}
@Test
public void testNexus6Trigger(){
Nexus6 robot = Nexus6.getInstance();
boolean isPowerOn = robot.isPowerOn();
robot.triggerPowerSwitch();
Assert.assertEquals(isPowerOn, robot.isPowerOn());
}
}

View File

@ -0,0 +1,30 @@
package roboter;
import org.junit.Assert;
import org.junit.Test;
public class FactoryTest {
@Test
public void singletonNexus6(){
Nexus6 roboter1 = Nexus6.getInstance();
Nexus6 roboter2=Nexus6.getInstance();
Assert.assertEquals(roboter1,roboter2);
}
@Test
public void factoryMethodTest(){
Robot robot1=RobotFactory.getRobot(Typ.R2D2,"roboterX");
Assert.assertTrue(robot1 instanceof R2D2);
Robot robot2=RobotFactory.getRobot(Typ.C3PO,"roboter2");
Assert.assertTrue(robot2 instanceof C3PO);
Assert.assertEquals(robot1.getName(),"roboterX");
Assert.assertEquals(robot2.getName(),"roboter2");
}
}

View File

@ -0,0 +1,44 @@
package roboter;
import org.junit.Assert;
import org.junit.Test;
import roboter.exceptions.RobotIllegalStateException;
import roboter.exceptions.RobotMagicValueException;
import java.util.ArrayList;
public class GetLastExceptionTest {
@Test
public void testGetLastExcetion(){
int[]zahlen=new int[]{1,3,5,42};
Robot robot= RobotFactory.getRobot(Typ.C3PO,"ukzfiouz");
Assert.assertThrows(RobotMagicValueException.class,()->{
robot.speak(zahlen);
});
Assert.assertThrows(RobotMagicValueException.class,()->{
robot.think(zahlen);
});
Assert.assertTrue(robot.getLastException() instanceof RobotMagicValueException);
Robot robot1= RobotFactory.getRobot(Typ.R2D2,"ukzfiouz");
Assert.assertThrows(RobotMagicValueException.class,()->{
robot1.speak(zahlen);
});
Assert.assertThrows(RobotMagicValueException.class,()->{
robot1.think(zahlen);
});
Assert.assertTrue(robot1.getLastException() instanceof RobotMagicValueException);
Robot robot2= RobotFactory.getRobot(Typ.Nexus6,"ukzfiouz");
Assert.assertThrows(RobotIllegalStateException.class,()->{
robot2.speak(zahlen);
});
Assert.assertThrows(RobotIllegalStateException.class,()->{
robot2.think(zahlen);
});
Assert.assertTrue(robot2.getLastException() instanceof RobotIllegalStateException);
}
}

View File

@ -0,0 +1,57 @@
package roboter;
import org.junit.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DynamicNode;
import roboter.exceptions.RobotException;
import roboter.exceptions.RobotMagicValueException;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Properties;
public class R2D2Test<SystemOutRule, OutputCapture> {
@Test
public void sortieren() throws RobotException, RobotMagicValueException {
var list = new int[]{12,6,7,10,18,2};
Robot robot= RobotFactory.getRobot(Typ.R2D2,"roboterX");
Assert.assertEquals("2,6,7,10,12,18",robot.speak(list));
var list1 = new int[] {17,10,19,1,4,2,7};
Assert.assertEquals("1,2,4,7,10,17,19", robot.speak(list));
var list2 = new int[] {3,17,7,20,5,15,8};
Assert.assertEquals("3,5,7,8,15,17,20", robot.speak(list));
var list3 = new int[] {13,8,5,12,1,9,7};
Assert.assertEquals("1,5,7,8,9,12,13", robot.speak(list));
var list4 = new int[] {18,4,21,7,3,2,9};
Assert.assertEquals("2,3,4,7,9,18,21", robot.speak(list));
var list5 = new int[] {13,23,8,4,22,6};
Assert.assertEquals("4,6,8,13,22,23", robot.speak(list));
var list6 = new int[] {10,9,8,7,6,5};
Assert.assertEquals("5,6,7,8,9,10", robot.speak(list));
var list7 = new int[] {1,2,3,5,4,6};
Assert.assertEquals("1,2,3,4,5,6", robot.speak(list));
var list8 = new int[] {20,19,18,17,16,15};
Assert.assertEquals("15,16,17,18,19,20", robot.speak(list));
var list9 = new int[] {15,1,13,10,7,4};
Assert.assertEquals("1,4,7,10,13,15", robot.speak(list));
var list10 = new int[] {10,15,11,8,5,6,};
Assert.assertEquals("5,6,8,10,11,15", robot.speak(list));
}
}

View File

@ -1,4 +0,0 @@
package tpe.exceptions.roboter.exceptions;
public class RobotException extends Exception{
}

View File

@ -1,4 +0,0 @@
package tpe.exceptions.roboter.exceptions;
public class RobotIllegalStateException {
}

View File

@ -1,4 +0,0 @@
package tpe.exceptions.roboter.exceptions;
public class RobotMagicValueException {
}