Example #1
0
 public void CloneShouldReturnObjectWithTheSameHashCode()
 {
     var card = new Card(CardSuit.Spade, CardType.Nine);
     var newCard = card.DeepClone();
     Assert.IsNotNull(newCard);
     Assert.AreEqual(card.GetHashCode(), newCard.GetHashCode());
 }
Example #2
0
 public void FromHashCodeShouldCreateCardsWithTheGivenHashCode()
 {
     foreach (CardSuit cardSuitValue in Enum.GetValues(typeof(CardSuit)))
     {
         foreach (CardType cardTypeValue in Enum.GetValues(typeof(CardType)))
         {
             var card = new Card(cardSuitValue, cardTypeValue);
             var hashCode = card.GetHashCode();
             var newCard = Card.FromHashCode(hashCode);
             Assert.AreEqual(card, newCard);
         }
     }
 }
Example #3
0
 public void GetHashCodeShouldReturn52ForKingOfSpades()
 {
     var card = new Card(CardSuit.Spade, CardType.King);
     var hashCode = card.GetHashCode();
     Assert.AreEqual(52, hashCode);
 }
Example #4
0
 public void GetHashCodeShouldReturnDifferentValidValueForEachCardCombination()
 {
     var values = new HashSet<int>();
     foreach (CardSuit cardSuitValue in Enum.GetValues(typeof(CardSuit)))
     {
         foreach (CardType cardTypeValue in Enum.GetValues(typeof(CardType)))
         {
             var card = new Card(cardSuitValue, cardTypeValue);
             var cardHashCode = card.GetHashCode();
             Assert.IsFalse(
                 values.Contains(cardHashCode),
                 $"Duplicate hash code \"{cardHashCode}\" for card \"{card}\"");
             values.Add(cardHashCode);
         }
     }
 }
Example #5
0
 public void GetHashCodeShouldReturn1ForAceOfClubs()
 {
     var card = new Card(CardSuit.Club, CardType.Ace);
     var hashCode = card.GetHashCode();
     Assert.AreEqual(1, hashCode);
 }