public void CardEquality() { var card1 = new CardDefaultHashCode(CardValue.Two, CardSuit.Club); var card2 = new CardDefaultHashCode(CardValue.Two, CardSuit.Club); Assert.Equal(card1, card2); }
public void Card_DoesntOverrideGetHashCode_HashCodes_ShouldBe_Equal_Fails() { var card1 = new CardDefaultHashCode(CardValue.Ace, CardSuit.Diamond); var card2 = new CardDefaultHashCode(CardValue.Ace, CardSuit.Diamond); Assert.Equal(card1, card2); //the cards are equal Assert.Equal(card1.GetHashCode(), card2.GetHashCode()); //but the hash codes are not. Fail. }
public void HashTable_Key_MustBe_Unique_Fails() { var card1 = new CardDefaultHashCode(CardValue.Two, CardSuit.Club); var card2 = new CardDefaultHashCode(CardValue.Two, CardSuit.Club); var hash = new Hashtable(); hash.Add(card1, ""); Assert.Throws <ArgumentException>(() => hash.Add(card2, "")); }
public void HashTable_ContainsKey_ShouldBe_True_For_Like_Values_Fails() { var card1 = new CardDefaultHashCode(CardValue.Two, CardSuit.Club); var card2 = new CardDefaultHashCode(CardValue.Two, CardSuit.Club); var hash = new Hashtable(); hash.Add(card1, ""); Assert.True(hash.ContainsKey(card1)); Assert.True(hash.ContainsKey(card2)); }
public void Card_DoesntOverrideGetHashCode_Dictionary_ShouldNotContain_DuplicateKeys_Fails() { var card1 = new CardDefaultHashCode(CardValue.Ace, CardSuit.Diamond); var card2 = new CardDefaultHashCode(CardValue.Ace, CardSuit.Diamond); var dictionary = new Dictionary <object, string>(); dictionary.Add(card1, ""); Assert.True(dictionary.ContainsKey(card1)); Assert.Throws <ArgumentException>(() => dictionary.Add(card2, "") //this should throw an exception ); Assert.Single(dictionary); //there should only be one item in the dictionary, but there are two. }