Exemple #1
0
        public void CardEquality()
        {
            var card1 = new Card_IsMutable(CardValue.Two, CardSuit.Club);
            var card2 = new Card_IsMutable(CardValue.Two, CardSuit.Club);

            Assert.Equal(card1, card2);
        }
Exemple #2
0
        public void Card_IsMutable_CausesProblems_OnHashTable()
        {
            //            var AceOfDiamonds = new Card_IsMutable(CardValue.Ace, CardSuit.Diamond);
            //            var AceOfHearts = new Card_IsMutable(CardValue.Ace, CardSuit.Heart);

            var mutableCard = new Card_IsMutable(CardValue.Ace, CardSuit.Diamond);

            //add the Ace Of Diamonds to the hash table
            var hash = new HashSet <Card_IsMutable>();

            hash.Add(mutableCard);

            Assert.Equal(mutableCard, new Card_IsMutable(CardValue.Ace, CardSuit.Diamond));
            Assert.True(hash.Contains(new Card_IsMutable(CardValue.Ace, CardSuit.Diamond)));

            //now we mutate the mutableCard from an Ace Of Diamonds to an Ace Of Hearts
            mutableCard.Suit = CardSuit.Heart;

            //the mutated card is equal to an Ace of Hearts
            Assert.Equal(mutableCard, new Card_IsMutable(CardValue.Ace, CardSuit.Heart));

            //but the Hashtable doesn't contain an ace of hearts
            Assert.False(hash.Contains(new Card_IsMutable(CardValue.Ace, CardSuit.Heart))); //so this fails
            Assert.False(hash.Contains(new Card_IsMutable(CardValue.Ace, CardSuit.Diamond)));

            var i = hash.GetEnumerator();

            i.MoveNext();
            var cardFromHashTable = i.Current;

            Assert.Equal(cardFromHashTable, new Card_IsMutable(CardValue.Ace, CardSuit.Heart));

            //now we mutate the mutableCard from an Ace Of Diamonds to an Ace Of Hearts
            mutableCard.Suit = CardSuit.Diamond;
            Assert.False(hash.Contains(new Card_IsMutable(CardValue.Ace, CardSuit.Heart))); //so this fails
            Assert.True(hash.Contains(new Card_IsMutable(CardValue.Ace, CardSuit.Diamond)));
        }
Exemple #3
0
        public void Card_IsMutable_CausesProblems()
        {
            //            var AceOfDiamonds = new Card_IsMutable(CardValue.Ace, CardSuit.Diamond);
            //            var AceOfHearts = new Card_IsMutable(CardValue.Ace, CardSuit.Heart);

            var mutableCard = new Card_IsMutable(CardValue.Ace, CardSuit.Diamond);

            //add the Ace Of Diamonds to the hash table
            var hash = new Hashtable();

            hash.Add(mutableCard, "");

            Assert.Equal(mutableCard, new Card_IsMutable(CardValue.Ace, CardSuit.Diamond));
            Assert.True(hash.ContainsKey(new Card_IsMutable(CardValue.Ace, CardSuit.Diamond)));

            //now we mutate the mutableCard from an Ace Of Diamonds to an Ace Of Hearts
            mutableCard.Suit = CardSuit.Heart;

            //the mutated card is equal to an Ace of Hearts
            Assert.Equal(mutableCard, new Card_IsMutable(CardValue.Ace, CardSuit.Heart));

            //but the Hashtable doesn't contain an ace of hearts
            Assert.True(hash.ContainsKey(new Card_IsMutable(CardValue.Ace, CardSuit.Heart))); //so this fails
        }