Example #1
0
        public void ProductOfAAndBInQuadradicThatGeneratesMostPrimes_IsNegative59231()
        {
            var primeService = new PrimeService();
            var result       = Sequences
                               .NaturalNumbers()
                               .Select(n => n - 1000)
                               .Take(2001)
                               .FullJoin(
                Sequences
                .NaturalNumbers()
                .Select(n => n - 1000)
                .Take(2001),
                (a, b) => (a: a, b: b))
                               .Select(quadratic => (
                                           quadratic: quadratic,
                                           primeCount: Sequences
                                           .NaturalNumbers()
                                           .Select(Operations.QuadraticFunction(quadratic.a, quadratic.b))
                                           .TakeWhile(primeService.IsPrime)
                                           .Count()))
                               .OrderByDescending(quadResult => quadResult.primeCount)
                               .Select(quadResult => quadResult.quadratic.a * quadResult.quadratic.b)
                               .First();

            Assert.AreEqual(-59231, result);
        }
Example #2
0
        public void IsPrime_ValuesLessThan2_ReturnFalse(int value)
        {
            var primeService = new PrimeService();
            var result       = primeService.IsPrime(value);

            Assert.False(result, $"{value} should not be prime");
        }
Example #3
0
        public PrimeService_IsPrimeShould()
        {
            mock.Setup(x => x.IsTrue()).Returns(false);

            _primeService = new PrimeService(mock.Object);
            //_primeService = new PrimeService();
        }
Example #4
0
        public void TestMethod1()
        {
            var  primeService = new PrimeService();
            bool result       = primeService.IsPrime(1);

            Assert.IsFalse(result, "1 should not be prime");
        }
 public void ReturnTruePrimesWithClassDataFromPrimeDataGenerator(params int[] list)
 {
     foreach (int t in list)
     {
         Assert.True(PrimeService.IsPrime(t));
     }
 }
Example #6
0
        public void Test2()
        {
            var  primeService = new PrimeService();
            bool result       = primeService.IsPrime(1);

            Assert.True(result, "1 should not be prime");
        }
Example #7
0
        public void Given_LessThanOneArraySize_Then_Return_EmptyArray(int arraySize)
        {
            IPrimeService primeNumbers = new PrimeService();
            var           primeArray   = primeNumbers.GetPrimeNumbers(arraySize);

            Assert.Empty(primeArray);
        }
Example #8
0
            public void IsNotPrimeTest(int value)
            {
                PrimeService primeService = CreatePrimeService();
                var          result       = primeService.IsPrime(value);

                Assert.IsFalse(result, $"{value} is prime");
            }
 public void AllNumbersAreNotPrimeWithMemberDataFromPrimeDataGenerator(params int[] list)
 {
     foreach (int t in list)
     {
         Assert.False(PrimeService.IsPrime(t));
     }
 }
Example #10
0
        public void IsPrime_InputIs1_ReturnFalse()
        {
            var  primeService = new PrimeService();
            bool result       = primeService.IsPrime(1);

            Assert.IsFalse(result);
        }
Example #11
0
        public void IsPrime_InputisNegative1_ReturnFalse()
        {
            var  primeService = new PrimeService();
            bool result       = primeService.IsPrime(-1);

            Assert.False(result, "-1 should not be prime");
        }
Example #12
0
        public void IsPrime_InputIs1_ReturnFalse()
        {
            var  primeService = new PrimeService();
            bool result       = primeService.IsPrime(1);

            Assert.False(result, "1 should not be prime");
        }
Example #13
0
        private void btnCheck_Click(object sender, EventArgs e)
        {
            PrimeService primeService = new PrimeService();

            try
            {
                int num = int.Parse(tbNum.Text);

                if (num < 2 || num > int.MaxValue)
                {
                    throw new Exception();
                }

                var result = primeService.IsPrime(num);

                if (result)
                {
                    lblAns.ForeColor = Color.Green;
                    lblAns.Text      = "Yes";
                }

                else
                {
                    lblAns.ForeColor = Color.Red;
                    lblAns.Text      = "No";
                }
            }

            catch (Exception)
            {
                MessageBox.Show("Write correct data!");
            }
        }
Example #14
0
        static void Main(string[] args)
        {
            int number = 0;

            while (true)
            {
                Console.Write("Enter size of Prime Numbers Multiplication Table: ");
                if (Int32.TryParse(Console.ReadLine(), out number))
                {
                    if (number >= 1)
                    {
                        break;
                    }
                    else
                    {
                        InvalidNumberError();
                    }
                }
                else
                {
                    InvalidNumberError();
                }
            }
            ;
            IPrimeService myPrimeCalculator = new PrimeService();
            IPrint        consoleDisplay    = new ConsolePrint();
            var           primeNumbers      = myPrimeCalculator.GetPrimeNumbers(number).ToArray();
            var           primeArray        = myPrimeCalculator.GetPrimeMultiplcationTable(primeNumbers);

            consoleDisplay.Print(primeArray);
            Console.ReadKey();
        }
        public void TwoIsPrime()
        {
            var primeService = new PrimeService();

            var result = primeService.IsPrime(2);

            Assert.True(result, "2 should be prime");
        }
