Funktionen Implementiert, Tests angepasst, Java Doc added

This commit is contained in:
Georg Reisinger 2020-10-18 12:35:58 +02:00
parent 061a978f6c
commit 95873d7e6d
23 changed files with 810 additions and 158 deletions

1
.gitignore vendored
View File

@ -22,3 +22,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.idea/compiler.xml
*.lst

View File

@ -1,37 +1,118 @@
/**
* Object einer Card
*/
public class Card {
private String name;
private double damage;
private ElementTyp elementTyp;
private CardType cardType;
/**
* Erstellt eine neue Card mit gegebenen Eigenschaften
* @param name Name der Card
* @param damage Damage den die Card macht
* @param elementTyp ElementType der Card
* @param cardType CardType der Card
*/
public Card(String name, double damage, ElementTyp elementTyp, CardType cardType) {
this.name = name;
this.damage = damage;
this.elementTyp = elementTyp;
this.cardType = cardType;
}
/**
* Holt den Namen der Card
* @return Name der Card
*/
public String getName() {
return "";
return this.name;
}
public int getDamage() {
return 0;
/**
* Holt den Damage der Card
* @return Damage der Card
*/
public double getDamage() {
return this.damage;
}
/**
* Holt den ElementType der Card
* @return ElementType der Card
*/
public ElementTyp getElementTyp() {
return null;
return this.elementTyp;
}
/**
* Holt den CardType der Card
* @return CardType der Card
*/
public CardType getCardType() {
return null;
return this.cardType;
}
public EffectivnessType getEffectivenessAgainst() {
return null;
/**
* Berechnet die Wirksamkeit gegen eine Andere card. Die Card im Parameter wird angegriffen
* @param toCeck Card gegen welche die Wirksamkeit geprüft werden soll
* @return Gibt die Wirksamkeit zurück
* @throws InternalError Wenn die Effectifeness von den 2 Cards nicht berechnet werden kann
*/
public EffectivnessType getEffectivenessAgainst(Card toCeck) {
if(toCeck.getCardType() == CardType.MONSTER){
if(this.cardType == CardType.MONSTER){
return EffectivnessType.NOEFFECT;
}else if (this.cardType == CardType.SPELL){
}
}else if (toCeck.getCardType() == CardType.SPELL){
if ((toCeck.getElementTyp() == ElementTyp.FIRE && this.elementTyp == ElementTyp.WATER) || (toCeck.getElementTyp() == ElementTyp.NORMAL && this.elementTyp == ElementTyp.FIRE) || (toCeck.getElementTyp() == ElementTyp.WATER && this.elementTyp == ElementTyp.NORMAL)){
return EffectivnessType.EFFECTIVE;
}else if (this.elementTyp == ElementTyp.FIRE && toCeck.getElementTyp() == ElementTyp.WATER){
return EffectivnessType.NOTEFFECTIVE;
}else if ((toCeck.getElementTyp() == ElementTyp.NORMAL && this.cardType == CardType.MONSTER && this.elementTyp == ElementTyp.NORMAL)){
return EffectivnessType.NOEFFECT;
}
}
throw new InternalError("Konnte die Effectiveness von den Cards nicht berechnen");
}
public boolean setName(String neuerName) {
return false;
/**
* Setztden namen der Card
* @param neuerName Name der Card
*/
public void setName(String neuerName) {
this.name = name;
}
public boolean setDamage(int damage) {
return false;
/**
* Setzt den Damage der Card
* @param damage Der Damage
*/
public void setDamage(int damage) {
this.damage = damage;
}
public boolean setElementType(ElementTyp elementTyp) {
return false;
/**
* Setzt den ElementType der Card
* @param elementTyp Der ElementType
*/
public void setElementType(ElementTyp elementTyp) {
this.elementTyp = elementTyp;
}
/**
* Testet ob die beiden Karten gleich sind
* @param card Card die geprüft werden soll
* @return True wenn die Karten übereinstimmen
*/
public boolean equals(Card card){
if(card == null) return false;
if(this.name == card.getName() && this.cardType == card.getCardType() && this.elementTyp == card.getElementTyp() && this.damage == card.getDamage()){
return true;
}else {
return false;
}
}
}

View File

@ -1,23 +1,78 @@
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Verwaltet eine Liste vo Cards
*/
public class Cards {
public Cards(ArrayList<Card> cardsArrayList) {
private ArrayList<Card> cards;
/**
* Erstellt ein nues obj mit gegebenen Karten
* @param cardsArrayList Die Cards zum erstellen des Obj
*/
public Cards(ArrayList<Card> cardsArrayList) {
this.cards = cardsArrayList;
}
/**
* Erstellt ein neues Obj ohne Cards
*/
public Cards() {
}
/**
* Fügt eine neue Card hinzu
* @param newCard neue Card
*/
public void addCard(Card newCard) {
this.cards.add(newCard);
}
/**
* Holt alle Cards
* @return Alle Cards
*/
public ArrayList<Card> getCards() {
return null;
return this.cards;
}
public boolean delCard(Card delCard) {
return false;
/**
* Löscht die gegebene Card
* @param delCard Card zum löschen
*/
public void delCard(Card delCard) {
this.cards.removeIf(obj -> obj.equals(delCard));
}
/**
* Prüft ob eine Card in den Cards vorhanden ist
* @param toCeck Card nach der in den Cards gesucht werden soll
* @return True wenn die Card in den Cards ist
*/
public boolean containsCard(Card toCeck){
AtomicBoolean returnval = new AtomicBoolean(false);
this.cards.forEach(item -> {
if(item.getElementTyp().equals(toCeck.getElementTyp()) && item.getCardType().equals(toCeck.getCardType()) && item.getName().equals(toCeck.getName()) && item.getDamage() == toCeck.getDamage()){
returnval.set(true);
}
});
return returnval.get();
}
/**
* Vergleicht 2 Cards Obj miteinander
* @param toCompare Cards zum vergleichen
* @return True wenn es aus den selben Cards besteht
*/
public boolean equals(Cards toCompare){
AtomicBoolean returnval = new AtomicBoolean(false);
this.cards.forEach(item -> {
if(toCompare.containsCard(item)){
returnval.set(true);
}
});
return returnval.get();
}
}

View File

@ -1,21 +1,65 @@
/**
* Alle coins eines Users
*/
public class Coins {
private int amount;
/**
* Erstellt ein neues Münzen Obj
* @param coins Alle münzen des Users
*/
public Coins(int coins) {
this.amount = coins;
}
/**
* Holt alle münzen
* @return Alle münzen
*/
public int getCoinAmount() {
return 0;
return this.amount;
}
/**
* Fügt münzen hinzu
* @param coins Münzen die hinzugefügt werden -> Positiv
* @throws NegativAmountException Wenn negative münzen hinzugefüght werden
*/
public void addCoin(int coins) throws NegativAmountException{
throw new NegativAmountException();
if(coins < 0) {
throw new NegativAmountException("Es kann kein negativer amount an Coins hinzugefügt werden");
}else {
this.amount += coins;
}
}
/**
* Entfernt münzen
* @param coins Münzen die entfernt werden sollen, muss positiv sein
* @return True wenn erfolgreich
* @throws NegativAmountException Wenn ein negativer betrag abgezogen werden soll
*/
public boolean removeCoin(int coins) throws NegativAmountException{
throw new NegativAmountException();
if(coins < 0) {
throw new NegativAmountException("Es kann kein negativer amount an Coins hinzugefügt werden");
}else {
this.amount -= coins;
return true;
}
}
public boolean changeCoinAmmount(int coins) {
return false;
/**
* Ändert den Absoluten Coin amount
* @param coins Neue Coin anzahl, muss positiv sein
* @return true wenn erfolgreich
* @throws NegativAmountException Wenn ein negativer wert eingegeben wird
*/
public boolean changeCoinAmmount(int coins) throws NegativAmountException{
if(coins < 0) {
throw new NegativAmountException("Es kann kein negativer amount an Coins hinzugefügt werden");
}else {
this.amount = coins;
return true;
}
}
}

View File

@ -1,2 +1,48 @@
/**
* User Login Daten
*/
public class Credentials {
private String passwort, username;
/**
* Startet einen neuen User mit folgenden Daten
* @param username Diesem Usernamen
* @param passwort Diesem Passwort
*/
public Credentials(String username, String passwort){
this.username = username;
this.passwort = passwort;
}
/**
* Holt das Passwort des users
* @return PW des Users
*/
public String getPasswort() {
return passwort;
}
/**
* Setzt das User Passwort
* @param passwort Neues Passwort
*/
public void setPasswort(String passwort) {
this.passwort = passwort;
}
/**
* Holt den Usernamen des Users
* @return Username
*/
public String getUsername() {
return username;
}
/**
* Setzt einen neuen Usernamen
* @param username Neuer Username
*/
public void setUsername(String username) {
this.username = username;
}
}

View File

@ -1,2 +1,64 @@
import java.util.ArrayList;
/**
* Stellt die Verbindung zur "Datenbank" her
* Die "Datenbank" sind hier nur beispieldaten.
*/
public class DBConnection {
private ArrayList<TradingDeal> tradingDeals;
private ArrayList<Package> packages;
/**
* Erstellt alle Beispieldaten und simuliert somit den
* Verbindungsaufbau zu einer DB
*/
public DBConnection(){
Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
Cards deck = new Cards();
Cards stack = new Cards();
deck.addCard(c1);
deck.addCard(c2);
stack.addCard(c3);
stack.addCard(c4);
stack.addCard(c5);
User user = new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000));
this.tradingDeals.add(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.SPELL));
this.packages.add(new Package(stack, "Test Package", 100));
}
/**
* Holt alle verfügbaren TradingDeals
* @return Alle Trading Deals
*/
public ArrayList<TradingDeal> getAllTradingDeals(){
return this.tradingDeals;
}
/**
* Holt alle verfügbaren Packages
* @return Alle Packages
*/
public ArrayList<Package> getAllPackages(){
return this.packages;
}
/**
* Fügt einen neuen Tradingdeal zum Store hinzu
* @param tradingDeal Der neue Deal
*/
public void addTradingDeal(TradingDeal tradingDeal){
this.tradingDeals.add(tradingDeal);
}
/**
* Fügt ein neues Package zu dem Store hinzu
* @param packageDeal Das neue Package
*/
public void addPackage(Package packageDeal){
this.packages.add(packageDeal);
}
}

View File

@ -1,5 +1,5 @@
public enum EffectivnessType {
EFFEKTIVE,
NOTEFFEKTIVE,
NOEFFEKT
EFFECTIVE,
NOTEFFECTIVE,
NOEFFECT
}

View File

@ -1,3 +1,3 @@
public enum ElementTyp {
WATER, FIRE
WATER, FIRE, NORMAL
}

View File

@ -1,2 +1,15 @@
/**
* Wenn ein negativer wert eingegeben wird aber ein Positiver erwartet wird, dann kann diese Exception geworfen werden
*/
public class NegativAmountException extends Exception {
/**
* Aufruf des Constructors der Super class Exception
* @param message Fehler Nachrichgt
* @param cause Fehler Ursache
*/
public NegativAmountException(String message){
super(message);
}
}

View File

@ -1,17 +1,43 @@
/**
* Package besteht aus 4 Karten. Ist eine Erweiterung der Cards, zeigt für 4 Cards den Preis und einen Packagenamen an
*/
public class Package extends Cards{
public Package(Cards stack, Cards deck, String name, int price) {
private String name;
private int price;
/**
* Erstellt ein neues Package mit den gegebenen Stats
* @param stack Cards des Packages
* @param name Name des Packages
* @param price Price des Packages
*/
public Package(Cards stack, String name, int price) {
super(stack.getCards());
this.name = name;
this.price = price;
}
/**
* Holt den namen des Packages
* @return Name des Packages
*/
public String getName() {
return null;
return this.name;
}
/**
* Holt den Preis des Packages
* @return Preis des Packages
*/
public int getPrice() {
return 0;
return this.price;
}
/**
* Setzt den Namen des Packages
* @param neuName Neuer name des Packages
*/
public void setName(String neuName) {
this.name = neuName;
}
}

View File

@ -1,17 +1,48 @@
/**
* Erweitert Cards insofern, dass es im Stack auch ein Deck gibt
*/
public class Stack extends Cards{
public Stack(Cards cards, Cards nochNewCards) {
private Cards deck;
/**
* Erstellt einen neuen Stack aus den User Cards und seinem Deck
* @param cards Alle Cards des Users
* @param deck Sein Deck
*/
public Stack(Cards cards, Cards deck) {
super(cards.getCards());
this.deck = deck;
}
/**
* Fügt ein neues Deck in den Stack ein
* @param newCards Gesamtes Deck
*/
public void addDeck(Cards newCards) {
this.deck = newCards;
}
/**
* Holt das gesamte Deck
* @return Gesamtes Deck
*/
public Cards getDeck() {
return null;
return this.deck;
}
public boolean delDeck(Cards delCards) {
return false;
/**
* Löscht eine Card aus dem Deck
* @param toDel Card zum löschen
*/
public void delDeck(Card toDel) {
this.deck.delCard(toDel);
}
/**
* Fügt dem deck eine neue Card ein
* @param toAdd Neue Card
*/
public void addDeckCard(Card toAdd){
this.deck.addCard(toAdd);
}
}

View File

@ -9,7 +9,5 @@ public interface Store {
boolean doTrading(TradingDeal tradingDeal1, TradingDeal tradingDeal2);
ArrayList<TradingDeal> getPossibleTradingDeals();
ArrayList<TradingDeal> getPossibleAvailableTradingDeals();
ArrayList<TradingDeal> getPossibleTradingDeals(Card toTrade);
}

View File

@ -1,43 +1,128 @@
/**
* Ein einzelner Trading deal wird hier verwaltet.
*/
public class TradingDeal {
private User tradingUser;
private Card cardToTrade;
private ElementTyp requiredElementType;
private double requiredMinDamage;
private CardType requiredCardType;
/**
* Ein TradingDeal wird erstellt
* @param user User des Deals
* @param cardToTrade Card die getauscht werden soll
* @param requiredElementType Req ElementType für den Tausch
* @param requiredMinDamage Req min damage für den Tausch
* @param requiredCardType Req Card Type für den Tausch
*/
public TradingDeal(User user, Card cardToTrade, ElementTyp requiredElementType, double requiredMinDamage, CardType requiredCardType) {
this.tradingUser = user;
this.cardToTrade = cardToTrade;
this.requiredElementType = requiredElementType;
this.requiredMinDamage = requiredMinDamage;
this.requiredCardType = requiredCardType;
}
/**
* Holt den Trading User
* @return User der den Trade erstellt hat
*/
public User getTradingUser() {
return null;
return this.tradingUser;
}
/**
* Card die getraded werden soll
* @return Card die getradet werden soll
*/
public Card getCardToTrade() {
return null;
return this.cardToTrade;
}
/**
* Req Element type holen
* @return Req Element Type
*/
public ElementTyp getRequiredElementType() {
return null;
return this.requiredElementType;
}
public int getRequiredMinDamage() {
return 0;
/**
* Req min damage holen
* @return Req min damage
*/
public double getRequiredMinDamage() {
return this.requiredMinDamage;
}
/**
* Hole req cardtype
* @return Req CardType
*/
public CardType getRequiredCardType() {
return null;
return this.requiredCardType;
}
public void setTradingUser(User user) {
/**
* Setzt den User des Trades
* @param tradingUser User der Traded
*/
public void setTradingUser(User tradingUser) {
this.tradingUser = tradingUser;
}
public void setCardToTrade(Card card) {
/**
* Setzt die Karte die Getradet werden soll
* @param cardToTrade Card zum tauschen
*/
public void setCardToTrade(Card cardToTrade) {
this.cardToTrade = cardToTrade;
}
public void setRequiredElementType(ElementTyp elementTyp) {
/**
* Setzt req elementType
* @param requiredElementType Der Req elementType
*/
public void setRequiredElementType(ElementTyp requiredElementType) {
this.requiredElementType = requiredElementType;
}
public void setRequiredMinDamage(int damage) {
/**
* Setzt die req Min damage
* @param requiredMinDamage Die req min gamage
*/
public void setRequiredMinDamage(double requiredMinDamage) {
this.requiredMinDamage = requiredMinDamage;
}
public void setRequiredCardType(CardType cardType) {
/**
* Setzt req cardType
* @param requiredCardType Der Req CardType
*/
public void setRequiredCardType(CardType requiredCardType) {
this.requiredCardType = requiredCardType;
}
/**
* Vom deal im Parameter wird die Card mit den Requirements von THIS verglichen
* @param checkDeal Von diesem Deal wird die CardToTrade geprüft
* @return True wenn der Deal passt
*/
public boolean dealOk(TradingDeal checkDeal){
return this.cardOk(checkDeal.getCardToTrade());
}
/**
* Von der Card im Parameter wird die Card mit den Requirements von THIS verglichen
* @param checkCard Card die mit dem Deal verglichen wird
* @return True wenn der Deal passt
*/
public boolean cardOk(Card checkCard){
if(checkCard.getCardType().equals(this.requiredCardType) && checkCard.getElementTyp().equals(this.requiredElementType) && checkCard.getDamage() >= this.requiredMinDamage){
return true;
}else {
return false;
}
}
}

View File

@ -1,55 +1,218 @@
import java.util.ArrayList;
/**
* User & Store Logik
*/
public class User implements Store{
private String name, nachname, email;
private Stack stack;
private DBConnection db;
private Credentials credentials;
private Coins coins;
/**
* Erstellt einen neuen User
* @param credentials Zugangsdaten des Users
* @param name Name des Users
* @param nachname Nachname des Users
* @param email Email des Users
* @param stack Alle Karten des Users
* @param coins Alle Münzen des Users
*/
public User(Credentials credentials, String name, String nachname, String email, Stack stack, Coins coins) {
this.credentials = credentials;
this.name = name;
this.nachname = nachname;
this.email = email;
this.stack = stack;
this.coins = coins;
this.db = new DBConnection();
}
/**
* Holt den Stack des Users
* @return Stack des Users
*/
public Stack getStack() {
return stack;
}
/**
* Setzt den Stack eines Users
* @param stack Der neue Stack des Users
*/
public void setStack(Stack stack) {
this.stack = stack;
}
/**
* Holt das DB Obj
* @return Das DB Obj
*/
public DBConnection getDb() {
return db;
}
/**
* Setzt ein neues DB Obj
* @param db Das neue DB Obj
*/
public void setDb(DBConnection db) {
this.db = db;
}
/**
* Holt die eindeutigen Logindaten des Users
* @return Eindeutige Logindaten
*/
public Credentials getCredentials() {
return credentials;
}
/**
* Setzt die eindeutigen Logindaten
* @param credentials Die neuen Credentials des Users
*/
public void setCredentials(Credentials credentials) {
this.credentials = credentials;
}
/**
* Holt alle Coins des Users
* @return Coins des Users
*/
public Coins getCoins() {
return coins;
}
/**
* Setzt alle Coins des Users
* @param coins Neue Coins des Users
*/
public void setCoins(Coins coins) {
this.coins = coins;
}
/**
* Get Name of User
* @return Name of User
*/
public String getName() {
return null;
return this.name;
}
/**
* Get Nachname of User
* @return Nachname of User
*/
public String getNachname() {
return null;
return this.nachname;
}
/**
* Email of User
* @return Email of User
*/
public String getEmail() {
return null;
return this.email;
}
public String setName(String name) {
return null;
/**
* Setzt den Namen des Users
* @param name Neuer Name des Users
*/
public void setName(String name) {
this.name = name;
}
public String setNachname(String nachname) {
return null;
/**
* Setzt den Nachnamen
* @param nachname Neuer Nachname
*/
public void setNachname(String nachname) {
this.nachname = nachname;
}
public String setEmail(String email) {
return null;
/**
* Setzt die Email des Users
* @param email Neue Email des Users
*/
public void setEmail(String email) {
this.email = email;
}
public Cards buyPackage(Package mypackage) {
return null;
//Store Methoden
/**
* Kauft ein Package
* @param mypackage Package welches gekauft werden soll
* @return Alle Karten des neuen Package
* @throws NegativAmountException Wenn ein negativer Preis im Package gesetzt wird.
*/
public ArrayList<Card> buyPackage(Package mypackage) throws NegativAmountException {
ArrayList<Package> availablePackages = db.getAllPackages();
availablePackages.removeIf(obj -> obj.equals(mypackage));
this.coins.removeCoin(mypackage.getPrice());
return mypackage.getCards();
}
/**
* Fügt dem Store einen neuen Tradingdeal hinzu
* @param tradingDeal Der neue Tradingdeal
*/
public void addTradingDeal(TradingDeal tradingDeal) {
db.addTradingDeal(tradingDeal);
}
/**
* Holt alle verfügbaren Tradingdeals
* @return Alle verfügbaren Deals
*/
public ArrayList<TradingDeal> getTradingDeals() {
return null;
return db.getAllTradingDeals();
}
public boolean doTrading(TradingDeal tradingDeal1, TradingDeal tradingDeal2) {
/**
* Startet ein Trading zw 2 TradingDeals
* @param myTradingDeal Wenn der Deal passt, wird diese Karte aus dem Stack entfernt
* @param storeTradingDeal Wenn der Deal passt, wird diese Karte dem Stack hinzugefügt
* @return True wenn erfolgreich, False wenn die Deals nicht zusammenpassen
*/
public boolean doTrading(TradingDeal myTradingDeal, TradingDeal storeTradingDeal) {
if (storeTradingDeal.dealOk(myTradingDeal)){
stack.delCard(myTradingDeal.getCardToTrade());
stack.addCard(storeTradingDeal.getCardToTrade());
}
return false;
}
public ArrayList<TradingDeal> getPossibleTradingDeals() {
return null;
/**
* Gibt alle Möglichen Trading Deals zurück
* @param toTrade Prüft nach diesem Deal
* @return
*/
@Override
public ArrayList<TradingDeal> getPossibleTradingDeals(Card toTrade) {
ArrayList<TradingDeal> storeList = db.getAllTradingDeals();
ArrayList<TradingDeal> possible = new ArrayList<TradingDeal>();
storeList.forEach(item -> {
if(item.cardOk(toTrade)){
possible.add(item);
}
});
return possible;
}
public ArrayList<TradingDeal> getPossibleAvailableTradingDeals() {
return null;
/**
* Checkt ob es sich um den selben User handelt
* @param toCheck Mit diesem User wird verglichen
* @return True wenn es der selbe User ist
*/
public boolean equals(User toCheck){
if (toCheck.getCredentials().getUsername() == this.credentials.getUsername() && toCheck.getCredentials().getPasswort() == this.credentials.getPasswort()){
return true;
}else {
return false;
}
}
}

View File

@ -7,47 +7,48 @@ public class CardTest {
@Test
public void test_getName() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
assertTrue(card.getName() != "");
assertTrue(card.getName().equals("Name"));
}
@Test
public void test_getDamage() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
assertTrue(card.getDamage() >= 0);
assertTrue(card.getDamage() == 10);
}
@Test
public void test_getElementType() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
ElementTyp elementTyp = card.getElementTyp();
assertTrue(elementTyp != null);
assertTrue(elementTyp != ElementTyp.WATER);
}
@Test
public void test_getCardType() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
CardType cardType = card.getCardType();
assertTrue(cardType != null);
assertTrue(cardType != CardType.SPELL);
}
@Test
public void test_getEffectivenessAgainst() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
EffectivnessType effectivnessType = card.getEffectivenessAgainst();
assertTrue(effectivnessType != null);
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
Card card2 = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
EffectivnessType effectivnessType = card.getEffectivenessAgainst(card2);
assertTrue(effectivnessType != EffectivnessType.NOEFFECT);
}
@Test
public void test_setName() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
boolean result = card.setName("NeuerName");
assertTrue(result);
card.setName("NeuerName");
assertTrue(card.getName().equals("NeuerName"));
}
@Test
public void test_setDamage() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
boolean result = card.setDamage(100);
assertTrue(result);
card.setDamage(100);
assertTrue(card.getDamage() == 100);
}
@Test
public void test_setElementTyp() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
boolean result = card.setElementType(ElementTyp.WATER);
assertTrue(result);
card.setElementType(ElementTyp.FIRE);
assertTrue(card.getElementTyp() == ElementTyp.FIRE);
}
}

View File

@ -5,34 +5,40 @@ import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CardsTest {
public Card newCard, card;
public Cards cards;
public ArrayList<Card> cardsArrayList;
private Cards newCards, cards, nochNewCards;
private Card newCard, card;
private ArrayList<Card> cardsArrayList, cardsArrayList2, cardsArrayList3;
private Stack stack;
@BeforeEach
void setUp() {
card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL);
cardsArrayList = new ArrayList<Card>();
cardsArrayList2 = new ArrayList<Card>();
cardsArrayList3 = new ArrayList<Card>();
cardsArrayList.add(card);
cardsArrayList2.add(newCard);
cardsArrayList2.add(card);
cards = new Cards(cardsArrayList);
newCards = new Cards(cardsArrayList2);
nochNewCards = new Cards(cardsArrayList3);
stack = new Stack(cards, nochNewCards);
}
@Test
void test_addCard() {
ArrayList<Card> result = cards.getCards();
cards.addCard(newCard);
cardsArrayList.add(newCard);
assertTrue(result == cardsArrayList);
assertTrue(cards.getCards().equals(cardsArrayList2));
}
@Test
void test_delCard() {
boolean result = cards.delCard(newCard);
assertTrue(result);
cards.addCard(newCard);
cards.delCard(newCard);
assertTrue(cards.getCards().equals(cardsArrayList));
}
@Test
void test_getCards() {
ArrayList<Card> result = cards.getCards();
assertTrue(result == cardsArrayList);
assertTrue(cards.getCards().equals(cardsArrayList));
}
}

View File

@ -19,7 +19,7 @@ public class CoinsTest {
coin.addCoin(-10);
fail("Erwartet NegativAmountException - addCoin");
}catch (NegativAmountException negativAmountException) {
assertTrue(negativAmountException.getMessage()=="negativAmountException");
assertTrue(negativAmountException.getMessage().equals("Es kann kein negativer amount an Coins hinzugefügt werden"));
}
}
@ -30,7 +30,7 @@ public class CoinsTest {
coin.removeCoin(-10);
fail("Erwartet NegativAmountException - removeCoin");
}catch (NegativAmountException negativAmountException) {
assertTrue(negativAmountException.getMessage()=="negativAmountException");
assertTrue(negativAmountException.getMessage().equals("Es kann kein negativer amount an Coins hinzugefügt werden"));
}
}
@ -47,12 +47,20 @@ public class CoinsTest {
@Test
public void test_changeCoinAmount_true(){
Coins coin = new Coins(10);
assertTrue(coin.changeCoinAmmount(-10));
try {
assertTrue(coin.changeCoinAmmount(10));
} catch (NegativAmountException e) {
e.printStackTrace();
}
}
@Test
public void test_changeCoinAmount_false(){
Coins coin = new Coins(9);
assertFalse(coin.changeCoinAmmount(-10));
try {
assertTrue(coin.changeCoinAmmount(7));
} catch (NegativAmountException e) {
e.printStackTrace();
}
}
}

View File

@ -23,13 +23,13 @@ public class PackageTest {
cards = new Cards(cardsArrayList);
newCards = new Cards(cardsArrayList2);
nochNewCards = new Cards(cardsArrayList3);
myPackage = new Package(cards, nochNewCards, "Name", 100);
myPackage = new Package(cards,"Name", 100);
}
@Test
void test_getName() {
String result = myPackage.getName();
assertTrue(result=="Name");
assertTrue(result.equals("Name"));
}
@Test
@ -42,6 +42,6 @@ public class PackageTest {
void test_setName() {
myPackage.setName("neuName");
String result = myPackage.getName();
assertTrue(result=="neuName");
assertTrue(result.equals("neuName"));
}
}

View File

@ -1,18 +0,0 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.mock;
public class SimpleCardTest {
@Test
@DisplayName("Test - getName()")
public void test_getName(){
//arrange
Card mockedA = mock(Card.class); //Erstellt einen Mock
String name = "Neuer Name";
//act
//assert
}
}

View File

@ -11,6 +11,7 @@ public class StackTest {
private Card newCard, card;
private ArrayList<Card> cardsArrayList, cardsArrayList2, cardsArrayList3;
private Stack stack;
@BeforeEach
void setUp() {
card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
@ -20,6 +21,7 @@ public class StackTest {
cardsArrayList3 = new ArrayList<Card>();
cardsArrayList.add(card);
cardsArrayList2.add(newCard);
cardsArrayList2.add(card);
cards = new Cards(cardsArrayList);
newCards = new Cards(cardsArrayList2);
nochNewCards = new Cards(cardsArrayList3);
@ -29,16 +31,17 @@ public class StackTest {
void test_addDeck() {
stack.addDeck(newCards);
Cards result = stack.getDeck();
assertTrue(result == newCards);
assertTrue(result.equals(newCards));
}
@Test
void test_delDeck() {
boolean result = stack.delDeck(cards);
assertTrue(result);
stack.addDeck(newCards);
stack.delDeck(newCard);
assertTrue(stack.getDeck().equals(cards));
}
@Test
void test_getDeck() {
Cards result = stack.getDeck();
assertTrue(result == cards);
assertTrue(result.equals(cards));
}
}

View File

@ -33,7 +33,7 @@ public class StoreTest {
//Coins
Coins coins = new Coins(10);
//User
Credentials credentials = new Credentials();
Credentials credentials = new Credentials("username", "passwort");
user = new User(credentials, "name", "nachname", "email", stack, coins);
userNew = new User(credentials, "nameNew", "nachnameNew", "emailNew", stack, coins);
@ -51,32 +51,70 @@ public class StoreTest {
user.addTradingDeal(tradingDeal);
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>();
expected.add(tradingDeal);
assertTrue(user.getTradingDeals() == expected);
Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
Cards deck = new Cards();
Cards stack = new Cards();
deck.addCard(c1);
deck.addCard(c2);
stack.addCard(c3);
stack.addCard(c4);
stack.addCard(c5);
TradingDeal vonDB = new TradingDeal(new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)), c1, ElementTyp.FIRE, 10, CardType.SPELL);
expected.add(vonDB);
assertTrue(user.getTradingDeals().equals(expected));
}
@Test
void test_doTrade() {
boolean result = user.doTrading(tradingDeal, tradingDeal);
Card cardtest = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
TradingDeal tradingDealtest = new TradingDeal(user, cardtest, ElementTyp.WATER, 100, CardType.MONSTER);
boolean result = user.doTrading(tradingDeal, tradingDealtest);
assertTrue(result);
}
@Test
void test_getTradingDeals() {
ArrayList<TradingDeal> result = user.getTradingDeals();
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>();
Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
Cards deck = new Cards();
Cards stack = new Cards();
deck.addCard(c1);
deck.addCard(c2);
stack.addCard(c3);
stack.addCard(c4);
stack.addCard(c5);
TradingDeal vonDB = new TradingDeal(new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)), c1, ElementTyp.FIRE, 10, CardType.SPELL);
expected.add(vonDB);
expected.add(tradingDeal);
assertTrue(result == expected);
assertTrue(result.equals(expected));
}
@Test
void test_getPossibleTradingDeals() {
ArrayList<TradingDeal> result = user.getPossibleTradingDeals();
Card testCard = new Card("Test", 15, ElementTyp.FIRE, CardType.SPELL);
ArrayList<TradingDeal> result = user.getPossibleTradingDeals(testCard);
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>();
expected.add(tradingDeal);
assertTrue(result == expected);
}
@Test
void test_getAvailableTradingDeals() {
ArrayList<TradingDeal> result = user.getPossibleAvailableTradingDeals();
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>();
expected.add(tradingDeal);
assertTrue(result == expected);
Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
Cards deck = new Cards();
Cards stack = new Cards();
deck.addCard(c1);
deck.addCard(c2);
stack.addCard(c3);
stack.addCard(c4);
stack.addCard(c5);
TradingDeal vonDB = new TradingDeal(new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)), c1, ElementTyp.FIRE, 10, CardType.SPELL);
expected.add(vonDB);
assertTrue(result.equals(expected));
}
}

View File

@ -33,9 +33,10 @@ public class TradingDealTest {
//Coins
Coins coins = new Coins(10);
//User
Credentials credentials = new Credentials();
Credentials credentials = new Credentials("username", "passwort");
Credentials newCredentials = new Credentials("usernamenew", "passwortnew");
user = new User(credentials, "name", "nachname", "email", stack, coins);
userNew = new User(credentials, "nameNew", "nachnameNew", "emailNew", stack, coins);
userNew = new User(newCredentials, "nameNew", "nachnameNew", "emailNew", stack, coins);
//Trading Deal
Card cardToTrade = card;
@ -48,12 +49,12 @@ public class TradingDealTest {
@Test
void test_getTradingUser() {
User result = tradingDeal.getTradingUser();
assertTrue(result==user);
assertTrue(result.equals(user));
}
@Test
void test_getCardToTrade() {
Card result = tradingDeal.getCardToTrade();
assertTrue(result==card);
assertTrue(result.equals(card));
}
@Test
void test_getRequiredElementType() {
@ -62,7 +63,7 @@ public class TradingDealTest {
}
@Test
void test_getRequiredMinDamage() {
int result = tradingDeal.getRequiredMinDamage();
double result = tradingDeal.getRequiredMinDamage();
assertTrue(result==100);
}
@Test
@ -75,7 +76,7 @@ public class TradingDealTest {
void test_setTradingUser() {
tradingDeal.setTradingUser(userNew);
User result = tradingDeal.getTradingUser();
assertTrue(result==userNew);
assertTrue(result.equals(userNew));
}
@Test
void test_setCardToTrade() {
@ -92,7 +93,7 @@ public class TradingDealTest {
@Test
void test_setRequiredMinDamage() {
tradingDeal.setRequiredMinDamage(10);
int result = tradingDeal.getRequiredMinDamage();
double result = tradingDeal.getRequiredMinDamage();
assertTrue(result==10);
}
@Test

View File

@ -30,51 +30,59 @@ public class UserTest {
nochNewCards = new Cards(cardsArrayList3);
stack = new Stack(cards, nochNewCards);
//Package
myPackage = new Package(cards, nochNewCards, "Name", 100);
myPackage = new Package(cards, "Name", 100);
//Coins
Coins coins = new Coins(10);
//User
Credentials credentials = new Credentials();
Credentials credentials = new Credentials("username", "pw");
user = new User(credentials, "name", "nachname", "email", stack, coins);
}
@Test
public void test_getName() {
String result = user.getName();
assertTrue(result != "");
assertTrue(result != "name");
}
@Test
public void test_getNachname() {
String result = user.getNachname();
assertTrue(result != "");
assertTrue(result != "nachname");
}
@Test
public void test_getEmail() {
String result = user.getEmail();
assertTrue(result != "");
assertTrue(result != "email");
}
@Test
public void test_setName() {
String newstring = "new";
String result = user.setName(newstring);
user.setName(newstring);
String result = user.getName();
assertTrue(result != newstring);
}
@Test
public void test_setNachname() {
String newstring = "new";
String result = user.setNachname(newstring);
user.setNachname(newstring);
String result = user.getNachname();
assertTrue(result != newstring);
}
@Test
public void test_setEmail() {
String newstring = "new";
String result = user.setEmail(newstring);
user.setEmail(newstring);
String result = user.getEmail();
assertTrue(result != newstring);
}
@Test
public void test_buyPackage(){
Cards cards = user.buyPackage(myPackage);
assertTrue(cards != null);
Cards cards = null;
try {
cards = new Cards(user.buyPackage(myPackage));
} catch (NegativAmountException e) {
e.printStackTrace();
}
assertTrue(cards.equals(new Cards(myPackage.getCards())));
}
}