Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Bowling bowl = new Bowling();

            Console.WriteLine("Let's start Bowling!!");
            try
            {
                foreach (var frame in bowl.Frames)
                {
                    for (int i = 0; i < frame.ThrowList.Count; i++)
                    {
                        Console.WriteLine("Enter number of pins knocked down this turn and press Enter");
                        var inputThrow = Console.ReadLine();
                        if (int.TryParse(inputThrow, out int userInput))
                        {
                            if (ValidateInput(userInput))
                            {
                                bowl.Roll(userInput, frame);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Score(bowl);
        }
Ejemplo n.º 2
0
        public void SumTest()
        {
            lancio[0].FirstSet(3);
            lancio[0].SecondSet(4);

            lancio[1].FirstSet(4);
            lancio[1].SecondSet(6);

            lancio[2].FirstSet(4);
            lancio[2].SecondSet(3);

            lancio[3].FirstSet(5);
            lancio[3].SecondSet(4);

            lancio[4].FirstSet(1);
            lancio[4].SecondSet(0);

            lancio[5].FirstSet(0);
            lancio[5].SecondSet(7);

            lancio[6].FirstSet(10);

            lancio[7].FirstSet(4);
            lancio[7].SecondSet(5);

            lancio[8].FirstSet(6);
            lancio[8].SecondSet(3);

            lancio[9].FirstSet(3);
            lancio[9].SecondSet(3);

            IBowling bowling = new Bowling(lancio);

            Assert.That(() => bowling.Score(), Is.EqualTo(88));
        }
Ejemplo n.º 3
0
        public void Single_semi_strike()
        {
            Bowling bowling = new Bowling();

            int score = bowling.CalculeScore("-12/----------------");

            Assert.AreEqual(11, score);
        }
Ejemplo n.º 4
0
        public void Single_scores_should_be_single_added()
        {
            Bowling bowling = new Bowling();

            int score = bowling.CalculeScore("-1-2----------------");

            Assert.AreEqual(3, score);
        }
Ejemplo n.º 5
0
        public void Semi_strike_with_bowls_after()
        {
            Bowling bowling = new Bowling();

            int score = bowling.CalculeScore("--2/1---------------");

            Assert.AreEqual(12, score);
        }
Ejemplo n.º 6
0
        public void All_strikes_12_rolls()
        {
            Bowling bowling = new Bowling();

            int score = bowling.CalculeScore("XXXXXXXXXXXX");

            Assert.AreEqual(300, score);
        }
Ejemplo n.º 7
0
        public void All_single_and_miss_20_rolls()
        {
            Bowling bowling = new Bowling();

            int score = bowling.CalculeScore("9-9-9-9-9-9-9-9-9-9-");

            Assert.AreEqual(90, score);
        }
Ejemplo n.º 8
0
        public void All_fails_should_be_0()
        {
            Bowling bowling = new Bowling();

            int score = bowling.CalculeScore("--------------------");

            Assert.AreEqual(0, score);
        }
Ejemplo n.º 9
0
        public void All_semi_strikes_21_rolls()
        {
            Bowling bowling = new Bowling();

            int score = bowling.CalculeScore("5/5/5/5/5/5/5/5/5/5/5");

            Assert.AreEqual(150, score);
        }
Ejemplo n.º 10
0
        public void return_game_score(string game, int expectedScore)
        {
            var bowling = new Bowling();

            var score = bowling.CalculateScore(game);

            Assert.That(score, Is.EqualTo(expectedScore));
        }
Ejemplo n.º 11
0
        public void ArgumentException()
        {
            IBowling bowling = new Bowling(lancio);

            lancio[0].FirstSet(3);
            lancio[0].SecondSet(-8);

            Assert.That(() => bowling.Score(), Throws.TypeOf <ArgumentException>());
        }
    public void ThrowNormal_NormalScore()
    {
        var b = new Bowling();

        b.Throw(5);
        b.Throw(6);

        Assert.That(b.GetScore(), Is.EqualTo(11));
    }
Ejemplo n.º 13
0
    public void exampleTests()
    {
        Bowling bowling = new Bowling();

        int[] testArray = new int[] { 1, 2, 3 };
        Assert.AreEqual("I I I I\n I I I \n       \n       ", bowling.BowlingPins(testArray));

        testArray = new int[] { 3, 5, 9 };
        Assert.AreEqual("I I   I\n I   I \n  I    \n   I   ", bowling.BowlingPins(testArray));
    }
Ejemplo n.º 14
0
        public void When_Spare_at_the_end_then_it_scores_26()
        {
            Bowling bowling = new Bowling();

            // act.
            int score = bowling.GetScore(new int[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 0, 1, 9, 5 });

            // assert.
            Check.That(score).IsEqualTo(26);
        }
Ejemplo n.º 15
0
        public void When_Srike_at_the_end_then_it_scores_30()
        {
            Bowling bowling = new Bowling();

            // act.
            int score = bowling.GetScore(new int[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 0, 10, 5, 4 });

            // assert.
            Check.That(score).IsEqualTo(30);
        }
Ejemplo n.º 16
0
        public void When_Spare_and_Other_Rolls_Equal_To_1_then_it_scores_29()
        {
            Bowling bowling = new Bowling();

            // act.
            int score = bowling.GetScore(new int[] { 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });

            // assert.
            Check.That(score).IsEqualTo(29);
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            ILancio[] lancio = new ILancio[11];

            for (int i = 0; i < lancio.Length; i++)
            {
                lancio[i] = new Lancio();
            }

            lancio[0].FirstSet(1);
            lancio[0].SecondSet(2);

            lancio[1].FirstSet(10);
            lancio[1].SecondSet(0);

            lancio[2].FirstSet(0);
            lancio[2].SecondSet(10);

            lancio[3].FirstSet(4);
            lancio[3].SecondSet(2);

            lancio[4].FirstSet(0);
            lancio[4].SecondSet(10);

            lancio[5].FirstSet(6);
            lancio[5].SecondSet(2);

            lancio[6].FirstSet(0);
            lancio[6].SecondSet(10);

            lancio[7].FirstSet(6);
            lancio[7].SecondSet(4);

            lancio[8].FirstSet(8);
            lancio[8].SecondSet(2);

            lancio[9].FirstSet(2);
            lancio[9].SecondSet(8);

            lancio[10].FirstSet(8);


            foreach (var b in lancio)
            {
                Console.Write(b.FirstGet() + "/" + b.SecondGet() + " ");
            }

            Console.WriteLine();

            IBowling bowling = new Bowling(lancio);

            Console.WriteLine(bowling.Score());

            Console.ReadLine();
        }
    public void ThrowSpare_SpecialScore()
    {
        var b = new Bowling();

        b.Throw(1);
        b.Throw(11);      // = spare
        b.Throw(5);       // score counts for double?
        b.Throw(3);       // No double score

        Assert.That(b.GetScore(), Is.EqualTo(1 + 11 + (5 * 2) + 3));
    }
Ejemplo n.º 19
0
        public void When_strike_and_all_other_roll_equal_1_then_it_scores_30()
        {
            // arrange.
            Bowling bowling = new Bowling();

            // act.
            int score = bowling.GetScore(new int[] { 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });

            // assert.
            Check.That(score).IsEqualTo(30);
        }
Ejemplo n.º 20
0
        public void When_all_roll_equal_1_then_it_scores_20()
        {
            //arrange
            Bowling bowling = new Bowling();


            //act
            int score = bowling.GetScore(new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });

            //assert
            Check.That(score).IsEqualTo(20);
        }
Ejemplo n.º 21
0
        private void SubmitButton_OnClick(object sender, RoutedEventArgs e)
        {
            var input  = textBox.Text;
            var result = 0;

            var score = Bowling.TryGetBowlingScore(input, ref result);

            textBlock.Text =
                score
                    ? "Score: " + result
                    : "Wrong score!";
        }
Ejemplo n.º 22
0
        public void AddToDirectory_ShouldGetCorrectBoolean()
        {
            //Arrange
            Bowling content    = new Bowling();
            Bowling repository = new Bowling();

            //Act
            bool addResult = repository.AddContentToDirectory(content);

            //Assert
            Assert.IsTrue(addResult);
        }
Ejemplo n.º 23
0
        public void StrikeTest()
        {
            lancio[0].FirstSet(3);
            lancio[0].SecondSet(4);

            lancio[1].FirstSet(10);

            lancio[2].FirstSet(4);
            lancio[2].SecondSet(5);

            IBowling bowling = new Bowling(lancio);

            Assert.That(() => bowling.Score(), Is.EqualTo(35));
        }
Ejemplo n.º 24
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            var input = textBox.Text;
            int score = 0;

            if (Bowling.TryGetBowlingScore(input, ref score))
            {
                textBlock.Text = score.ToString();
            }
            else
            {
                textBlock.Text = "ERROR";
            }
        }
Ejemplo n.º 25
0
        private void BowlingOuting()
        {
            Bowling bowling = new Bowling();

            bowling.TypeOfEvent = "Bowling";
            Console.WriteLine("How many people attended this event?");
            bowling.NumberOfPeople = int.Parse(Console.ReadLine());
            Console.WriteLine("What was the total event cost?");
            bowling.EventCost     = decimal.Parse(Console.ReadLine());
            bowling.CostPerPerson = bowling.EventCost / bowling.NumberOfPeople;
            Console.WriteLine($"This event cost ${bowling.CostPerPerson}");
            Console.WriteLine("When was this event?");
            bowling.DateOfEvent = DateTime.Parse(Console.ReadLine());
            _outing.AddToOutingList(bowling);
        }
Ejemplo n.º 26
0
        public void GetByTitle_ShouldReturnCorrectContent()
        {
            //Arrange
            Bowling repo       = new Bowling();
            Bowling newContent = new Bowling();

            repo.AddContentToDirectory(newContent);
            string title = "";

            //Act
            Bowling searchResult = repo.GetContentByTitle(title);

            //Assert
            Assert.AreEqual(searchResult.NameOfEvent, title);
        }
Ejemplo n.º 27
0
        public void GetDirectory_ShouldReturnCorrectCollection()
        {
            //Arrange
            Bowling content = new Bowling();
            Bowling repo    = new Bowling();

            repo.AddContentToDirectory(content);

            //Act
            List <Bowling> contents = repo.GetContents();

            bool directoryHasContent = contents.Contains(content);

            //Assert
            Assert.IsTrue(directoryHasContent);
        }
Ejemplo n.º 28
0
        public void UpdateExistingContent_ShouldReturnTrue()
        {
            //Arrange
            Bowling repo       = new Bowling();
            Bowling oldContent = new Bowling();

            repo.AddContentToDirectory(oldContent);

            Bowling newContent = new Bowling();

            //Act
            bool updateResult = repo.UpdateExistingContent(oldContent.NameOfEvent, newContent);

            //Assert
            Assert.IsTrue(updateResult);
        }
Ejemplo n.º 29
0
        public void DeleteExistingContent_ShouldReturnTrue()
        {
            //Arrange
            Bowling repo    = new Bowling();
            Bowling content = new Bowling();

            repo.AddContentToDirectory(content);

            //Act
            Bowling oldContent = repo.GetContentByTitle("Bowling");

            bool removeResult = repo.DeleteExistingContent(oldContent);

            //Assert
            Assert.IsNull(removeResult);
        }
 public void SetupGameAt(BowlingFrame frame)
 {
     _game = new Bowling(
         new Game
     {
         Status = "In Progress"
     },
         new PlayerScore
     {
         Frame = frame.Frame,
         Score = frame.StartingScore,
         Ball  = frame.Ball,
         Spare = false,
     },
         0
         );
 }
Ejemplo n.º 31
0
        public void ShouldHandleSpareCorrectly()
        {
            var rounds = new List <(string, string)>()
            {
                ("3", "3"),
                ("4", "4"),
                ("4", Bowling.SPARE),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "3"),
            };
            var bowling = new Bowling();

            var points = bowling.CalculatePoints(rounds);

            points.Should().Be(83);
        }
Ejemplo n.º 32
0
        public void ShouldHandleStrikeCorrectly()
        {
            var rounds = new List <(string, string)>()
            {
                ("3", "3"),
                ("4", "4"),
                (Bowling.STRIKE, string.Empty),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "3"),
            };
            var bowling = new Bowling();

            var points = bowling.CalculatePoints(rounds);

            points.Should().Be(87);
        }
