コード例 #1
0
ファイル: Match.cs プロジェクト: andycornforth/Darts_Scorer
        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());
        }
コード例 #2
0
ファイル: Visit.cs プロジェクト: andycornforth/Darts_Scorer
        public Visit(Player player, int score)
        {
            ValidateScore(score);

            Player = player;
            Score = score;
        }
コード例 #3
0
 public void ICannotAdd2PlayersToAMatchWithTheSameName()
 {
     var match = new Match(7, 501);
     var player = new Player("Andy");
     match.AddPlayer(player);
     match.AddPlayer(player);
 }
コード例 #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);
        }
コード例 #5
0
 public void ErrorIsThrownWhenTheMatchEnds()
 {
     var match = new Match(2, 501);
     var player = new Player("Andy");
     match.StartNewLeg();
     match.StartNewLeg();
     match.StartNewLeg();
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #9
0
ファイル: Leg.cs プロジェクト: andycornforth/Darts_Scorer
        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);
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #14
0
 public void AnErrorIsThrownWhenAnInvalidScoreIsAddedToAVisit()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, 175);
 }
コード例 #15
0
ファイル: Leg.cs プロジェクト: andycornforth/Darts_Scorer
 public bool HasPlayerWon(Player player)
 {
     if (player.Score == 0)
         return true;
     return false;
 }
コード例 #16
0
 public void AnErrorIsThrownIfAPlayerHasAScoreLessThan0()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, -1);
 }
コード例 #17
0
ファイル: Match.cs プロジェクト: andycornforth/Darts_Scorer
        public int AddLegWonToPlayer(Player player)
        {
            var playerEntry = Players.Where(p => p.Key.Name == player.Name).FirstOrDefault();

            return playerEntry.Value.Value += 1;
        }
コード例 #18
0
        public void ICannotAddAPlayerToALegWithoutAName()
        {
            var leg = new Leg(501);
            var player = new Player(null);

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

            leg.AddPlayer(player);
        }
コード例 #21
0
        public void ICannotAddAPlayerToALegWithANameAsEmptyString()
        {
            var leg = new Leg(501);
            var player = new Player("");

            leg.AddPlayer(player);
        }
コード例 #22
0
        public void ICannotAdd2PlayersToALegWithTheSameName()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");

            leg.AddPlayer(player);
            leg.AddPlayer(player);
        }
コード例 #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);
        }
コード例 #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);
        }