コード例 #1
0
        public void Card_HashCodes_ShouldBe_Equal_Fails()
        {
            var card1 = new Card_GetHashCodeThrowsException(CardValue.Ace, CardSuit.Diamond);
            var card2 = new Card_GetHashCodeThrowsException(CardValue.Ace, CardSuit.Diamond);

            Assert.Equal(card1.GetHashCode(), card2.GetHashCode()); //ArgumentException
        }
コード例 #2
0
        public void CardEquality()
        {
            var card1 = new Card_GetHashCodeThrowsException(CardValue.Two, CardSuit.Club);
            var card2 = new Card_GetHashCodeThrowsException(CardValue.Two, CardSuit.Club);

            Assert.Equal(card1, card2);
        }
コード例 #3
0
        public void HashTable_Key_MustBe_Unique_Fails()
        {
            var card1 = new Card_GetHashCodeThrowsException(CardValue.Two, CardSuit.Club);
            var card2 = new Card_GetHashCodeThrowsException(CardValue.Two, CardSuit.Club);

            //we can't add to a hashtable, because GetHashCode() throws NotImplementedException
            var hash = new Hashtable();

            hash.Add(card1, "");                                          //fails: throws NotImplementedException
            Assert.Throws <ArgumentException>(() => hash.Add(card2, "")); //fails: throws NotImplementedException
        }
コード例 #4
0
        public void HashTable_ContainsKey_ShouldBe_True_For_Like_Values_Fails()
        {
            var card1 = new Card_GetHashCodeThrowsException(CardValue.Two, CardSuit.Club);
            var card2 = new Card_GetHashCodeThrowsException(CardValue.Two, CardSuit.Club);

            //we can't add to a hashtable, because GetHashCode() throws NotImplementedException
            var hash = new Hashtable();

            hash.Add(card1, "");                  //fails: throws NotImplementedException

            Assert.True(hash.ContainsKey(card1)); //fails: false
            Assert.True(hash.ContainsKey(card2)); //fails: false
        }
コード例 #5
0
        public void Card_Dictionary_ShouldNotContain_DuplicateKeys()
        {
            var card1 = new Card_GetHashCodeThrowsException(CardValue.Ace, CardSuit.Diamond);
            var card2 = new Card_GetHashCodeThrowsException(CardValue.Ace, CardSuit.Diamond);

            var dictionary = new Dictionary <Card_GetHashCodeThrowsException, string>();

            dictionary.Add(card1, "");
            Assert.True(dictionary.ContainsKey(card1));

            Assert.Throws <ArgumentException>(() =>
                                              dictionary.Add(card2, "")
                                              );

            Assert.Single(dictionary);
        }