public void willGetACardWithFaceCard() { var validString = "Q-S"; var ExpectedCard = new Spades(Card.QUEEN); var ActualCard = CardBuilder.fromString(validString); Assert.AreEqual(ExpectedCard, ActualCard); }
public Card fromString(string cardString) { var cardStringAsArray = cardString.Split("-".ToCharArray()); if (cardStringAsArray.Length != 2) { throw new CardBuilderException("Invalid card string"); } var faceValue = cardStringAsArray[0]; var suit = cardStringAsArray[1]; var faceValueIntValue = convertValueFromLetterToNumber(faceValue); if (faceValueIntValue > Card.ACE || faceValueIntValue < 2) { throw new CardBuilderException("Invalid face value"); } Card c; switch (suit) { case "D": c = new Diamonds(faceValueIntValue); break; case "H": c = new Hearts(faceValueIntValue); break; case "S": c = new Spades(faceValueIntValue); break; case "C": c = new Clubs(faceValueIntValue); break; default: throw new CardBuilderException("Invalid suit"); } return c; }