diff --git a/README.md b/README.md index f2c8402..7f1cbab 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ (so würde z.B. (true || false == false) false zurückgeben) - i++ und i-- sind nur in for-Schleifen oder Statements erlaubt, --i und ++i sind generell nicht erlaubt - ein File kann nur eine Klasse enthalten +- Datentypen sind auf int, boolean und char sowie Klassen beschränkt ## Aufbau der Tests diff --git a/src/test/java/E2ETests/Features/E2E_Main.java b/src/test/java/E2ETests/Features/E2E_Main.java index 38c2af8..cc9e8fa 100644 --- a/src/test/java/E2ETests/Features/E2E_Main.java +++ b/src/test/java/E2ETests/Features/E2E_Main.java @@ -167,7 +167,7 @@ public class E2E_Main { Assertions.assertNull(returnValue); Assertions.assertEquals(3, byteArrayOutputStream.toString().length()); // durch die newline wird die Ausgabe um 2 Zeichen länger - Assertions.assertEquals("3", byteArrayOutputStream.toString().substring(0, byteArrayOutputStream.toString().length() - 2)); + Assertions.assertEquals("3", byteArrayOutputStream.toString().substring(0, 1)); System.setOut(originalOut); } catch (Exception e) { Assertions.fail(); diff --git a/src/test/java/E2ETests/Features/E2E_Print.java b/src/test/java/E2ETests/Features/E2E_Print.java index 62209c4..836323c 100644 --- a/src/test/java/E2ETests/Features/E2E_Print.java +++ b/src/test/java/E2ETests/Features/E2E_Print.java @@ -143,7 +143,7 @@ public class E2E_Print { Assertions.assertNull(returnValue); Assertions.assertEquals(3, byteArrayOutputStream.toString().length()); // durch die newline wird die Ausgabe um 2 Zeichen länger - Assertions.assertEquals("a", byteArrayOutputStream.toString().substring(0, byteArrayOutputStream.toString().length() - 2)); + Assertions.assertEquals("a", byteArrayOutputStream.toString().substring(0, 1)); System.setOut(originalOut); } catch (Exception e) { Assertions.fail(); @@ -165,7 +165,7 @@ public class E2E_Print { Assertions.assertNull(returnValue); Assertions.assertEquals(6, byteArrayOutputStream.toString().length()); // durch die newline wird die Ausgabe um 2 Zeichen länger - Assertions.assertEquals("true", byteArrayOutputStream.toString().substring(0, byteArrayOutputStream.toString().length() - 2)); + Assertions.assertEquals("true", byteArrayOutputStream.toString().substring(0, 4)); System.setOut(originalOut); } catch (Exception e) { Assertions.fail(); diff --git a/src/test/testFiles/AllFeaturesAtOnce/AllFeaturesInOne.java b/src/test/testFiles/AllFeaturesAtOnce/AllFeaturesInOne.java new file mode 100644 index 0000000..5c83d70 --- /dev/null +++ b/src/test/testFiles/AllFeaturesAtOnce/AllFeaturesInOne.java @@ -0,0 +1,202 @@ +public class AllFeaturesInOne { + // This is a comment + int repititionsOfSchema; + int maxLengthOfSchema; + char letter1; + char letter2; + char letter3; + boolean doStillExecuteAfterMaxLength; + Configuration configuration; + + public AllFeaturesInOne() { + this.letter1 = 'a'; + this.letter2 = 'b'; + this.letter3 = 'c'; + this.maxLengthOfSchema = 100; + this.doStillExecuteAfterMaxLength = false; + this.repititionsOfSchema = 5; + } + + public AllFeaturesInOne(char letter3) { + this.letter1 = 'a'; + this.letter2 = 'b'; + this.letter3 = letter3; + this.maxLengthOfSchema = 100; + this.doStillExecuteAfterMaxLength = false; + this.repititionsOfSchema = 5; + } + + public AllFeaturesInOne(int repititionsOfSchema, char letter3) { + this.repititionsOfSchema = repititionsOfSchema; + this.letter1 = 'a'; + this.letter2 = 'b'; + this.letter3 = letter3; + this.maxLengthOfSchema = 100; + this.doStillExecuteAfterMaxLength = false; + } + + public AllFeaturesInOne(Configuration configuration) { + this.configuration = configuration; + this.repititionsOfSchema = configuration.getRepititionsOfSchema(); + this.maxLengthOfSchema = configuration.maxLengthOfSchema; + this.letter1 = configuration.letter1; + this.letter2 = configuration.letter2; + this.letter3 = configuration.letter3; + this.doStillExecuteAfterMaxLength = configuration.doStillExecuteAfterMaxLength; + } + + public void printFibonacciSchema(boolean withSpaceBetweenSteps) { + int number1 = 0; + int number2 = 1; + int numberOfLetter = 0; + for (int i = 0; i < this.repititionsOfSchema; i++) { + if(number2 == this.maxLengthOfSchema && !this.doStillExecuteAfterMaxLength) { + break; + } + int j; + for(j = number2; j > 0; j -= 1) { + if (numberOfLetter == 0) { + print(this.letter1); + } else if (numberOfLetter == 1) { + print(this.letter2); + } else { + print(this.letter3); + } + } + if (withSpaceBetweenSteps) { + print('L'); + } + numberOfLetter = (numberOfLetter + 1) % 3; + int sum = number1 + number2; + number1 = number2; + number2 = sum; + } + } + + public void printFibonacciButWithMultiplication() { + int number1 = 1; + int number2 = 2; + int numberOfLetter = 0; + for (int i = 0; i < this.repititionsOfSchema; i += 1) { + if(number2 <= this.maxLengthOfSchema || this.doStillExecuteAfterMaxLength) { + int j; + for(j = 0; j < number2; j = j + 1) { + if (numberOfLetter == 0) { + print(this.letter1); + } else if (numberOfLetter == 1) { + print(this.letter2); + } else { + print(this.letter3); + } + } + print('L'); + numberOfLetter = (numberOfLetter + 1) % 3; + int number2OldValue = number2; + number2 *= number1; + number1 = number2OldValue; + } else { + return; + } + } + } + + public void printEveryLetterXTimesAndSkipEveryYTimesComplex(int x, int y) { + int numberOfLetter = 0; + int rest = 0; + int numberOfRepititions; + int numberToDivide; + int numberOfRepetitionsWithoutSkip = 0; + do { + numberOfRepititions = (x - rest) - ((x - rest) / y); + if (rest > 0) { + numberOfRepititions += rest - 1; + } + rest = (y - ((x + (-rest)) % y)) % y; + while (numberOfRepititions > 0) { + numberOfRepetitionsWithoutSkip++; + if (numberOfRepetitionsWithoutSkip == y) { + print(''); + numberOfRepetitionsWithoutSkip = 0; + } else { + if (numberOfLetter == 0) { + print(this.letter1); + } else if (numberOfLetter == 1) { + print(this.letter2); + } else { + print(this.letter3); + } + } + numberOfRepititions--; + } + numberOfLetter = (numberOfLetter + 1) % 3; + } while(rest != 0); + } + + public void printEveryLetterXTimesAndSkipEveryYTimesSimple(int x, int y) { + int numberOfLetter = 0; + int repititionsAbs = 0; + while((repititionsAbs % y) != 0 || repititionsAbs == 0) { + for (int i = 0; i < x; i++) { + repititionsAbs++; + if (repititionsAbs % y == 0) { + print('L'); + continue; + } + if (numberOfLetter == 0) { + print(this.letter1); + } else if (numberOfLetter == 1) { + print(this.letter2); + } else { + print(this.letter3); + } + } + numberOfLetter = (numberOfLetter + 1) % 3; + } + } + + public char getLetter2() { + return this.letter2; + } + + public void setLetter2(char letter2) { + this.letter2 = letter2; + } + + public int setMaxLengthOfSchema(int maxLengthOfSchema) { + this.maxLengthOfSchema = maxLengthOfSchema; + return this.maxLengthOfSchema; + } + + public void setDoStillExecuteAfterMaxLength(boolean doStillExecuteAfterMaxLength) { + this.doStillExecuteAfterMaxLength = doStillExecuteAfterMaxLength; + } + + public boolean allLettersAreDifferent() { + return this.letter1 != this.letter2 && this.letter1 != this.letter3 && letter2 != this.letter3; + } + + public static void main(String[] args) { + AllFeaturesInOne allFeaturesInOne = new AllFeaturesInOne('d'); + if (allFeaturesInOne.getLetter2() == 'd') { + allFeaturesInOne.setLetter2('i'); + } + allFeaturesInOne.setMaxLengthOfSchema(1000); + //should print the fibonacci schema in chars with a space between each step and with 5 steps + allFeaturesInOne.printFibonacciSchema(true); + + AllFeaturesInOne allFeaturesInOne2 = new AllFeaturesInOne(6, 'e'); + allFeaturesInOne2.setDoStillExecuteAfterMaxLength(true); + //should print the fibonacci schema in chars with a space between each step and with 6 steps + // but with mul instead of sum + allFeaturesInOne2.printFibonacciButWithMultiplication(); + + Configuration configuration = new Configuration(10, 100, 'f', 'g', 'h', true); + AllFeaturesInOne allFeaturesInOne3 = new AllFeaturesInOne(configuration); + print(allFeaturesInOne3.allLettersAreDifferent()); + // these two should print the same thing + allFeaturesInOne3.printEveryLetterXTimesAndSkipEveryYTimesComplex(13, 7); + allFeaturesInOne3.printEveryLetterXTimesAndSkipEveryYTimesSimple(13, 7); + // should print true + print(allFeaturesInOne3.configuration.getRepititionsOfSchema() == 10); + } +} \ No newline at end of file diff --git a/src/test/testFiles/AllFeaturesAtOnce/Configuration.java b/src/test/testFiles/AllFeaturesAtOnce/Configuration.java new file mode 100644 index 0000000..8017df7 --- /dev/null +++ b/src/test/testFiles/AllFeaturesAtOnce/Configuration.java @@ -0,0 +1,28 @@ +public class Configuration { + int repititionsOfSchema; + int maxLengthOfSchema; + char letter1; + char letter2; + char letter3; + boolean doStillExecuteAfterMaxLength; + + public Configuration( + int repititionsOfSchema, + int maxLengthOfSchema, + char letter1, + char letter2, + char letter3, + boolean doStillExecuteAfterMaxLength + ) { + this.repititionsOfSchema = repititionsOfSchema; + this.maxLengthOfSchema = maxLengthOfSchema; + this.letter1 = letter1; + this.letter2 = letter2; + this.letter3 = letter3; + this.doStillExecuteAfterMaxLength = doStillExecuteAfterMaxLength; + } + + public int getRepititionsOfSchema() { + return this.repititionsOfSchema; + } +} \ No newline at end of file