public void DiceCalculator_Threes_2ReturnsValidAndScoreOf6() { //arrange var rules = new List <Func <byte[], bool> >(); Func <byte[], int> scoreFormula; byte valueToCheck = 3; byte minimumCount = 1; scoreFormula = DiceScoringFormulas.DiceSumOfSpecificNumber(valueToCheck); rules.Add(DiceValidations.DiceMustHaveCount(5)); rules.Add(DiceValidations.DiceMustHaveValues1To6()); rules.Add(DiceValidations.DiceMustContain(valueToCheck)); rules.Add(DiceValidations.DiceMustHaveCountOfACertainValue(valueToCheck, minimumCount)); var calculator = new DiceCalculator(rules, scoreFormula, "Threes", "The sum of the dice with the number 3"); //act var results = calculator.Calculate(GetDiceByteArray(1, 3, 2, 4, 3)); //assert) Assert.IsTrue(results.IsValid && results.Score == 6); }
public void DiceCalculator_Aces_ReturnsSumOf1s(byte valueToCheck, byte[] bytes, int expected) { //arrange var rules = new List <Func <byte[], bool> >(); var scoreFormula = DiceScoringFormulas.DiceSumOfSpecificNumber(valueToCheck); rules.Add(DiceValidations.DiceAlwaysValid()); var calculator = new DiceCalculator(rules, scoreFormula, "Aces", "The sum of the dice with the number 1"); //act var results = calculator.Calculate(bytes); //assert) Assert.IsTrue(results.IsValid, "Results should have been valid."); Assert.IsTrue(results.Score == expected, $"Score was expected to be {expected} but was {results.Score} instead."); }
private List <DiceCalculator> Setup() { var result = new List <DiceCalculator>(); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceAlwaysValid() }, DiceScoringFormulas.DiceSumOfSpecificNumber(1), "Aces", "The sum of the dice with the number 1")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceAlwaysValid() }, DiceScoringFormulas.DiceSumOfSpecificNumber(2), "Twos", "The sum of the dice with the number 2")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceAlwaysValid() }, DiceScoringFormulas.DiceSumOfSpecificNumber(3), "Threes", "The sum of the dice with the number 3")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceAlwaysValid() }, DiceScoringFormulas.DiceSumOfSpecificNumber(4), "Fours", "The sum of the dice with the number 4")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceAlwaysValid() }, DiceScoringFormulas.DiceSumOfSpecificNumber(5), "Fives", "The sum of the dice with the number 5")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceAlwaysValid() }, DiceScoringFormulas.DiceSumOfSpecificNumber(6), "Sixes", "The sum of the dice with the number 6")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceIsXofAKind(3) }, DiceScoringFormulas.DiceSumAllIfValid(DiceValidations.DiceIsXofAKind(3)), "Three Of A Kind", "Sum of all dice")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceIsXofAKind(4) }, DiceScoringFormulas.DiceSumAllIfValid(DiceValidations.DiceIsXofAKind(4)), "Four Of A Kind", "Sum of all dice")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceIsFullHouse() }, DiceScoringFormulas.DiceReturnSpecificValueIfValid(DiceValidations.DiceIsFullHouse(), 25), "Full House", "25")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceIsSmallStraight() }, DiceScoringFormulas.DiceReturnSpecificValueIfValid(DiceValidations.DiceIsSmallStraight(), 30), "Small Straight", "30")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceIsLargeStraight() }, DiceScoringFormulas.DiceReturnSpecificValueIfValid(DiceValidations.DiceIsLargeStraight(), 40), "Large Straight", "40")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceIsXofAKind(5) }, DiceScoringFormulas.DiceReturnSpecificValueIfValid(DiceValidations.DiceIsXofAKind(5), 50), "Yahtzee", "50")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceAlwaysValid() }, DiceScoringFormulas.DiceSumAll(), "Chance", "Sum of all dice")); result.Add(new DiceCalculator(new List <Func <byte[], bool> >() { DiceValidations.DiceIsXofAKind(5) }, DiceScoringFormulas.DiceBonusYahtzeeIfValid(DiceValidations.DiceIsXofAKind(5)), "Yahtzee Bonus", "100")); return(result); }