本文整理汇总了C#中Card.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Card.CompareTo方法的具体用法?C# Card.CompareTo怎么用?C# Card.CompareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Card
的用法示例。
在下文中一共展示了Card.CompareTo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSortCards
public void TestSortCards()
{
Card testAS = new Card(1, Suit.Spades);
Card testKS = new Card(13, Suit.Spades);
Card testQS = new Card(12, Suit.Spades);
List<Card> cards = new List<Card>() { testAS, testQS, testKS };
cards.Sort();
Assert.IsTrue(testAS.CompareTo(testKS) > 0);
Assert.IsFalse(testKS.CompareTo(testAS) > 0);
Assert.IsTrue(testAS.CompareTo(testQS) > 0);
Assert.IsFalse(testQS.CompareTo(testAS) > 0);
Assert.IsTrue(testKS.CompareTo(testQS) > 0);
Assert.IsFalse(testQS.CompareTo(testKS) > 0);
}
示例2: TestCardSort
public void TestCardSort(string first, string second, int expectedDifference)
{
var firstCard = new Card(first);
var secondCard = new Card(second);
var result = firstCard.CompareTo(secondCard);
Assert.AreEqual(expectedDifference, result);
}
示例3: TestCardCompareJackClubsWithJackHearts
public void TestCardCompareJackClubsWithJackHearts()
{
Card jackClubs = new Card(CardFace.Jack, CardSuit.Clubs);
Card jackHearts = new Card(CardFace.Jack, CardSuit.Hearts);
int expected = -2;
int actual = jackClubs.CompareTo(jackHearts);
Assert.AreEqual(expected, actual);
}
示例4: TestCardCompareAceWithJack
public void TestCardCompareAceWithJack()
{
Card ace = new Card(CardFace.Ace, CardSuit.Hearts);
Card jack = new Card(CardFace.Jack, CardSuit.Hearts);
int expected = 3;
int actual = ace.CompareTo(jack);
Assert.AreEqual(expected, actual);
}
示例5: TestCardCompareAceHeartsWithAceHearts
public void TestCardCompareAceHeartsWithAceHearts()
{
Card aceHearts = new Card(CardFace.Ace, CardSuit.Hearts);
Card anotherAceHearts = new Card(CardFace.Ace, CardSuit.Hearts);
int expected = 0;
int actual = aceHearts.CompareTo(anotherAceHearts);
Assert.AreEqual(expected, actual);
}
示例6: ShouldPassCompareToOffToItsIGame
public void ShouldPassCompareToOffToItsIGame()
{
game.Expect(g => g.Compare(null, null)).IgnoreArguments().Return(0);
var card1 = new Card(game) { Suit = "Clubs", Value = "5" };
var card2 = new Card(game) { Suit = "Clubs", Value = "5" };
card1.CompareTo(card2).ShouldBe(0);
game.AssertWasCalled(g => g.Compare(card1, card2), mo => mo.IgnoreArguments());
}
示例7: CompareToTest
public void CompareToTest()
{
IComparable target = new Card(); // TODO: Initialize to an appropriate value
object obj = null; // TODO: Initialize to an appropriate value
int expected = 0; // TODO: Initialize to an appropriate value
int actual;
actual = target.CompareTo(obj);
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
示例8: CompareCards
private int CompareCards(Card card1, Card card2)
{
Suit tempTrump = trumpSuit;
if (trumpSuit == Suit.None)
{
//Handle no trump
trumpSuit = CurrentTrickBaseSuit;
}
if (card2.Suit != tempTrump && card1.Suit != tempTrump)
{
return 0;
}
else if (card2.Suit != tempTrump && card1.Suit == tempTrump)
{
return 1;
}
else if (card1.Suit != tempTrump && card2.Suit != tempTrump)
{
return -1;
}
else
{
return card1.CompareTo(card2);
}
}
示例9: CompareToTest
public void CompareToTest()
{
var newCard = new Card(123, 123, "Name");
Assert.AreEqual(newCard.CompareTo(_card), 0, "CompareTo broke");
}
示例10: TestCardComparison_LowToHigh
public void TestCardComparison_LowToHigh()
{
List<Card> deck = DeckOfCards.GetPokerDeck();
Card lowCard = new Card { rank = Rank.Deuce, suit = Suit.Diamonds };
Card highCard = new Card { rank = Rank.Ten, suit = Suit.Clubs };
string actual = string.Format("{0} is {1} {2}", lowCard.ToString(),
lowCard.CompareTo(highCard) == -1 ? "lower than" : lowCard.CompareTo(highCard) == 1 ? "higher than"
: "the same as", highCard.ToString());
string expected = "Deuce of Diamonds is lower than Ten of Clubs";
StringAssert.AreEqualIgnoringCase(expected, actual);
}
示例11: TestCardComparison_BothAreSame
public void TestCardComparison_BothAreSame()
{
List<Card> deck = DeckOfCards.GetPokerDeck();
Card highCard = new Card { rank = Rank.Ten, suit = Suit.Clubs };
Card sameCard = new Card { rank = Rank.Ten, suit = Suit.Clubs };
string actual = string.Format("{0} is {1} {2}", highCard.ToString(),
highCard.CompareTo(sameCard) == -1 ? "lower than" : highCard.CompareTo(sameCard) == 1 ? "higher than"
: "the same as", sameCard.ToString());
string expected = "Ten of Clubs is the same as Ten of Clubs";
StringAssert.AreEqualIgnoringCase(expected, actual);
}
示例12: TestCardCompareTwoWithJack
public void TestCardCompareTwoWithJack()
{
Card jack = new Card(CardFace.Jack, CardSuit.Hearts);
Card two = new Card(CardFace.Two, CardSuit.Hearts);
int expected = -9;
int actual = two.CompareTo(jack);
Assert.AreEqual(expected, actual);
}