2021-11-05 11:35:09 +01:00
|
|
|
import org.junit.jupiter.api.Assertions;
|
2021-11-05 09:14:26 +01:00
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
2021-11-12 10:37:38 +01:00
|
|
|
|
2021-11-05 09:14:26 +01:00
|
|
|
import java.util.ArrayList;
|
2021-11-10 18:19:40 +01:00
|
|
|
|
2021-11-12 11:11:03 +01:00
|
|
|
/**
|
|
|
|
* New class TextTest
|
|
|
|
* This class is here to test the different methods of the Text class.
|
|
|
|
* Author: Roman Schenk, Andrin Fassbind
|
|
|
|
* Date: 12.11.2021
|
|
|
|
*/
|
2021-11-04 14:19:58 +01:00
|
|
|
public class TextTest {
|
2021-11-05 09:14:26 +01:00
|
|
|
Text txt;
|
2021-11-12 10:49:19 +01:00
|
|
|
ArrayList<String> stringListe;
|
2021-11-05 09:14:26 +01:00
|
|
|
|
2021-11-12 11:11:03 +01:00
|
|
|
/**
|
2021-11-12 19:30:18 +01:00
|
|
|
* This method prepares local parameters by resets them for each test method
|
2021-11-12 11:11:03 +01:00
|
|
|
*/
|
2021-11-05 09:14:26 +01:00
|
|
|
@BeforeEach
|
|
|
|
void setup() {
|
2021-11-12 10:53:40 +01:00
|
|
|
stringListe = new ArrayList<>();
|
2021-11-05 09:14:26 +01:00
|
|
|
txt = new Text();
|
|
|
|
}
|
|
|
|
|
2021-11-12 19:30:18 +01:00
|
|
|
/**
|
|
|
|
* Test methode: indexNormalTest()
|
|
|
|
* <p>
|
|
|
|
* This test method checks, if the index method lists the words with all lines, in which they appear
|
|
|
|
* It should return "Word 1, 2" and "Test 1, 2, 3"
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void indexNormalTest() {
|
|
|
|
txt.add("Word word Test");
|
|
|
|
txt.add("Word word etc. !!test zweite... Zeile");
|
|
|
|
txt.add("Lorem ipsum lorem ipsum TEST");
|
|
|
|
stringListe = txt.index();
|
|
|
|
Assertions.assertEquals("Word 1, 2", stringListe.get(0));
|
|
|
|
Assertions.assertEquals("Test 1, 2, 3", stringListe.get(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test method: indexMultipleWordsTest()
|
|
|
|
* <p>
|
|
|
|
* This method tests if the method get the first word, which appears multiple times
|
|
|
|
* Index() should return
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void indexMultipleWordsTest() {
|
|
|
|
txt.add("Word Word Word Test");
|
|
|
|
Assertions.assertEquals("Word 1", txt.index().get(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test method: indexEmptyTest()
|
|
|
|
* <p>
|
|
|
|
* Tests the method index(), when there are no text saved or available
|
|
|
|
* It should return an empty Array with the type String
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void indexEmptyTest() {
|
|
|
|
Assertions.assertEquals(new ArrayList<String>(), txt.index());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test method: indexWithAddedEmptyLine()
|
|
|
|
* <p>
|
|
|
|
* Test Method to check if the method index() is working with empty Strings
|
|
|
|
* It should return an empty ArrayList with the type String
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void indexWithAddedEmptyLine() {
|
|
|
|
txt.add("");
|
|
|
|
Assertions.assertEquals(new ArrayList<String>(), txt.index());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-10 13:55:59 +01:00
|
|
|
/**
|
|
|
|
* Test Method for add and dummy methods
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void addTest() {
|
|
|
|
Assertions.assertEquals(0, txt.getText().size());
|
2021-11-11 14:05:46 +01:00
|
|
|
Assertions.assertFalse(txt.add(1, "test"));
|
|
|
|
Assertions.assertFalse(txt.dummy(1));
|
2021-11-10 13:55:59 +01:00
|
|
|
Assertions.assertEquals(0, txt.getText().size());
|
2021-11-11 14:05:46 +01:00
|
|
|
Assertions.assertTrue(txt.add("test1"));
|
|
|
|
Assertions.assertTrue(txt.add(1, "test2"));
|
2021-11-10 13:55:59 +01:00
|
|
|
Assertions.assertEquals("test2", txt.getText().get(0));
|
|
|
|
Assertions.assertEquals("test1", txt.getText().get(1));
|
2021-11-11 14:05:46 +01:00
|
|
|
Assertions.assertTrue(txt.dummy(2));
|
|
|
|
Assertions.assertTrue(txt.dummy());
|
|
|
|
Assertions.assertEquals(txt.getText().get(1), txt.getText().get(3));
|
2021-11-10 13:55:59 +01:00
|
|
|
Assertions.assertEquals(4, txt.getText().size());
|
|
|
|
}
|
|
|
|
|
2021-11-11 11:33:10 +01:00
|
|
|
/**
|
|
|
|
* Test Method del
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void del() {
|
2021-11-11 14:05:46 +01:00
|
|
|
Assertions.assertTrue(txt.add("Das ist der erste Beispiel Text."));
|
|
|
|
Assertions.assertTrue(txt.add("Das ist der zweite Beispiel Text."));
|
|
|
|
Assertions.assertTrue(txt.add("Das ist der dritte Beispiel Text."));
|
|
|
|
Assertions.assertTrue(txt.add("Das ist der vierte Beispiel Text."));
|
|
|
|
Assertions.assertFalse(txt.del(5));
|
|
|
|
Assertions.assertTrue(txt.del(2));
|
|
|
|
Assertions.assertTrue(txt.del());
|
2021-11-11 11:33:10 +01:00
|
|
|
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(0));
|
|
|
|
Assertions.assertEquals("Das ist der dritte Beispiel Text.", txt.getText().get(1));
|
|
|
|
}
|
|
|
|
|
2021-11-11 09:44:23 +01:00
|
|
|
/**
|
|
|
|
* Test Method for replace Method
|
|
|
|
*/
|
2021-11-11 09:43:14 +01:00
|
|
|
@Test
|
|
|
|
void replace() {
|
2021-11-11 14:05:46 +01:00
|
|
|
Assertions.assertTrue(txt.add("Das ist der erste Beispiel Text."));
|
|
|
|
Assertions.assertTrue(txt.add("Das ist der zweite Beispiel Text."));
|
|
|
|
Assertions.assertFalse(txt.replace(3, "alt", "neu"));
|
|
|
|
Assertions.assertTrue(txt.replace(1, "erste", "zweite"));
|
|
|
|
Assertions.assertTrue(txt.replace("zweite", "erste"));
|
2021-11-11 22:42:10 +01:00
|
|
|
Assertions.assertTrue(txt.add("Text Text hallo Text"));
|
|
|
|
Assertions.assertTrue(txt.replace("Text", "Test"));
|
2021-11-11 09:43:14 +01:00
|
|
|
Assertions.assertEquals("Das ist der zweite Beispiel Text.", txt.getText().get(0));
|
|
|
|
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(1));
|
2021-11-11 22:42:10 +01:00
|
|
|
Assertions.assertEquals("Test Test hallo Test", txt.getText().get(2));
|
2021-11-11 09:43:14 +01:00
|
|
|
}
|
|
|
|
|
2021-11-04 14:19:58 +01:00
|
|
|
}
|