Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Restore compareTo() tests
Browse files Browse the repository at this point in the history
This partialls reverts commit 7c8b11e.
  • Loading branch information
StrangerCoug committed Oct 7, 2023
1 parent a8faff5 commit c97e6b4
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.jupiter.api.Assertions.assertThrows;

class CardTest {
Expand Down Expand Up @@ -64,6 +65,34 @@ void testEqualsContract() {
EqualsVerifier.forClass(Card.class).verify();
}

@Test
void testCompareToSameCard() {
Card card1 = new Card(CardRank.ACE, CardSuit.SPADES);
Card card2 = new Card(CardRank.ACE, CardSuit.SPADES);
assertThat(card1.compareTo(card2), equalTo(0));
}

@Test
void testCompareToDifferentRank() {
Card card1 = new Card(CardRank.TWO, CardSuit.SPADES);
Card card2 = new Card(CardRank.ACE, CardSuit.SPADES);
assertThat(card2.compareTo(card1), greaterThan(0));
}


@Test
void testCompareToDifferentSuit() {
Card card1 = new Card(CardRank.ACE, CardSuit.CLUBS);
Card card2 = new Card(CardRank.ACE, CardSuit.SPADES);
assertThat(card2.compareTo(card1), greaterThan(0));
}

@Test
void testCompareToNull() {
Card card = new Card(CardRank.ACE, CardSuit.CLUBS);
assertThrows(NullPointerException.class, () -> card.compareTo(null));
}

@Test
void testToString() {
String[] expectedValues = new String[]{"Two of Clubs", "Three of Diamonds", "Four of Hearts", "Five of Spades",
Expand Down

0 comments on commit c97e6b4

Please sign in to comment.