Beispiel #1
0
        public void CheckPrimaltyProperty()
        {
            var rand = new Random(DateTime.Now.Millisecond);

            for (int i = 0; i < 100; i++)
            {
                var number = rand.Next(-100, 100);

                Assert.IsTrue(PrimeProperty(number) == PrimeNumberService.IsPrime(number));
            }
        }
Beispiel #2
0
        public void ComparePrimalNumbersFromZeroToHundredWithTheFilteredFromTheMethodNumbers()
        {
            //Arrange
            int[]      primalNumbersTo100      = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
            List <int> primalNumbersFromMethod = new List <int>();

            //Act
            for (int i = 0; i < 100; i++)
            {
                if (PrimeNumberService.IsPrime(i))
                {
                    primalNumbersFromMethod.Add(i);
                }
            }

            //Assert
            Assert.IsTrue(primalNumbersTo100.Length == primalNumbersFromMethod.Count);

            for (int i = 0; i < primalNumbersTo100.Length; i++)
            {
                Assert.IsTrue(primalNumbersTo100[i] == primalNumbersFromMethod[i]);
            }
        }
Beispiel #3
0
 public void IsPrimeNumberTest()
 {
     Assert.IsFalse(service.IsPrime(1));
     Assert.IsTrue(service.IsPrime(5));
     Assert.AreEqual(199, service.FindNextPrime(197));
 }