/** Runs the unit test. */ public override void RunTests() { Debug.Write ("\nTesting Card Class\n" + CardGame.ConsoleLine ('*') + "Creating test Card object...\n"); Card cardA, cardB; cardA = new Card (); Debug.Assert (cardA.ToString () == "Black Joker", "Error: Default constructor should produce a black" + "joker.\n" + cardA.ToString ()); cardA = new Card (Card.Joker, Card.Hearts); Debug.Assert (cardA.ToString () == "Red Joker", "Error: new Card (Card.Joker, Card.Hearts) " + "should produce a black joker.\n" + cardA.ToString ()); cardA = new Card (Card.Joker, Card.Spades); Debug.Assert (cardA.ToString () == "Black Joker", "Error: new Card (Card.Joker, Card.Spades) " + "should produce a black joker.\n" + cardA.ToString ()); cardA = new Card (Card.Ace, Card.Spades); Debug.Assert (cardA.ToString () == "Ace of Spades", "Error: new Card (Card.Ace, Card.Spades) " + "should produce a black joker.:\n" + cardA.ToString ()); cardA = new Card (5, Card.Spades); Debug.Assert (cardA.ToString () == "5 of Spades", "Error: new Card (5, Card.Spades) " + "should produce a black joker.:\n" + cardA.ToString ()); Debug.Write ("Testing Card.Compare (Card) function...\n" + "Creating some test Card object to compare. \n"); Debug.Write ("Creating some Cards with invalid input and testing Equals (int, int) function.\n"); cardA = new Card (-4, 6); Debug.Assert (cardA.ToString () == "Black Joker", "Error: new Card (-4, 6) didn't create a Black " + "Joker, but created a " + cardA.ToString ()); cardA = new Card (15, -1); Debug.Assert (cardA.ToString () == "King of Clubs", "Error: new Card (15, -1) didn't create a King " + "of Clubs, but created a " + cardA.ToString ()); Debug.Write ("Testing bool Equals (Card other) funciton\n"); cardA = new Card (5, Card.Spades); Debug.Assert (cardA.Equals (5, Card.Spades), "Error: !cardA.Equals(5, Card.Spades) :\ncardA: " + cardA.ToString ()); cardB = new Card (5, Card.Spades); Debug.Assert (cardA.Equals(cardB), "Error: !cardA.Equals(cardB) :\ncardA: " + cardA.ToString () + "\ncardB: " + cardB.ToString ()); Debug.Write ("Done testing the Card class.\n\n"); }
/** Operator compares thisCard to the otherCard and returns true if they are the same. */ public bool Equals(Card other) { //< Always check to see if an object is null before trying to access any of it's data members!!! if ((Object)other == null) return false; Debug.WriteLine ("other.ToString (): " + other.ToString () + "\nother.PipValue: " + other.pipValue + " other.Suit: " + other.suit); return Equals (other.PipValue, other.Suit); }