Example #16
0
        public void Given_ValidArraySize_Then_DoNotReturn_CompositeNumbers(int arraySize)
        {
            IPrimeService primeNumbers = new PrimeService();
            var           primeArray   = primeNumbers.GetPrimeNumbers(arraySize);

            Assert.Equal(arraySize, primeArray.Count);
            Assert.DoesNotContain(4, primeArray);
        }
Example #17
0
        public void Given_ValidArraySize_Then_Return_PrimeNumbers(int arraySize)
        {
            IPrimeService primeNumbers = new PrimeService();
            var           primeArray   = primeNumbers.GetPrimeNumbers(arraySize);

            Assert.Equal(arraySize, primeArray.Count);
            Assert.Contains(2, primeArray);
        }
Example #18
0
        public void IsPrime_CompositeNumber_ReturnsFalse(int number)
        {
            var primeService = new PrimeService();

            var result = primeService.IsPrime(number);

            Assert.False(result);
        }
Example #19
0
        public void IsPrime_PrimeNumber_ReturnsTrue(int number)
        {
            var primeService = new PrimeService();

            var result = primeService.IsPrime(number);

            Assert.True(result);
        }
        public void OneIsNotPrime()
        {
            var primeService = new PrimeService();

            var result = primeService.IsPrime(1);

            Assert.False(result, "1 should not be prime");
        }
Example #21
0
        public void ShouldThrowIfValidatorIsNull()
        {
            var resolver  = new Mock <IPrimeFacilitiesResolver>();
            var logger    = new Mock <ILog>();
            var validator = (IValidator <MethodIdNumberPairContainer>)null;

            var result = new PrimeService(resolver.Object, logger.Object, validator);
        }
Example #22
0
        public void Given_GreaterThanOneInput_Then_Return_CorrectArrayCount()
        {
            var arraySize = 5;

            IPrimeService primeNumbers = new PrimeService();
            var           primeArray   = primeNumbers.GetPrimeNumbers(arraySize);

            Assert.Equal(arraySize, primeArray.Count);
        }
Example #23
0
        public async Task CanGet()
        {
            var primeService = new PrimeService();
            var controller   = new PrimeController(primeService);
            var response     = (OkObjectResult)await controller.Get();

            _output.WriteLine($"{response.Value}");
            response.ShouldNotBeNull();
        }
Example #24
0
        public void NumberOfPrimeRoationsBelow100_Is13()
        {
            var primeService = new PrimeService();
            var result       = Sequences.NumbersBetween(2, 100)
                               .Where(num => num.ToDigitRotations().AllPrime(primeService))
                               .Count();

            Assert.AreEqual(13, result);
        }
Example #25
0
        public void Given_EmptyInputArray_Then_Return_Null()
        {
            int[] array = { };

            IPrimeService primeNumbers = new PrimeService();
            var           primeArray   = primeNumbers.GetPrimeMultiplcationTable(array);

            Assert.Null(primeArray);
        }
Example #26
0
        public void GetPrimeFactors_CompositeNumber_ReturnsCorrectPrimeFactors(int number)
        {
            var primeService       = new PrimeService();
            var primeFactorService = new PrimeFactorService(primeService);

            var result = primeFactorService.GetPrimeFactors(number);

            Assert.Equal(number, result.Aggregate(1, (x, y) => x * y));
            Assert.All(result, x => primeService.IsPrime(x));
        }
Example #27
0
        public void Given_ValidInputArray_Then_Return_CorrectTableMatrixCount()
        {
            int[] array = { 2, 3, 5, 7 };

            IPrimeService primeNumbers = new PrimeService();
            var           primeArray   = primeNumbers.GetPrimeMultiplcationTable(array);

            Assert.Equal(array.Length + 1, primeArray.GetLength(0));
            Assert.Equal(array.Length + 1, primeArray.GetLength(1));
        }
        public void IsPrime_ValuesLessThan2_ReturnFalse(int value)
        {
            // Arrange
            var primeService = new PrimeService();

            // Act
            var result = primeService.IsPrime(value);

            // Assert
            result.Should().BeFalse($"{value} should not be prime");
        }
        public void IsPrime_InputIs3_ReturnTrue()
        {
            // Arrange
            var primeService = new PrimeService();

            // Act
            bool result = primeService.IsPrime(3);

            // Assert
            result.Should().BeTrue();
        }
Example #30
0
        public void RotationsOf197_AreAllPrime()
        {
            var primeService = new PrimeService();
            var result       = new BigInteger(197)
                               .ToDigitRotations();

            var result2 = result
                          .AllPrime(primeService);

            Assert.IsTrue(result2);
        }