示例#1
0
    public void PickedPrimeNumbersAreAsExpected()
    {
        var sut          = new PrimeNumberGenerator();
        var primeNumbers = sut.Generate(15).ToList();

        Assert.AreEqual(47, primeNumbers[14]);
        var otherPrimeNumbers = sut.Generate(155).ToList();

        Assert.AreEqual(907, otherPrimeNumbers[154]);
    }
示例#2
0
    public void PrimeNumbersAreReturnedInSameSequence()
    {
        var sut               = new PrimeNumberGenerator();
        var primeNumbers      = sut.Generate(1155).ToList();
        var otherPrimeNumbers = sut.Generate(1515).ToList();

        for (var i = 0; i < primeNumbers.Count; i++)
        {
            Assert.AreEqual(primeNumbers[i], otherPrimeNumbers[i]);
        }
    }
示例#3
0
        public static void Main(string[] args)
        {
            var inputValidation = new InputValidation();

            if (inputValidation.ValidateInputParameters(args))
            {
                IPrimeNumberGenerator primeNumGenerator = new PrimeNumberGenerator();

                var primeNumbers = primeNumGenerator.Generate(inputValidation.StartValue, inputValidation.EndValue);

                if (primeNumbers == null || !primeNumbers.Any())
                {
                    Console.WriteLine($"No prime numbers exist in specified range [{inputValidation.StartValue}, {inputValidation.EndValue}]");
                    return;
                }

                Console.WriteLine($"Prime numbers in specified range [{inputValidation.StartValue}, {inputValidation.EndValue}] (in ascending order):");

                foreach (var prime in primeNumbers)
                {
                    Console.Write($"{prime} ");
                }

                Console.WriteLine();
            }
        }
示例#4
0
    public void CanGenerateFirstPrimeNumbers()
    {
        var sut                  = new PrimeNumberGenerator();
        var primeNumbers         = sut.Generate(5).ToList();
        var expectedPrimeNumbers = new[] { 2, 3, 5, 7, 11 };

        Assert.AreEqual(expectedPrimeNumbers.Length, primeNumbers.Count);
        for (var i = 0; i < primeNumbers.Count; i++)
        {
            Assert.AreEqual(expectedPrimeNumbers[i], primeNumbers[i]);
        }
    }
        public void ShouldGenerateFirst10PrimeNumbers()
        {
            var expected = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
            var target = new PrimeNumberGenerator();

            var actual = target.Generate().Take(10).ToArray();

            Assert.Equal(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], actual[i]);
            }
        }
        public void ShouldGenerateFirst10PrimeNumbers()
        {
            var expected = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
            var target   = new PrimeNumberGenerator();

            var actual = target.Generate().Take(10).ToArray();

            Assert.Equal(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], actual[i]);
            }
        }