Commit 188ddd6e authored by Michaelis, Maike's avatar Michaelis, Maike
Browse files

refactoring own solution from EA2-TDD

parent d7d92b31
package swt.ea2.tdd;
package swt.ea2.tdd;
/*
* Ein Buch hat einen Titel und ist einer Buchserie zugeordnet.
......
package swt.ea2.tdd;
package swt.ea2.tdd;
/*
* Eine Buchserie hat einen Namen und ein Preis, der für jeden Titel dieser Serie gilt.
......
package swt.ea2.tdd.impl;
import swt.ea2.tdd.Book;
/**
* Ein Buch hat einen Titel und ist einer Buchserie zugeordnet.
*
* @author Maike Michaelis (maike.michaelis@stud.th-luebeck.de)
* @version 1.0, 18.05.2020
*/
public class Book {
public class BookImpl implements Book {
private String title;
private BookSeries serie;
private BookSeriesImpl serie;
public Book(String title, BookSeries serie) {
public BookImpl(String title, BookSeriesImpl serie) {
this.title = title;
this.serie = serie;
}
......@@ -19,7 +21,7 @@ public class Book {
return title;
}
public BookSeries getSeries() {
public BookSeriesImpl getSeries() {
return serie;
}
......
package swt.ea2.tdd.impl;
import swt.ea2.tdd.BookSeries;
/**
* Eine Buchserie hat einen Namen und ein Preis, der für jeden Titel dieser Serie gilt.
*
* @author Maike Michaelis (maike.michaelis@stud.th-luebeck.de)
* @version 1.0, 18.05.2020
*/
public class BookSeries {
public class BookSeriesImpl implements BookSeries {
private double price;
private String serienID;
public BookSeries(String serienID, double price) {
public BookSeriesImpl(String serienID, double price) {
this.price = price;
this.serienID = serienID;
}
......
package swt.ea2.tdd.impl;
import swt.ea2.tdd.Book;
/**
* Warenkorbelement hat ein Buch und dessen Anzahl, die hinzugef�gt werden soll
*
......
package swt.ea2.tdd.impl;
import swt.ea2.tdd.Book;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
......@@ -14,7 +16,7 @@ import java.util.List;
* @author Maike Michaelis (maike.michaelis@stud.th-luebeck.de)
* @version 1.0, 18.05.2020
*/
public class ShoppingCart {
public class ShoppingCartImpl {
private double total = 0.0;
private double aktuell = 0.0;
private List<ShoppingCartElement> wk = new ArrayList<ShoppingCartElement>();
......
......@@ -3,12 +3,14 @@ package swt.ea2.tdd.impl;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import swt.ea2.tdd.BookSeries;
import swt.ea2.tdd.ShoppingCart;
class ShoppingCartTest {
ShoppingCart cart = new ShoppingCart();
BookSeries serieHarryPotter = new BookSeries("HP", 8.00);
BookSeries seriePT = new BookSeries("PT", 8.00);
ShoppingCartImpl cart = new ShoppingCartImpl();
BookSeriesImpl serieHarryPotter = new BookSeriesImpl("HP", 8.00);
BookSeriesImpl seriePT = new BookSeriesImpl("PT", 8.00);
@Test
void leererWarenkorb() {
......@@ -17,85 +19,85 @@ class ShoppingCartTest {
@Test
void keineSerie_einBuch() {
cart.addBook(new Book("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 1", serieHarryPotter), 1);
assertEquals(8.0, cart.getPrice(), 0.1);
}
@Test
void keineSerie_Anzahl_erhoeht() {
cart.addBook(new Book("Harry Potter 1", serieHarryPotter), 5);
cart.addBook(new BookImpl("Harry Potter 1", serieHarryPotter), 5);
assertEquals(40.0, cart.getPrice(), 0.1);
}
@Test
void keineSerie_unterschiedlicheSerienID() {
cart.addBook(new Book("Harry Potter 1",serieHarryPotter), 1);
cart.addBook(new Book("Phantastische Tierwesen 1",seriePT), 1);
cart.addBook(new BookImpl("Harry Potter 1",serieHarryPotter), 1);
cart.addBook(new BookImpl("Phantastische Tierwesen 1",seriePT), 1);
assertEquals(16.0, cart.getPrice(), 0.1);
}
@Test
void serie_Rabatt5() {
cart.addBook(new Book("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 2", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 2", serieHarryPotter), 1);
assertEquals(15.2, cart.getPrice(), 0.1);
}
@Test
void serie_Rabatt10() {
cart.addBook(new Book("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 2", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 3", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 2", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 3", serieHarryPotter), 1);
assertEquals(21.6, cart.getPrice(), 0.1);
}
@Test
void serie_Rabatt20() {
cart.addBook(new Book("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 2", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 3", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 4", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 2", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 3", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 4", serieHarryPotter), 1);
assertEquals(25.6, cart.getPrice(), 0.1);
}
@Test
void serie_Rabatt25() {
cart.addBook(new Book("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 2", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 3", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 4", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 5", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 2", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 3", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 4", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 5", serieHarryPotter), 1);
assertEquals(30.0, cart.getPrice(), 0.1);
}
@Test
void serie_mehrAls5Buecher_doppelteBuecher() {
cart.addBook(new Book("Harry Potter 5", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 4", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 3", serieHarryPotter), 2);
cart.addBook(new Book("Harry Potter 2", serieHarryPotter), 2);
cart.addBook(new Book("Harry Potter 1", serieHarryPotter), 2);
cart.addBook(new BookImpl("Harry Potter 5", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 4", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 3", serieHarryPotter), 2);
cart.addBook(new BookImpl("Harry Potter 2", serieHarryPotter), 2);
cart.addBook(new BookImpl("Harry Potter 1", serieHarryPotter), 2);
assertEquals(30.0+21.6, cart.getPrice(), 0.1);
}
@Test
void serie_mehrAls5Buecher_unterschiedlicheBuecher() {
cart.addBook(new Book("Harry Potter 7", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 6", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 5", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 2", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 3", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 4", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 7", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 6", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 5", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 1", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 2", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 3", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 4", serieHarryPotter), 1);
assertEquals(30.0+15.20, cart.getPrice(), 0.1);
}
@Test
void serie_Rabatt4_und_Rabatt2_und_einsOhneRabatt() {
cart.addBook(new Book("Harry Potter 7", serieHarryPotter), 2);
cart.addBook(new Book("Harry Potter 6", serieHarryPotter), 1);
cart.addBook(new Book("Harry Potter 5", serieHarryPotter), 1);
cart.addBook(new Book("Phantastische Tierwesen 1", seriePT), 1);
cart.addBook(new Book("Phantastische Tierwesen 2", seriePT), 1);
cart.addBook(new Book("Harry Potter 4", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 7", serieHarryPotter), 2);
cart.addBook(new BookImpl("Harry Potter 6", serieHarryPotter), 1);
cart.addBook(new BookImpl("Harry Potter 5", serieHarryPotter), 1);
cart.addBook(new BookImpl("Phantastische Tierwesen 1", seriePT), 1);
cart.addBook(new BookImpl("Phantastische Tierwesen 2", seriePT), 1);
cart.addBook(new BookImpl("Harry Potter 4", serieHarryPotter), 1);
assertEquals(25.6+15.2+8.0, cart.getPrice(), 0.1);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment