Beispiel #1
0
        public void FindNextPrime_BigNum()
        {
            string semiPrime = new string(SEMI_PRIME.ToCharArray()
                                          .Where(c => !char.IsWhiteSpace(c))
                                          .ToArray());

            var result = primeService.FindNextPrime(BigInteger.Parse(semiPrime));

            Assert.AreEqual(true, result.Succeeded, $"Error: {result.Error}");
            Assert.AreEqual(true, result.Value.Accuracy < 1.0, "Accuracy shouldn't be 100%.");
        }
Beispiel #2
0
        public void IsPrime_BigCompositeNum()
        {
            string semiPrime = new string(SEMI_PRIME.ToCharArray()
                                          .Where(c => !char.IsWhiteSpace(c))
                                          .ToArray());

            var result = primeService.IsPrime(BigInteger.Parse(semiPrime));

            // is operation successful
            Assert.AreEqual(true, result.Succeeded, $"Error: {result.Error}");

            // if Miller-Rabin primality test managed to determine this is not a prime,
            // the accuracy should be 100%.
            if (!result.Value.IsPrime)
            {
                Assert.AreEqual(1.0, result.Value.Accuracy, "Should have 100% accuracy.");
            }
        }