Browse Source

Merge branch 'ChangeCards' into 'main'

Refactoring Cards

See merge request fdai7736/onses!8
main
fdai7736 11 months ago
parent
commit
2b6e429cef
  1. 41
      src/main/java/de/hsfulda/onses/models/Card.java
  2. 47
      src/main/java/de/hsfulda/onses/models/Cards.java
  3. 40
      src/test/java/de/hsfulda/onses/CardTest.java

41
src/main/java/de/hsfulda/onses/models/Card.java

@ -0,0 +1,41 @@
package de.hsfulda.onses.models;
public class Card {
private int id;
private Color color;
private Value value;
public enum Color {
RED, BLUE, GREEN, YELLOW, BLACK;
};
public enum Value {
ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DRAWTWO, SKIP, REVERSE, CHOOSE, CHOOSEDRAW;
};
public Card setId(int id) {
this.id = id;
return this;
}
public Card setColor(Color color) {
this.color = color;
return this;
}
public Card setValue(Value value) {
this.value = value;
return this;
}
public int getId() {
return this.id;
}
public Color getColor() {
return this.color;
}
public Value getValue() {
return this.value;
}
}

47
src/main/java/de/hsfulda/onses/models/Cards.java

@ -1,47 +0,0 @@
package de.hsfulda.onses.models;
public class Cards {
public enum ecolor {
RED, BLUE, GREEN, YELLOW, BLACK;
private static final ecolor[] colors = ecolor.values();
public static ecolor getColors (int n)
{
return ecolor.colors[n];
}
};
public enum evalue {
ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DRAWTWO, SKIP, REVERSE, CHOOSE, CHOOSEDRAW;
private static final evalue[] values = evalue.values();
public static evalue getValue(int n) {
return evalue.values[n];
}
};
private final int id;
private final ecolor color;
private final evalue value;
public Cards(int id, ecolor color, evalue value)
{
this.id = id;
this.color = color;
this.value = value;
}
public int getId() {
return this.id;
}
public ecolor getColor() {
return this.color;
}
public evalue getValue() {
return this.value;
}
}

40
src/test/java/de/hsfulda/onses/CardsTest.java → src/test/java/de/hsfulda/onses/CardTest.java

@ -5,9 +5,9 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import de.hsfulda.onses.models.Cards;
import de.hsfulda.onses.models.Card;
public class CardsTest {
public class CardTest {
@Test @Test
@DisplayName("CardGetID5") @DisplayName("CardGetID5")
@ -17,7 +17,7 @@ public class CardsTest {
int expected = 5; int expected = 5;
int ID = 5; int ID = 5;
// act // act
Cards testcard = new Cards(ID, Cards.ecolor.BLACK, Cards.evalue.FIVE);
Card testcard = new Card().setId(ID).setColor(Card.Color.BLACK).setValue(Card.Value.FIVE);
int answer = testcard.getId(); int answer = testcard.getId();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -31,7 +31,7 @@ public class CardsTest {
int expected = 112; int expected = 112;
int ID = 112; int ID = 112;
// act // act
Cards testcard = new Cards(ID, Cards.ecolor.BLUE, Cards.evalue.CHOOSEDRAW);
Card testcard = new Card().setId(ID).setColor(Card.Color.BLUE).setValue(Card.Value.CHOOSEDRAW);
int answer = testcard.getId(); int answer = testcard.getId();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -43,11 +43,11 @@ public class CardsTest {
public void CardTestGetColorBlue() { public void CardTestGetColorBlue() {
// arrange // arrange
Cards.ecolor expected = Cards.ecolor.BLUE;
Cards.ecolor color = Cards.ecolor.BLUE;
Card.Color expected = Card.Color.BLUE;
Card.Color color = Card.Color.BLUE;
// act // act
Cards testcard = new Cards(9, color, Cards.evalue.FIVE);
Cards.ecolor answer = testcard.getColor();
Card testcard = new Card().setId(9).setColor(color).setValue(Card.Value.FIVE);
Card.Color answer = testcard.getColor();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@ -56,11 +56,11 @@ public class CardsTest {
public void CardTestGetColorBlack() { public void CardTestGetColorBlack() {
// arrange // arrange
Cards.ecolor expected = Cards.ecolor.BLACK;
Cards.ecolor color = Cards.ecolor.BLACK;
Card.Color expected = Card.Color.BLACK;
Card.Color color = Card.Color.BLACK;
// act // act
Cards testcard = new Cards(15, color, Cards.evalue.CHOOSE);
Cards.ecolor answer = testcard.getColor();
Card testcard = new Card().setId(15).setColor(color).setValue(Card.Value.CHOOSE);
Card.Color answer = testcard.getColor();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@ -71,11 +71,11 @@ public class CardsTest {
public void CardTestGetValueThree() { public void CardTestGetValueThree() {
// arrange // arrange
Cards.evalue expected = Cards.evalue.THREE;
Cards.evalue value = Cards.evalue.THREE;
Card.Value expected = Card.Value.THREE;
Card.Value value = Card.Value.THREE;
// act // act
Cards testcard = new Cards(2, Cards.ecolor.BLUE, value);
Cards.evalue answer = testcard.getValue();
Card testcard = new Card().setId(2).setColor(Card.Color.BLUE).setValue(value);
Card.Value answer = testcard.getValue();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@ -84,11 +84,11 @@ public class CardsTest {
public void CardTestGetValueSkip() { public void CardTestGetValueSkip() {
// arrange // arrange
Cards.evalue expected = Cards.evalue.SKIP;
Cards.evalue value = Cards.evalue.SKIP;
Card.Value expected = Card.Value.SKIP;
Card.Value value = Card.Value.SKIP;
// act // act
Cards testcard = new Cards(19, Cards.ecolor.BLACK, value);
Cards.evalue answer = testcard.getValue();
Card testcard = new Card().setId(19).setColor(Card.Color.BLACK).setValue(value);
Card.Value answer = testcard.getValue();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
Loading…
Cancel
Save