public void ReturnNumber()
        {
            var buzzGenerator = new FizzBuzzGenerator(new FizzBuzzMultiplesStrategy());
            var actual        = buzzGenerator.Generate(1);

            Assert.AreEqual("1", actual);
        }
        public void ReturnBuzzForNumberThatContain5()
        {
            var buzzGenerator = new FizzBuzzGenerator(new FizzBuzzContainsStrategy());
            var actual        = buzzGenerator.Generate(51);

            Assert.AreEqual("Buzz", actual);
        }
        public void ReturnBuzzForMultipleOf5()
        {
            var buzzGenerator = new FizzBuzzGenerator(new FizzBuzzMultiplesStrategy());
            var actual        = buzzGenerator.Generate(55);

            Assert.AreEqual("Buzz", actual);
        }
Example #4
0
        public void GivenGenerateWhenInvalidNumberThenHandleException()
        {
            Action action = () => FizzBuzzGenerator.Generate("x", this.logger.Object);

            action.Should().ThrowExactly <InvalidOperationException>().WithMessage("Fizz Buzz input 'x' should be a integer");
            this.VerifyLogging("System.InvalidOperationException: Fizz Buzz input 'x' should be a integer", LogLevel.Error);
        }
Example #5
0
        public void GivenGenerateWhenNeitherMultiplesOfThreeOrFiveThenNoFizzAndOrBuzz()
        {
            var result = FizzBuzzGenerator.Generate("1", this.logger.Object);

            result.Should().Be(new KeyValuePair <string, string>("1", string.Empty));
            this.VerifyLogging("Queue Item '1', Item '1' with result of '' has been processed.", LogLevel.Information);
        }
        public void FizzBuzzGenerate_4_Outputs4()
        {
            const string expected = "4";
            var          actual   = FizzBuzzGenerator.Generate(4);

            Assert.Equal(expected, actual);
        }
Example #7
0
        public void GetNumbers_should_support_up_to_max_int()
        {
            var fizzBuzzGenerator = new FizzBuzzGenerator();

            fizzBuzzGenerator.GetNumbers(int.MaxValue - 5, int.MaxValue).Should()
            .StartWith((int.MaxValue - 5).ToString()).And.EndWith(int.MaxValue.ToString());
        }
        public void ShouldReturnInputAsStringWhenGivenNumberIsNeitherDivisibleBy3or5(int input)
        {
            string actual   = FizzBuzzGenerator.Generate(input);
            string expected = input.ToString();

            Assert.AreEqual(expected, actual);
        }
Example #9
0
        public void GetNumbers_should_support_negative_numbers()
        {
            var fizzBuzzGenerator = new FizzBuzzGenerator();

            fizzBuzzGenerator.GetNumbers(-3, -1).Should()
            .StartWith("fizz").And.EndWith("-1");
        }
        public void ShouldReturnStringFizzBuzzWhenGivenNumberIsDivisibleBy3And5(int input)
        {
            string actual   = FizzBuzzGenerator.Generate(input);
            string expected = "FizzBuzz";

            Assert.AreEqual(expected, actual);
        }
        public void FizzBuzzGenerate_1_Outputs1()
        {
            const string expected = "1";
            var          actual   = FizzBuzzGenerator.Generate(1);

            Assert.Equal(expected, actual);
        }
        public void FizzBuzzGenerate_30_OutputsFizzBuzz()
        {
            const string expected = "FizzBuzz";
            var          actual   = FizzBuzzGenerator.Generate(30);

            Assert.Equal(expected, actual);
        }
        public void FizzBuzzGenerate_7_Outputs7()
        {
            const string expected = "7";
            var          actual   = FizzBuzzGenerator.Generate(7);

            Assert.Equal(expected, actual);
        }
        public void FizzBuzzGenerate_2_Outputs2()
        {
            const string expected = "2";
            var          actual   = FizzBuzzGenerator.Generate(2);

            Assert.Equal(expected, actual);
        }
Example #15
0
        public void GivenGenerateWhenMultiplesOfThreeAndFiveThenFizzBuzz()
        {
            var result = FizzBuzzGenerator.Generate("15", this.logger.Object);

            result.Should().Be(new KeyValuePair <string, string>("15", "FizzBuzz"));
            this.VerifyLogging("Queue Item '15', Item '15' with result of 'FizzBuzz' has been processed.", LogLevel.Information);
        }
        public void ShouldReturnNumber()
        {
            var input = 8;

            var output = FizzBuzzGenerator.GenerateElement(input);

            Assert.AreEqual("8", output.ToList()[0]);
        }
