Add MonsterCard

This commit is contained in:
P0nk
2023-07-25 17:52:38 +02:00
parent 84ad5b4db8
commit e31465a1b5
2 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
package database.monsterbook;
public record MonsterCard(int cardId, byte level) {
public MonsterCard {
if (cardId / 10_000 != 238) {
throw new IllegalArgumentException("Invalid monster card id: %d".formatted(cardId));
}
if (level < 0 || level > 5) {
throw new IllegalArgumentException("Invalid monster card level: %d".formatted(level));
}
}
public boolean isSpecial() {
return cardId / 1000 == 2388;
}
}

View File

@@ -0,0 +1,48 @@
package database.monsterbook;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import static org.junit.jupiter.api.Assertions.*;
class MonsterCardTest {
@Test
void invalidCardId() {
assertThrows(IllegalArgumentException.class, () -> new MonsterCard(123456, validLevel()));
}
@ParameterizedTest
@ValueSource(bytes = {-1, 6})
void invalidLevel(byte invalidLevel) {
assertThrows(IllegalArgumentException.class, () -> new MonsterCard(validCardId(), invalidLevel));
}
@Test
public void createValidCard() {
assertDoesNotThrow(() -> new MonsterCard(validCardId(), validLevel()));
}
@Test
void specialCardIsSpecial() {
var specialCard = new MonsterCard(2388000, validLevel());
assertTrue(specialCard.isSpecial());
}
@Test
void normalCardIsNotSpecial() {
var normalCard = new MonsterCard(2381234, validLevel());
assertFalse(normalCard.isSpecial());
}
private int validCardId() {
return 2380000;
}
private byte validLevel() {
return 1;
}
}