Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added files to testing directory #23

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/test/java/local/Casino/Account/AccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package local.Casino.Account;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class AccountTest {

private Account account;

@BeforeEach
public void setUp() {
int ID = 1;
String username = "testuser";
account = new Account(ID, username);
}

@Test
public void testGetBalance() {
double expectedBalance = 0.0;
double actualBalance = account.getBalance();
Assertions.assertEquals(expectedBalance, actualBalance);
}

@Test
public void testGetUsername() {
String expectedUsername = "testuser";
String actualUsername = account.getUsername();
Assertions.assertEquals(expectedUsername, actualUsername);
}

@Test
public void testIncreaseBalance() {
double increment = 100.0;
double expectedBalance = 100.0;
double actualBalance = account.increaseBalance(increment);
Assertions.assertEquals(expectedBalance, actualBalance);
}

@Test
public void testDecreaseBalance() {
double decrement = 50.0;
double expectedBalance = -50.0;
double actualBalance = account.decreaseBalance(decrement);
Assertions.assertEquals(expectedBalance, actualBalance);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package local.Casino.Account.Transaction;

public class DepositTest {

}
21 changes: 21 additions & 0 deletions src/test/java/local/Casino/Account/Transaction/PaymentTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package local.Casino.Account.Transaction;
import local.Casino.Account.Account;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class PaymentTest {

private Account sender;
private Account receiver;
@BeforeEach
public void setUp() {
sender = new Account(1, "sender");
receiver = new Account(2, "receiver");
int amountSent = 100;
new Payment(amountSent, sender, receiver);
}

@Test
public void testConstructor() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package local.Casino.Account.Transaction;

public class TransactionTest {

}
20 changes: 20 additions & 0 deletions src/test/java/local/Casino/Account/Transaction/WithdrawalTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package local.Casino.Account.Transaction;
import local.Casino.Account.Account;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class WithdrawalTest {

private Account sender;

@BeforeEach
public void setUp() {
sender = new Account(1, "sender");
int amountSent = 100;
withdrawal = new Withdrawal(amountSent, sender);
}

@Test
public void testConstructor() {
}
}
30 changes: 30 additions & 0 deletions src/test/java/local/Casino/CardGames/CardTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package local.Casino.CardGames;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CardTest {

@Test
public void testToString() {
Card card = new Card(Card.Value.ACE, Card.Suit.SPADES);
String expected = "Ace of Spades";
String actual = card.toString();
Assertions.assertEquals(expected, actual);
}

@Test
public void testToString_InvalidSuit() {
Card card = new Card(Card.Value.TWO, null);
String expected = "INVALID SUIT of Two";
String actual = card.toString();
Assertions.assertEquals(expected, actual);
}

@Test
public void testToString_InvalidValue() {
Card card = new Card(null, Card.Suit.HEARTS);
String expected = "INVALID VALUE of Hearts";
String actual = card.toString();
Assertions.assertEquals(expected, actual);
}
}
45 changes: 45 additions & 0 deletions src/test/java/local/Casino/CardGames/DeckTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package local.Casino.CardGames;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class DeckTest {

private Deck deck;

@BeforeEach
public void setUp() {
deck = new Deck();
}

@Test
public void testResetDeck() {
deck.shuffle();
deck.resetDeck();
Assertions.assertEquals(52, deck.mainDeck.length);
}

@Test
public void testShuffle() {
Card[] initialDeck = deck.mainDeck.clone();
deck.shuffle();

Assertions.assertNotEquals(initialDeck, deck.mainDeck);
}

@Test
public void testDeal() {
Card card = deck.deal();
Assertions.assertNotNull(card);
Assertions.assertEquals(51, deck.mainDeck.length);
}

@Test
public void testDeal_EmptyDeck() {
for (int i = 0; i < 52; i++) {
deck.deal();
}
Card card = deck.deal();
Assertions.assertNull(card);
}
}
53 changes: 53 additions & 0 deletions src/test/java/local/Casino/CasinoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package local.Casino;
import local.Casino.Account.Account;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class CasinoTest {

private Casino casino;

@BeforeEach
public void setUp() {
casino = new Casino(10);
}

@Test
public void testCreateAccount() {
int result = casino.createAccount("user1");
Assertions.assertEquals(0, result);
Assertions.assertNotNull(casino.getAccount("user1"));
}

@Test
public void testCreateAccount_MaxAccountsReached() {
for (int i = 0; i < 10; i++) {
casino.createAccount("user" + i);
}
int result = casino.createAccount("user11");
Assertions.assertEquals(1, result);
Assertions.assertNull(casino.getAccount("user11"));
}

@Test
public void testCreateAccount_InvalidUsername() {
casino.createAccount("user1");
int result = casino.createAccount("user1");
Assertions.assertEquals(2, result);
}

@Test
public void testGetAccount() {
casino.createAccount("user1");
Account account = casino.getAccount("user1");
Assertions.assertNotNull(account);
Assertions.assertEquals("user1", account.getUsername());
}

@Test
public void testGetAccount_NonexistentUsername() {
Account account = casino.getAccount("user1");
Assertions.assertNull(account);
}
}
26 changes: 26 additions & 0 deletions src/test/java/local/Casino/Slots/SlotsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package local.Casino.Slots;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import local.Casino.Slots.Slots.Symbol;

public class SlotsTest {

@Test
public void testGetWinnings_NoWinningCombination() {
Symbol[] rolls = {Symbol.LEMON, Symbol.WATERMELON, Symbol.HEART};
double bet = 10.0;
double expectedWinnings = 0.0;
double actualWinnings = Slots.getWinnings(rolls, bet);
Assertions.assertEquals(expectedWinnings, actualWinnings);
}

@Test
public void testPlaySlots() {
Symbol[] rolls = Slots.playSlots();
Assertions.assertEquals(Slots.NUMBER_OF_ROLLS, rolls.length);

for (Symbol symbol : rolls) {
Assertions.assertNotNull(symbol);
}
}
}