m-m-c-c / blef

Blef - gra karciana
3 stars 0 forks source link

Replace UT framawork xUnit with NUnit #22

Open cezarypiatek opened 7 years ago

cezarypiatek commented 7 years ago

It's hard to generate test data sets with xUnit. I recommend to use NUnit test framework. For example there is a PairwiseAttribute which could significantly simplify our tests https://github.com/nunit/docs/wiki/Pairwise-Attribute Of course there are XXXData attributes in xUnit but it's very tedious to generate Cartesian product of data sets.

Example 1 (Generates 36 tests cases)

[Test]
[Pairwise]
public void should_be_able_to_tell_that_pair_is_stronger_than_highcard(
    [Values(Rank.Nine, Rank.Ten, Rank.Jack, Rank.Queen, Rank.King, Rank.Ace)]Rank pairRank,
    [Values(Rank.Nine, Rank.Ten, Rank.Jack, Rank.Queen, Rank.King, Rank.Ace)]Rank highCardRank)
{
    //ARRANGE
    var pair = new Pair(pairRank);
    var highCard = new  HighCard(highCardRank);

    //ACT
    var result = pair.IsStrongerThan(highCard);

    //ASSERT
    Assert.True(result);
}
should_be_able_to_tell_that_pair_is_stronger_than_highcard (36 tests) [0:00.195] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ace,Ace) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ace,Jack) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ace,King) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ace,Nine) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ace,Queen) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ace,Ten) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Jack,Ace) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Jack,Jack) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Jack,King) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Jack,Nine) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Jack,Queen) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Jack,Ten) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(King,Ace) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(King,Jack) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(King,King) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(King,Nine) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(King,Queen) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(King,Ten) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Nine,Ace) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Nine,Jack) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Nine,King) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Nine,Nine) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Nine,Queen) [0:00.019] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Nine,Ten) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Queen,Ace) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Queen,Jack) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Queen,King) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Queen,Nine) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Queen,Queen) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Queen,Ten) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ten,Ace) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ten,Jack) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ten,King) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ten,Nine) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ten,Queen) [0:00.000] Success
should_be_able_to_tell_that_pair_is_stronger_than_highcard(Ten,Ten) [0:00.000] Success    

Example 2 (Generates 24 test cases)

[Test]
[Pairwise]
public void should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(
   [Values(Rank.Nine, Rank.Ten, Rank.Jack, Rank.Queen, Rank.King, Rank.Ace)]Rank highCardRank, 
   [Values(Suit.Clubs, Suit.Diamonds, Suit.Hearts, Suit.Spades)]Suit suit)
{
    //ARRANGE
    var table = new Table
    {
        PlayerHands = new[]
        {
            new PlayerHand
            {
                Cards = new[]
                {
                    new Card(highCardRank, suit)
                }
            }
        }
    };
    var highCard = new HighCard(highCardRank);

    //ACT
    var isPresence = highCard.IsOnTable(table);

    //ASSERT
    Assert.True(isPresence);
}

should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table (24 tests) [0:00.159] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Ace,Clubs) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Ace,Diamonds) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Ace,Hearts) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Ace,Spades) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Jack,Clubs) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Jack,Diamonds) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Jack,Hearts) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Jack,Spades) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(King,Clubs) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(King,Diamonds) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(King,Hearts) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(King,Spades) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Nine,Clubs) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Nine,Diamonds) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Nine,Hearts) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Nine,Spades) [0:00.034] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Queen,Clubs) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Queen,Diamonds) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Queen,Hearts) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Queen,Spades) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Ten,Clubs) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Ten,Diamonds) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Ten,Hearts) [0:00.000] Success
should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Ten,Spades) [0:00.000] Success

To achieve the same result with xUnit I have to write data sets generation logic by myself.

public static IEnumerable<object[]> GenerateAllRankSuitCombinations()
{
    foreach (var suit in new[] {Suit.Clubs, Suit.Diamonds, Suit.Hearts, Suit.Spades})
    {
        foreach (var rank in new[]{Rank.Nine, Rank.Ten, Rank.Jack, Rank.Queen, Rank.King, Rank.Ace})
            yield return new object[] { rank, suit };
    }
}

[Theory]
[MemberData(nameof(GenerateAllRankSuitCombinations))]
public void should_be_able_to_tell_that_highcard_is_presence_when_there_is_a_single_card_on_the_table(Rank highCardRank, Suit suit)
{
    //ARRANGE
    var table = new Table
    {
        PlayerHands = new[]
        {
            new PlayerHand
            {
                Cards = new[]
                {
                    new Card(highCardRank, suit)
                }
            }
        }
    };
    var highCard = new HighCard(highCardRank);

    //ACT
    var isPresence = highCard.IsOnTable(table);

    //ASSERT
    Assert.True(isPresence);
}
kmorcinek commented 7 years ago

xUnit is considered better than NUnit. Google at least claims that, I claim that, most of the people that I know that have comparing things the same. There are some things that are better in NUnit. But there are much more things in xUnit than in NUnit. And this things will show up. Are we going to have this discussion soon again going the oposite way?

cezarypiatek commented 7 years ago

@kmorcinek Comparing available functionality of xUnit with NUnit I cannot agree with you. Please look at available attributes for xUnit and NUnit https://xunit.github.io/docs/comparisons.html#attributes https://github.com/nunit/docs/wiki/Attributes

If you have a better source that could convince me please provide appropriate link.

Google at least claims that, I claim that

Please provide a facts that prove your thesis.