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()); }
public Visit(Player player, int score) { ValidateScore(score); Player = player; Score = score; }
public void ICannotAdd2PlayersToAMatchWithTheSameName() { var match = new Match(7, 501); var player = new Player("Andy"); match.AddPlayer(player); match.AddPlayer(player); }
public void AnErrorIsThrownIfAPlayerHasAVisitWhoIsNotInTheLeg() { var leg = new Leg(501); var player = new Player("Andy"); var visit = new Visit(player, 100); var newScore = leg.Visit(visit); }
public void ErrorIsThrownWhenTheMatchEnds() { var match = new Match(2, 501); var player = new Player("Andy"); match.StartNewLeg(); match.StartNewLeg(); match.StartNewLeg(); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); }
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); }
public void AnErrorIsThrownWhenAnInvalidScoreIsAddedToAVisit() { var player = new Player("Andy"); var visit = new Visit(player, 175); }
public bool HasPlayerWon(Player player) { if (player.Score == 0) return true; return false; }
public void AnErrorIsThrownIfAPlayerHasAScoreLessThan0() { var player = new Player("Andy"); var visit = new Visit(player, -1); }
public int AddLegWonToPlayer(Player player) { var playerEntry = Players.Where(p => p.Key.Name == player.Name).FirstOrDefault(); return playerEntry.Value.Value += 1; }
public void ICannotAddAPlayerToALegWithoutAName() { var leg = new Leg(501); var player = new Player(null); leg.AddPlayer(player); }
public void AnErrorIsThrownIfAPlayerHasAScoreHigherThan180() { var player = new Player("Andy"); var visit = new Visit(player, 181); }
public void ICannotAddAPlayerToALegWithANameLongerThan10Characters() { var leg = new Leg(501); var player = new Player("12345678910"); leg.AddPlayer(player); }
public void ICannotAddAPlayerToALegWithANameAsEmptyString() { var leg = new Leg(501); var player = new Player(""); leg.AddPlayer(player); }
public void ICannotAdd2PlayersToALegWithTheSameName() { var leg = new Leg(501); var player = new Player("Andy"); leg.AddPlayer(player); leg.AddPlayer(player); }
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); }
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); }