Ejemplo n.º 33
0
        public void ShouldCorrectlySumUpRoundsWithPointInAllShots()
        {
            var rounds = new List <(string, string)>()
            {
                ("3", "3"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "3"),
            };
            var bowling = new Bowling();

            var points = bowling.CalculatePoints(rounds);

            points.Should().Be(77);
        }
Ejemplo n.º 34
0
        public void ShouldCalculateSpareInTenthRound()
        {
            var rounds = new List <(string, string)>()
            {
                ("3", "3"),
                ("4", "4"),
                ("3", Bowling.SPARE),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", "4"),
                ("4", Bowling.SPARE),
                ("4", string.Empty)
            };
            var bowling = new Bowling();

            var points = bowling.CalculatePoints(rounds);

            points.Should().Be(90);
        }
Ejemplo n.º 35
0
        public void AllSparesWithAnExtraFive()
        {
            var rounds = new List <(string, string)>()
            {
                ("5", Bowling.SPARE),
                ("5", Bowling.SPARE),
                ("5", Bowling.SPARE),
                ("5", Bowling.SPARE),
                ("5", Bowling.SPARE),
                ("5", Bowling.SPARE),
                ("5", Bowling.SPARE),
                ("5", Bowling.SPARE),
                ("5", Bowling.SPARE),
                ("5", Bowling.SPARE),
                ("5", string.Empty)
            };
            var bowling = new Bowling();

            var points = bowling.CalculatePoints(rounds);

            points.Should().Be(150);
        }
Ejemplo n.º 36
0
        public void ShouldHandleAllStrikes()
        {
            var rounds = new List <(string, string)>()
            {
                (Bowling.STRIKE, string.Empty),
                (Bowling.STRIKE, string.Empty),
                (Bowling.STRIKE, string.Empty),
                (Bowling.STRIKE, string.Empty),
                (Bowling.STRIKE, string.Empty),
                (Bowling.STRIKE, string.Empty),
                (Bowling.STRIKE, string.Empty),
                (Bowling.STRIKE, string.Empty),
                (Bowling.STRIKE, string.Empty),
                (Bowling.STRIKE, string.Empty),
                ("10", "10")
            };
            var bowling = new Bowling();

            var points = bowling.CalculatePoints(rounds);

            points.Should().Be(300);
        }
Ejemplo n.º 37
0
        static void Main(string[] args)
        {
            var bowling = new Bowling();
            while (!bowling.PartieFinie)
            {
                try
                {
                    Console.WriteLine("Frame: {0}", bowling.Frame + 1);
                    Console.WriteLine("Score: {0}", bowling.Score);
                    Console.WriteLine("Lancer: {0}", bowling.LancerDansLaFrame);
                    Console.WriteLine("Quilles:{0}", bowling.Quilles);

                    Console.Write("Nombre de quilles tombees:");
                    bowling.Lance(int.Parse(Console.ReadLine()));
                    Console.WriteLine();
                }
                catch (FormatException)
                {
                    Console.WriteLine("FormatIncorrect");
                }
            }
            Console.WriteLine("Score Final:{0}", bowling.Score);
        }
Ejemplo n.º 38
0
 public void ApresUnSpareLaPartieEstFinieAuFrame10AvecUnLancerSupplementaire()
 {
     var bowling = new Bowling();
     foreach (var resultat in Enumerable.Repeat(1, 18)) bowling.Lance(resultat);
     bowling.Lance(5);
     bowling.Lance(5);
     Assert.IsFalse(bowling.PartieFinie);
     bowling.Lance(1);
     Assert.IsTrue(bowling.PartieFinie);
 }
Ejemplo n.º 39
0
 public void ApresUnLancerOnAjouteLeNombreDeQuillesTombeesAuScore()
 {
     var bowling = new Bowling();
     var currentScore = bowling.Score;
     bowling.Lance(6);
     Assert.AreEqual(currentScore + 6, bowling.Score);
 }
Ejemplo n.º 40
0
 public void ApresUnStrikePartieEstFinieAuBoutDe2LancersSupplementaires()
 {
     var bowling = new Bowling();
     foreach (var resultat in Enumerable.Repeat(1, 18)) bowling.Lance(resultat);
     bowling.Lance(10);
     bowling.Lance(1);
     Assert.IsFalse(bowling.PartieFinie);
     bowling.Lance(1);
     Assert.IsTrue(bowling.PartieFinie);
 }
Ejemplo n.º 41
0
 public void ApresUnStrikeOnPasseALaFrameSuivante()
 {
     var bowling = new Bowling();
     var currentFrame = bowling.Frame;
     bowling.Lance(10);
     Assert.AreEqual(currentFrame + 1, bowling.Frame);
 }
Ejemplo n.º 42
0
 public void Setup()
 {
     _bowling = new Bowling();
 }
Ejemplo n.º 43
0
 public void SiLeLancerDAvantEstUnStrikeEtCeluiAvantUnStrikeOnCompte3FoisLeLancer()
 {
     var bowling = new Bowling();
     bowling.Lance(10);
     bowling.Lance(10);
     var currentScore = bowling.Score;
     bowling.Lance(6);
     Assert.AreEqual(currentScore + 6 * 3, bowling.Score);
 }
Ejemplo n.º 44
0
 public void Setup()
 {
     _sut = new Bowling(new EventAggregator());
 }