Example #17
0
        public void GetNumbers_should_throw_when_reversed()
        {
            var fizzBuzzGenerator = new FizzBuzzGenerator();

            Action act = () => fizzBuzzGenerator.GetNumbers(57, 54).ToArray();

            act.ShouldThrow <ArgumentOutOfRangeException>();
        }
        public void ShouldReturnFizzBuzz()
        {
            var input = 15;

            var output = FizzBuzzGenerator.GenerateElement(input);

            Assert.AreEqual("FizzBuzz", output.ToList()[0]);
        }
Example #19
0
        public void FirstFizz()
        {
            var result = new FizzBuzzGenerator().Apply(Enumerable.Range(1, 100)).ToList();

            Assert.AreEqual("1", result[0]);
            Assert.AreEqual("2", result[1]);
            Assert.AreEqual("Fizz", result[2]);
        }
Example #20
0
        private static void RunLegacyGenerator()
        {
            var fizzBuzzer = new FizzBuzzGenerator();

            foreach (var value in fizzBuzzer.GetNumbers(1, Int32.MaxValue))
            {
                Console.WriteLine(value);
            }
        }
Example #21
0
        static void Main(string[] args)
        {
            Console.WriteLine(FizzBuzzGenerator.PrintableRange(1, 100));

            Console.WriteLine("fizz: {0}", FizzBuzzGenerator.FizzWordsCount);
            Console.WriteLine("buzz: {0}", FizzBuzzGenerator.BuzzWordsCount);
            Console.WriteLine("fizzbuzz: {0}", FizzBuzzGenerator.FizzBuzzWordsCount);
            Console.WriteLine("lucky: {0}", FizzBuzzGenerator.LuckyWordsCount);
            Console.WriteLine("integer: {0}", FizzBuzzGenerator.NumberCount);
        }
        public void ShouldRaiseErrorWhenNumberIsNegative()
        {
            // Arrange
            int input = -100;

            // Act
            Action act = () => FizzBuzzGenerator.Generate(input);

            // Assert
            Assert.Throws <ArgumentException>(act);
        }
Example #23
0
        public void FizzBuzz_Fifteen_Returns_Correct_Sequence()
        {
            var fizzBuzz = new FizzBuzzGenerator();

            var correctSequence = new List <string> {
                "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"
            };

            Assert.That(fizzBuzz.FizzBuzz(15), Is.EqualTo(correctSequence), "Expected FizzBuzz ( 15 ) to be"
                        + " {\"1\", \"2\", \"Fizz\", \"4\" ,\"Buzz\", \"Fizz\", \"7\", \"8\", \"Fizz\", \"Buzz\", \"11\", \"Fizz\", \"13\", \"14\", \"FizzBuzz\"}");
        }
