public void TestConstructorWithBadNumberOfCards(int numberOfCards) { // ARRANGE IAxiom axiom = new Axiom(); ICard topCard = new Card(Colour.Blue, Number.Five, axiom); // ACT ArgumentOutOfRangeException argumentOutOfRangeException = null; IRuleScore ruleScore = null; try { ruleScore = new RuleScore( numberOfCards: numberOfCards, topCard: topCard); } catch (ArgumentOutOfRangeException ex) { argumentOutOfRangeException = ex; } // ASSERT if (argumentOutOfRangeException != null) { Console.WriteLine(argumentOutOfRangeException.ToString()); } Assert.IsNotNull(argumentOutOfRangeException, "Expected exception not thrown"); Assert.IsNull(ruleScore, "ruleScore == null"); }
public void TestConstructorWithPositiveNumberOfCardsAndNullTopCard() { // ARRANGE const int numberOfCards = 1; // ACT ArgumentException argumentException = null; IRuleScore ruleScore = null; try { ruleScore = new RuleScore( numberOfCards: numberOfCards, topCard: null); } catch (ArgumentException ex) { argumentException = ex; } // ASSERT if (argumentException != null) { Console.WriteLine(argumentException.ToString()); } Assert.IsNotNull(argumentException, "argumentException != null"); Assert.IsNull(ruleScore, "ruleScore == null"); }
public void TestConstructorWithZeroNumberOfCardsAndNullTopCard() { // ARRANGE IAxiom axiom = new Axiom(); const int numberOfCards = 0; ICard topCard = new Card(Colour.Blue, Number.Five, axiom); // ACT ArgumentException argumentException = null; IRuleScore ruleScore = null; try { ruleScore = new RuleScore( numberOfCards: numberOfCards, topCard: topCard); } catch (ArgumentException ex) { argumentException = ex; } // ASSERT if (argumentException != null) { Console.WriteLine(argumentException.ToString()); } Assert.IsNotNull(argumentException, "argumentException != null"); Assert.IsNull(ruleScore, "ruleScore == null"); }
/// <summary> /// Compare this Rule Score to another. /// </summary> /// <param name="other">Rule Score to compare to.</param> /// <returns>-1 if lower, 1 if higher and 0 if the same.</returns> public int CompareTo(IRuleScore other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } if (this.NumberOfCards > other.NumberOfCards) { return(1); } if (this.NumberOfCards < other.NumberOfCards) { return(-1); } // When the number of cards is zero then then top card will be null. // Hence there is no top card to compare with. if (this.NumberOfCards == 0) { return(0); } return(this.TopCard.CompareTo(other.TopCard)); }
public void TestScore() { // ARRANGE IAxiom axiom = new Axiom(); IList <ICard> cards = new List <ICard> { new Card(Colour.Blue, Number.Five, axiom), new Card(Colour.Red, Number.Four, axiom), new Card(Colour.Green, Number.Four, axiom), new Card(Colour.Blue, Number.Two, axiom), }; IRule orangeRule = new OrangeRule(); IPalette palette = new Palette(cards); // ACT IRuleScore ruleScore = orangeRule.Score(palette); // ASSERT Assert.IsNotNull(ruleScore); Assert.AreEqual(expected: 2, actual: ruleScore.NumberOfCards); Assert.IsNotNull(ruleScore.TopCard); Assert.AreEqual(Colour.Red, ruleScore.TopCard.Colour); Assert.AreEqual(Number.Four, ruleScore.TopCard.Number); }
/// <inheritdoc/> public IList <ICard> ScoringCards(IPalette palette) { IRuleScore ruleScore = this.Score(palette); return(palette.Cards .Where(c => c.Colour == ruleScore.TopCard.Colour) .ToList()); }
/// <inheritdoc /> public IList <ICard> ScoringCards(IPalette palette) { if (palette == null) { throw new ArgumentNullException(nameof(palette)); } IRuleScore ruleScore = this.Score(palette); return(palette.Cards .Where(c => c.Number == ruleScore.TopCard.Number) .ToList()); }
public void TestScoreWithNoEvenCards() { // ARRANGE IAxiom axiom = new Axiom(); IList <ICard> cards = new List <ICard> { new Card(Colour.Blue, Number.Five, axiom), new Card(Colour.Red, Number.Seven, axiom), new Card(Colour.Green, Number.Seven, axiom), }; IRule greenRule = new GreenRule(axiom); IPalette palette = new Palette(cards); // ACT IRuleScore ruleScore = greenRule.Score(palette); // ASSERT Assert.IsNotNull(ruleScore); Assert.AreEqual(expected: 0, actual: ruleScore.NumberOfCards); Assert.IsNull(ruleScore.TopCard); }