Ejemplo n.º 45
0
 public void ApresPremierLancerOnPeutFaireTomber10moinsXQuilles()
 {
     var bowling = new Bowling();
     bowling.Lance(6);
     Assert.AreEqual(4, bowling.Quilles);
 }
Ejemplo n.º 46
0
 public void LePremierLancerEstUnStrike()
 {
     var bowling = new Bowling();
     bowling.Lance(10);
     Assert.AreEqual(Lancer.Strike, bowling.ResultatLancer);
 }
Ejemplo n.º 47
0
 public void AuPremierLancerOnEstALaFrame0()
 {
     var bowling = new Bowling();
     Assert.AreEqual(0, bowling.Frame);
 }
Ejemplo n.º 48
0
 public void LeSecondLancerEstNormalSIlResteDesQuilles()
 {
     var bowling = new Bowling();
     bowling.Lance(4);
     bowling.Lance(5);
     Assert.AreEqual(Lancer.Normal, bowling.ResultatLancer);
 }
Ejemplo n.º 49
0
 public void PremierLancerPeutFaireTomberAuPlus10Quilles()
 {
     var bowling = new Bowling();
     Assert.AreEqual(10, bowling.Quilles);
 }
Ejemplo n.º 50
0
 public void SiDernierFrameSpareApresUnStrikeOnSArrete()
 {
     var bowling = new Bowling();
     foreach (var resultat in Enumerable.Repeat(1, 18)) bowling.Lance(resultat);
     bowling.Lance(5);
     bowling.Lance(5);
     Assert.IsFalse(bowling.PartieFinie);
     bowling.Lance(10);
     Assert.IsTrue(bowling.PartieFinie);
 }
Ejemplo n.º 51
0
 public void ApresUnLancer0EtUnLancer10OnAUnSpare()
 {
     var bowling = new Bowling();
     bowling.Lance(0);
     bowling.Lance(10);
     Assert.AreEqual(Lancer.Spare, bowling.ResultatLancer);
 }
Ejemplo n.º 52
0
 public void SiLeLancerDAvantEstUnStrikeOnCompte2FoisLeLancer()
 {
     var bowling = new Bowling();
     bowling.Lance(10);
     var currentScore = bowling.Score;
     bowling.Lance(7);
     Assert.AreEqual(currentScore + 7 * 2, bowling.Score);
 }
Ejemplo n.º 53
0
 public FakeGames()
 {
     _game = new Bowling(new EventAggregator());
     _game.AddPlayer("Kamran");
     _game.AddPlayer("Cassie");
 }
Ejemplo n.º 54
0
 public void ALaProchaineFrameOnDoitLancer10Quilles()
 {
     var bowling = new Bowling();
     bowling.Lance(5);
     bowling.Lance(4);
     Assert.AreEqual(10, bowling.Quilles);
 }
Ejemplo n.º 55
0
 public void AuPremierLancerLeScoreEstA0()
 {
     var bowling = new Bowling();
     Assert.AreEqual(0, bowling.Score);
 }
Ejemplo n.º 56
0
 public void SiLes2LancerFontTomber10QuillesLeLancerEstUnSpare()
 {
     var bowling = new Bowling();
     bowling.Lance(6);
     bowling.Lance(4);
     Assert.AreEqual(Lancer.Spare, bowling.ResultatLancer);
 }
Ejemplo n.º 57
0
 public void ApresLaFrame10LaPartieEstFinie()
 {
     var bowling = new Bowling();
     foreach (var resultat in Enumerable.Repeat(1, 19)) bowling.Lance(resultat);
     Assert.IsFalse(bowling.PartieFinie);
     bowling.Lance(1);
     Assert.IsTrue(bowling.PartieFinie);
 }
Ejemplo n.º 58
0
 public void AuDebutLaPartieNEstPasFinie()
 {
     var bowling = new Bowling();
     Assert.IsFalse(bowling.PartieFinie);
 }
Ejemplo n.º 59
0
 public void LePremierLancerNonStrikeEstNormal()
 {
     var bowling = new Bowling();
     bowling.Lance(5);
     Assert.AreEqual(Lancer.Normal, bowling.ResultatLancer);
 }
Ejemplo n.º 60
0
 public void SiLeLancerDAvantEstUnSpareOnCompte2FoisLeLancer()
 {
     var bowling = new Bowling();
     bowling.Lance(4);
     bowling.Lance(6);
     var currentScore = bowling.Score;
     bowling.Lance(3);
     Assert.AreEqual(currentScore + 3 * 2, bowling.Score);
 }