Example #24
0
        public void More()
        {
            var result = new FizzBuzzGenerator().Apply(Enumerable.Range(1, 100)).ToList();

            Assert.AreEqual("1", result[0]);
            Assert.AreEqual("2", result[1]);
            Assert.AreEqual("Fizz", result[2]);
            Assert.AreEqual("4", result[3]);
            Assert.AreEqual("Buzz", result[4]);
            Assert.AreEqual("Fizz", result[5]);
            Assert.AreEqual("FizzBuzz", result[14]);
        }
        public void Generate_NoMatch_ReturnsNumber()
        {
            // arrange
            var max       = 1;
            var processor = new FizzBuzzGenerator();

            // act
            var results = processor.Generate(max);

            // assert
            Assert.AreEqual($"1", results.First());
        }
        public void FizzBuzzGeneratorShouldPrintValues100Times()
        {
            // Arrange
            _console = MockRepository.GenerateMock <IConsole>();
            var generator = new FizzBuzzGenerator(_console);

            _console.Expect(x => x.Print(Arg <string> .Is.Anything)).Repeat.Times(100);

            // Act
            generator.Start();

            // Assert
            _console.VerifyAllExpectations();
        }
        public void FizzBuzzGeneratorShouldPrintFizzBuzzForMultiplesOfThreeAndFive()
        {
            // Arrange
            _console = MockRepository.GenerateMock <IConsole>();
            var generator = new FizzBuzzGenerator(_console);

            _console.Expect(x => x.Print(Arg <string> .Matches(Is.Equal("FizzBuzz")))).Repeat.AtLeastOnce();

            // Act
            generator.Start();

            // Assert
            _console.VerifyAllExpectations();
        }
        public void FizzBuzz()
        {
            var fizzBuzzGenerator = new FizzBuzzGenerator();

            Assert.Equal("1", fizzBuzzGenerator.FizzBuzz(1));
            Assert.Equal("2", fizzBuzzGenerator.FizzBuzz(2));
            Assert.Equal("Fizz", fizzBuzzGenerator.FizzBuzz(3));
            Assert.Equal("Buzz", fizzBuzzGenerator.FizzBuzz(5));
            Assert.Equal("Fizz", fizzBuzzGenerator.FizzBuzz(6));
            Assert.Equal("Fizz", fizzBuzzGenerator.FizzBuzz(9));
            Assert.Equal("Buzz", fizzBuzzGenerator.FizzBuzz(10));
            Assert.Equal("FizzBuzz", fizzBuzzGenerator.FizzBuzz(15));
            Assert.Equal("FizzBuzz", fizzBuzzGenerator.FizzBuzz(30));
        }
        public void PrintingSpecifications()
        {
            var outputWriter = default(OutputWriterStub);
            var sut = default(FizzBuzzGenerator);

            "given a fizzbuzz generator"
                .Context(() =>
                {
                    outputWriter = new OutputWriterStub();
                    sut = new FizzBuzzGenerator(outputWriter);
                });

            "when generating numbers one to one hundred"
                .Do(() =>
                    sut.Generate());

            "then the first item generated is the number 1"
                .Assert(() =>
                    Assert.Equal("1", outputWriter.Output[0]));

            "then the second item generated is the number 2"
                .Assert(() =>
                    Assert.Equal("2", outputWriter.Output[1]));

            "then the third item generated is the word 'Fizz'"
                .Assert(() =>
                    Assert.Equal("Fizz", outputWriter.Output[2]));

            "then the fourth item generated is the number 4"
                .Assert(() =>
                    Assert.Equal("4", outputWriter.Output[3]));

            "then the fifth item generated is the word 'Buzz'"
                .Assert(() =>
                    Assert.Equal("Buzz", outputWriter.Output[4]));

            "then the fifteen item generated is the word 'FizzBuzz'"
                .Assert(() =>
                    Assert.Equal("FizzBuzz", outputWriter.Output[14]));

            "then the thirieth item generated is the word 'FizzBuzz'"
                .Assert(() =>
                    Assert.Equal("FizzBuzz", outputWriter.Output[29]));
        }
        public void PrintingSpecifications()
        {
            var outputWriter = default(OutputWriterStub);
            var sut          = default(FizzBuzzGenerator);

            "given a fizzbuzz generator"
            .Context(() =>
            {
                outputWriter = new OutputWriterStub();
                sut          = new FizzBuzzGenerator(outputWriter);
            });

            "when generating numbers one to one hundred"
            .Do(() =>
                sut.Generate());

            "then the first item generated is the number 1"
            .Assert(() =>
                    Assert.Equal("1", outputWriter.Output[0]));

            "then the second item generated is the number 2"
            .Assert(() =>
                    Assert.Equal("2", outputWriter.Output[1]));

            "then the third item generated is the word 'Fizz'"
            .Assert(() =>
                    Assert.Equal("Fizz", outputWriter.Output[2]));

            "then the fourth item generated is the number 4"
            .Assert(() =>
                    Assert.Equal("4", outputWriter.Output[3]));

            "then the fifth item generated is the word 'Buzz'"
            .Assert(() =>
                    Assert.Equal("Buzz", outputWriter.Output[4]));

            "then the fifteen item generated is the word 'FizzBuzz'"
            .Assert(() =>
                    Assert.Equal("FizzBuzz", outputWriter.Output[14]));

            "then the thirieth item generated is the word 'FizzBuzz'"
            .Assert(() =>
                    Assert.Equal("FizzBuzz", outputWriter.Output[29]));
        }
Example #31
0
        // Divisible by 3 print fizz
        // Divisible by 5 print buzz
        // neither see the number
        // allow pass in number pairs, ie 8 -> hamburger
        // as many pairs as they want.
        // fully unit test the project
        // extra credit- Setup build script, Git Repo in a fashion to work in a continuous integration manor.
        // upload to github and send to rayne

        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to FizzBuzzGenerator CLI.");
            Console.WriteLine("Please enter the max number of iterations:");

            try
            {
                var max           = int.Parse(Console.ReadLine());
                var fizzProcessor = new FizzBuzzGenerator();
                var output        = fizzProcessor.Generate(max);
                foreach (var item in output)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            catch (Exception)
            {
                Console.WriteLine("Exception occurred. Could not parse input. Exiting...");
            }
        }