Esempio n. 1
0
        public void AddPlayer(Player player)
        {
            if (Players.Where(p => p.Key.Name == player.Name).Count() > 0)
                throw new Exception("Duplicate player added to match.");

            Players.Add(player, new LegsWon());
        }
Esempio n. 2
0
        public Visit(Player player, int score)
        {
            ValidateScore(score);

            Player = player;
            Score = score;
        }
Esempio n. 3
0
 public void ICannotAdd2PlayersToAMatchWithTheSameName()
 {
     var match = new Match(7, 501);
     var player = new Player("Andy");
     match.AddPlayer(player);
     match.AddPlayer(player);
 }
Esempio n. 4
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);
        }
Esempio n. 5
0
 public void ErrorIsThrownWhenTheMatchEnds()
 {
     var match = new Match(2, 501);
     var player = new Player("Andy");
     match.StartNewLeg();
     match.StartNewLeg();
     match.StartNewLeg();
 }
Esempio n. 6
0
        public void ICanAddAPlayerToAMatch()
        {
            var match = new Match(7, 501);
            var player = new Player("Andy");
            match.AddPlayer(player);

            Assert.AreEqual(1, match.Players.Count);
            Assert.AreEqual("Andy", match.Players.FirstOrDefault().Key.Name);
        }
Esempio n. 7
0
        public void ICanAddALegWonToAPlayer()
        {
            var match = new Match(7, 501);
            var player = new Player("Andy");
            match.AddPlayer(player);

            var numberOfLegsWon = match.AddLegWonToPlayer(player);

            Assert.AreEqual(1, numberOfLegsWon);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public void AddPlayer(Player player)
        {
            if (player.Name == null || player.Name == string.Empty)
                throw new Exception("A player must have a name.");
            if (player.Name.Count() > 10)
                throw new Exception("A players name cannot exceep 10 characters");
            if (Players.Where(p => p.Name == player.Name).Count() > 0)
                throw new Exception("Duplicate player added to leg.");

            player.Score = StartScore;
            Players.Add(player);
        }
Esempio n. 10
0
        public void ICanStartANewLeg()
        {
            var match = new Match(7, 501);
            var player = new Player("Andy");
            match.AddPlayer(player);
            var player2 = new Player("Arthur");
            match.AddPlayer(player2);

            var leg = match.StartNewLeg();

            Assert.AreEqual(2, leg.Players.Count);
            Assert.AreEqual(501, leg.StartScore);
        }
Esempio n. 11
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));
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
 public void AnErrorIsThrownWhenAnInvalidScoreIsAddedToAVisit()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, 175);
 }
Esempio n. 15
0
 public bool HasPlayerWon(Player player)
 {
     if (player.Score == 0)
         return true;
     return false;
 }
Esempio n. 16
0
 public void AnErrorIsThrownIfAPlayerHasAScoreLessThan0()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, -1);
 }
Esempio n. 17
0
        public int AddLegWonToPlayer(Player player)
        {
            var playerEntry = Players.Where(p => p.Key.Name == player.Name).FirstOrDefault();

            return playerEntry.Value.Value += 1;
        }
Esempio n. 18
0
        public void ICannotAddAPlayerToALegWithoutAName()
        {
            var leg = new Leg(501);
            var player = new Player(null);

            leg.AddPlayer(player);
        }
Esempio n. 19
0
 public void AnErrorIsThrownIfAPlayerHasAScoreHigherThan180()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, 181);
 }
Esempio n. 20
0
        public void ICannotAddAPlayerToALegWithANameLongerThan10Characters()
        {
            var leg = new Leg(501);
            var player = new Player("12345678910");

            leg.AddPlayer(player);
        }
Esempio n. 21
0
        public void ICannotAddAPlayerToALegWithANameAsEmptyString()
        {
            var leg = new Leg(501);
            var player = new Player("");

            leg.AddPlayer(player);
        }
Esempio n. 22
0
        public void ICannotAdd2PlayersToALegWithTheSameName()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");

            leg.AddPlayer(player);
            leg.AddPlayer(player);
        }
Esempio n. 23
0
        public void ICanAddAPlayerToALeg()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");

            leg.AddPlayer(player);

            Assert.AreEqual(1, leg.Players.Count);
            Assert.AreEqual("Andy", leg.Players[0].Name);
            Assert.AreEqual(501, leg.Players[0].Score);
        }
Esempio n. 24
0
        public void ICanCheckIfTheLegHasBeenWonWhenPlayerHasWon()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);

            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, 100));//101
            leg.Visit(new Visit(player, 101));//0

            var hasWon = leg.HasPlayerWon(player);

            Assert.IsTrue(hasWon);
        }