本文整理汇总了C#中Card.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Card.GetHashCode方法的具体用法?C# Card.GetHashCode怎么用?C# Card.GetHashCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Card
的用法示例。
在下文中一共展示了Card.GetHashCode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloneShouldReturnObjectWithTheSameHashCode
public void CloneShouldReturnObjectWithTheSameHashCode()
{
var card = new Card(CardSuit.Spade, CardType.Nine);
var newCard = card.DeepClone();
Assert.IsNotNull(newCard);
Assert.AreEqual(card.GetHashCode(), newCard.GetHashCode());
}
示例2: cards_are_different_if_their_value_is_different
public void cards_are_different_if_their_value_is_different()
{
var card1 = new Card(Suit.Spades, 2);
var card2 = new Card(Suit.Spades, 3);
card1.ShouldNotEqual(card2);
card1.GetHashCode().ShouldNotEqual(card2.GetHashCode());
}
示例3: Card_GetHashCode_Test
public void Card_GetHashCode_Test()
{
var card1 = new Card(Rank.Ace, Suite.Club);
var card2 = new Card(Rank.King, Suite.Spades);
Assert.AreEqual(9, card1.GetHashCode());
Assert.AreEqual(108, card2.GetHashCode());
}
示例4: GetHashCode
public new void GetHashCode()
{
Assert.ThrowsExact<ArgumentNullException>(() => Instance.GetHashCode(null));
Assert.True(Instance.GetHashCode(Card.Joker) == Card.Joker.GetHashCode());
var aceSpades = new Card(Suit.Spades, Rank.Ace);
var aceHearts = new Card(Suit.Hearts, Rank.Ace);
var twoHearts = new Card(Suit.Hearts, Rank.Two);
Assert.True(Instance.GetHashCode(aceSpades) == aceSpades.GetHashCode());
Assert.True(Instance.GetHashCode(aceHearts) == aceHearts.GetHashCode());
Assert.True(Instance.GetHashCode(twoHearts) == twoHearts.GetHashCode());
Assert.False(Instance.GetHashCode(aceSpades) == aceHearts.GetHashCode());
Assert.False(Instance.GetHashCode(aceSpades) == twoHearts.GetHashCode());
Assert.False(Instance.GetHashCode(aceHearts) == aceSpades.GetHashCode());
Assert.False(Instance.GetHashCode(aceHearts) == twoHearts.GetHashCode());
Assert.False(Instance.GetHashCode(twoHearts) == aceSpades.GetHashCode());
Assert.False(Instance.GetHashCode(twoHearts) == aceHearts.GetHashCode());
}
示例5: EachCardHasDifferentHashCode
public void EachCardHasDifferentHashCode()
{
var cards = new Dictionary<int, Card>();
foreach (CardSuit cardColor in Enum.GetValues(typeof(CardSuit)))
{
foreach (CardType cardType in Enum.GetValues(typeof(CardType)))
{
var card = new Card(cardType, cardColor);
var hashCode = card.GetHashCode();
if (cards.ContainsKey(hashCode))
{
Assert.Fail("Found 2 cards with the same hash code: {0} and {1}", card, cards[hashCode]);
}
cards.Add(hashCode, card);
}
}
}
示例6: FromHashCodeShouldCreateCardsWithTheGivenHashCode
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);
}
}
}
示例7: GetHashCodeShouldReturnDifferentValidValueForEachCardCombination
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);
}
}
}
示例8: GetHashCodeShouldReturn52ForKingOfSpades
public void GetHashCodeShouldReturn52ForKingOfSpades(int expectedHashCode, CardSuit cardSuit, CardType cardType)
{
var card = new Card(cardSuit, cardType);
var hashCode = card.GetHashCode();
Assert.AreEqual(expectedHashCode, hashCode);
}