Merge remote-tracking branch 'origin/main'

This commit is contained in:
Leonardo Brandenberger 2021-11-11 11:45:01 +01:00
commit 1cc559b416
6 changed files with 111 additions and 14 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,16 @@
#Äquivalenzklassen
### Text.java Index method
|Positiv testcase||
|:---|:---|
|1. Case|At least one Word gets used more than 3 times but not more than 3 times in one paragraph && at least one word doesn't get used more than 3 times in the whole text.|
|2. Case|At least one word gets used more than 3 times in only one paragraph çç at least one word doesn't get used more than 3 times in the whole text.|
|3. Case|The same word is been written in uppercase and lowercase and is been noticed as the same word.|
|4. Case|Punctuation marks and spaces are in the text|
|Negativ testcase||
|:---|:---|
|1. Case|Empty list of paragraphs|
|2. Case|Several punctuation marks and or spaces are been used behind|

View File

@ -6,7 +6,6 @@ public class Text {
private final ArrayList<String> text = new ArrayList<>(); private final ArrayList<String> text = new ArrayList<>();
private static final String dummyText = "The standard Lorem Ipsum passage, used since the 1500s \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\" Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC \"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"; private static final String dummyText = "The standard Lorem Ipsum passage, used since the 1500s \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\" Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC \"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?";
private HashMap<String, ArrayList<Integer>> wordbook = new HashMap<>();
/** /**
* Method to check if a specific Paragraph exists * Method to check if a specific Paragraph exists
@ -136,7 +135,7 @@ public class Text {
* @return ArrayList<String> * @return ArrayList<String>
*/ */
public ArrayList<String> index() { public ArrayList<String> index() {
wordbook = createWordlist(); HashMap<String,ArrayList<Integer>> wordbook = createWordlist();
String input; String input;
ArrayList<String> output = new ArrayList<>(); ArrayList<String> output = new ArrayList<>();
ArrayList<Integer> values; ArrayList<Integer> values;
@ -165,6 +164,7 @@ public class Text {
* @return HashMap<String, ArrayList < Integer>> * @return HashMap<String, ArrayList < Integer>>
*/ */
private HashMap<String, ArrayList<Integer>> createWordlist() { private HashMap<String, ArrayList<Integer>> createWordlist() {
HashMap<String,ArrayList<Integer>> wordbook = new HashMap<>();
int counter; int counter;
ArrayList<Integer> numbersList; ArrayList<Integer> numbersList;
String firstLetter; String firstLetter;
@ -172,10 +172,12 @@ public class Text {
for (int i = 0; i < text.size(); i++) { for (int i = 0; i < text.size(); i++) {
String[] words = text.get(i).trim().toLowerCase().split("[ :;.,!?><'/\n]+"); String[] words = text.get(i).trim().toLowerCase().split("[ :;.,!?><'/\n]+");
for (String word : words) { for (String word : words) {
//Words get formatted consistently
counter = 1; counter = 1;
firstLetter = word.substring(0, 1); firstLetter = word.substring(0, 1);
restLetters = word.substring(1); restLetters = word.substring(1);
word = firstLetter.toUpperCase() + restLetters; word = firstLetter.toUpperCase() + restLetters;
//Words are beeing counted
if (wordbook.containsKey(word)) { if (wordbook.containsKey(word)) {
numbersList = wordbook.get(word); numbersList = wordbook.get(word);
counter = numbersList.get(0); counter = numbersList.get(0);

View File

@ -3,6 +3,7 @@ public class TextEditor {
public static void main(String[] args) { public static void main(String[] args) {
TextLogik t = new TextLogik(); TextLogik t = new TextLogik();
} }
} }

View File

@ -4,6 +4,11 @@ public class TextLogik {
private final Text text; private final Text text;
private final TextOutput textOutput; private final TextOutput textOutput;
/**
* Initiates a new instance of the class TextLogik.
* Contains command instructions for the class Text.
* Defined the different cases and appointed to specific commands.
*/
public TextLogik() { public TextLogik() {
text = new Text(); text = new Text();
textOutput = new TextOutput(); textOutput = new TextOutput();
@ -79,6 +84,12 @@ public class TextLogik {
} while (!"EXIT".equals(command[0])); } while (!"EXIT".equals(command[0]));
} }
/**
* Method to check if a command is numeric.
*
* @param str command that should be a number.
* @return true if the given str matches.
*/
private boolean isNumeric(String str) { private boolean isNumeric(String str) {
return str.matches("\\d+"); return str.matches("\\d+");
} }

View File

@ -1,28 +1,95 @@
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
public class TextTest { public class TextTest {
Text txt; Text txt;
ArrayList<String> sListe;
@BeforeEach @BeforeEach
void setup() { void setup() {
txt = new Text(); txt = new Text();
} }
/**
* Test Method for add and dummy methods
*/
@Test
void addTest() {
Assertions.assertEquals(0, txt.getText().size());
Assertions.assertEquals(false, txt.add(1, "test"));
Assertions.assertEquals(false, txt.dummy(1));
Assertions.assertEquals(0, txt.getText().size());
Assertions.assertEquals(true, txt.add("test1"));
Assertions.assertEquals(true, txt.add(1, "test2"));
Assertions.assertEquals("test2", txt.getText().get(0));
Assertions.assertEquals("test1", txt.getText().get(1));
Assertions.assertEquals(true, txt.dummy(2));
Assertions.assertEquals(true, txt.dummy());
Assertions.assertEquals(true, txt.getText().get(1).equals(txt.getText().get(3)));
Assertions.assertEquals(4, txt.getText().size());
}
/**
*
* Test Method del
*/
@Test
void del() {
Assertions.assertEquals(true, txt.add("Das ist der erste Beispiel Text."));
Assertions.assertEquals(true, txt.add("Das ist der zweite Beispiel Text."));
Assertions.assertEquals(true, txt.add("Das ist der dritte Beispiel Text."));
Assertions.assertEquals(true, txt.add("Das ist der vierte Beispiel Text."));
Assertions.assertEquals(false, txt.del(5));
Assertions.assertEquals(true, txt.del(2));
Assertions.assertEquals(true, txt.del());
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(0));
Assertions.assertEquals("Das ist der dritte Beispiel Text.", txt.getText().get(1));
}
/**
* Test Method for replace Method
*/
@Test
void replace() {
Assertions.assertEquals(true, txt.add("Das ist der erste Beispiel Text."));
Assertions.assertEquals(true, txt.add("Das ist der zweite Beispiel Text."));
Assertions.assertEquals(false, txt.replace(3, "alt", "neu"));
Assertions.assertEquals(true, txt.replace(1, "erste", "zweite"));
Assertions.assertEquals(true, txt.replace("zweite", "erste"));
Assertions.assertEquals("Das ist der zweite Beispiel Text.", txt.getText().get(0));
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(1));
}
/**
* Test methode for Index method
*/
@Test @Test
void indexTest() { void indexTest() {
txt.add("Hallo ?Hallo> zusammen !test!"); ArrayList<String> stringListe;
txt.add("Hallo, wie zusammen");
txt.add("Hallo! Wie wie zusammen"); //Positiv Testcase One, Three and Four Negativ Testcase Two
sListe= txt.index(); txt.add("Word word Test");
for (String str : sListe){ txt.add("Word word etc. !!test zweite... Zeile");
System.out.println(str); txt.add("Lorem ipsum lorem ipsum TEST");
} stringListe = txt.index();
Assertions.assertEquals("Hallo 1, 2, 3",sListe.get(0)); Assertions.assertEquals("Word 1, 2",stringListe.get(0));
Assertions.assertEquals("Test 1, 2, 3",stringListe.get(1));
//End of Test
setup();
//Positiv Testcase Two
txt.add("Word word Word Test");
stringListe = txt.index();
Assertions.assertEquals("Word 1",stringListe.get(0));
//End of Test
setup();
//Negativ Testcase One
stringListe = txt.index();
Assertions.assertEquals(0,stringListe.size());
} }
} }