public void TestRedBlack( ) { Card heart = new Card( Suit.Hearts, 1, true, null ); Card spade = new Card( Suit.Spades, 2, true, null ); Card diamond = new Card( Suit.Diamonds, 5, true, null ); Card club = new Card( Suit.Clubs, 12, true, null ); Assert.AreEqual( heart.IsRed( ), true ); Assert.AreEqual( diamond.IsRed( ), true ); Assert.AreEqual( spade.IsBlack( ), true ); Assert.AreEqual( club.IsBlack( ), true ); Assert.AreEqual( heart.IsOppositeColor( spade ), true ); Assert.AreEqual( heart.IsOppositeColor( club ), true ); Assert.AreEqual( heart.IsOppositeColor( diamond ), false ); Assert.AreEqual( heart.IsOppositeColor( heart ), false ); Assert.AreEqual( spade.IsOppositeColor( heart ), true ); Assert.AreEqual( spade.IsOppositeColor( diamond ), true ); Assert.AreEqual( spade.IsOppositeColor( club ), false ); Assert.AreEqual( spade.IsOppositeColor( spade ), false ); Assert.AreEqual( diamond.IsOppositeColor( spade ), true ); Assert.AreEqual( diamond.IsOppositeColor( club ), true ); Assert.AreEqual( diamond.IsOppositeColor( heart ), false ); Assert.AreEqual( diamond.IsOppositeColor( diamond ), false ); Assert.AreEqual( club.IsOppositeColor( heart ), true ); Assert.AreEqual( club.IsOppositeColor( diamond ), true ); Assert.AreEqual( club.IsOppositeColor( spade ), false ); Assert.AreEqual( club.IsOppositeColor( club ), false ); }
/// <summary> /// Returns true if the color of the current card is the opposite /// color of the other card. Red and black are considered opposite /// colors in this regard. /// </summary> /// <param name="other"></param> /// <returns></returns> public bool IsOppositeColor( Card other ) { return ( this.IsBlack( ) && other.IsRed( ) ) || ( this.IsRed( ) && other.IsBlack( ) ); }