Ejemplo n.º 1
0
        public void AnErrorIsThrownIfAPlayerHasAVisitWhoIsNotInTheLeg()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            var visit = new Visit(player, 100);

            var newScore = leg.Visit(visit);
        }
Ejemplo n.º 2
0
        public void APlayerCanHaveAVisitAndSeeTheirScoreChange()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);
            var visit = new Visit(player, 100);

            var newScore = leg.Visit(visit);

            Assert.AreEqual(401, newScore);
        }
Ejemplo n.º 3
0
        public void AnErrorIsThronWhenAPlayerReaches0WithAnImpossibleCheckout()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);
            var visit = new Visit(player, 100);
            var checkoutVisit = new Visit(player, 101);

            leg.Visit(new Visit(player, 100));//401
            leg.Visit(new Visit(player, 100));//301
            leg.Visit(new Visit(player, 100));//201
            leg.Visit(new Visit(player, 39));//162
            leg.Visit(new Visit(player, 162));
        }
Ejemplo n.º 4
0
        public void APlayersScoreCanReachExacly0()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);
            var visit = new Visit(player, 100);
            var checkoutVisit = new Visit(player, 101);

            leg.Visit(visit);//401
            leg.Visit(visit);//301
            leg.Visit(visit);//201
            leg.Visit(visit);//101
            var score = leg.Visit(checkoutVisit);//1 = bust, therefore 101

            Assert.AreEqual(0, leg.Players[0].Score);
        }
Ejemplo n.º 5
0
        public int Visit(Visit visit)
        {
            var player = Players.Where(p => p.Name.Equals(visit.Player.Name)).FirstOrDefault();

            if (player == null)
                throw new Exception("Player is not in the leg.");

            var newScore = player.Score - visit.Score;

            if (newScore < 2 && newScore != 0)
                newScore = player.Score;

            if (newScore == 0)
                ValidateCheckout(player.Score);

            return player.Score = newScore;
        }
Ejemplo n.º 6
0
        public void APlayersScoreRemainsTheSameWhenTheirOverallScoreGoBelow2()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);
            var visit = new Visit(player, 100);

            leg.Visit(visit);//401
            leg.Visit(visit);//301
            leg.Visit(visit);//201
            leg.Visit(visit);//101
            var score = leg.Visit(visit);//1 = bust, therefore 101

            Assert.AreEqual(101, leg.Players[0].Score);
        }
Ejemplo n.º 7
0
 public void AnErrorIsThrownWhenAnInvalidScoreIsAddedToAVisit()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, 175);
 }
Ejemplo n.º 8
0
 public void AnErrorIsThrownIfAPlayerHasAScoreLessThan0()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, -1);
 }
Ejemplo n.º 9
0
 public void AnErrorIsThrownIfAPlayerHasAScoreHigherThan180()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, 181);
 }