Пример #1
0
        public static void PrimeNumberFactorizationFails(int p)
        {
            // Arrange
            var factorizer = new TrialDivisionFactorizer();

            // Act
            var success = factorizer.TryFactor(p, out _);

            // Assert
            Assert.IsFalse(success);
        }
Пример #2
0
        private void TrialDivisionFactorizer(int limit, int passes, int start, int end)
        {
            var factorizer = new TrialDivisionFactorizer(limit);

            for (int p = 0; p < passes; ++p)
            {
                for (int n = start; n <= end; ++n)
                {
                    factorizer.GetPrimeFactors(n).ToArray();
                }
            }
        }
Пример #3
0
        public void GetDistinctPrimeFactors_AgreesWithNaiveFactorizer()
        {
            var sieveFactorizer         = new SieveOfEratosthenesFactorizer(3481);
            var trialDivisionFactorizer = new TrialDivisionFactorizer(3481);

            for (int n = 0; n <= 3481; ++n)
            {
                CollectionAssert.AreEquivalent(
                    NaivePrimeDeciderProviderFactorizer.GetDistinctPrimeFactors(n).ToArray(),
                    sieveFactorizer.GetDistinctPrimeFactors(n).ToArray());
                CollectionAssert.AreEquivalent(
                    NaivePrimeDeciderProviderFactorizer.GetDistinctPrimeFactors(n).ToArray(),
                    trialDivisionFactorizer.GetDistinctPrimeFactors(n).ToArray());
            }
        }
Пример #4
0
        public void GetDistinctPrimeFactors_AgreesWithKnownOutput()
        {
            var sieveFactorizer         = new SieveOfEratosthenesFactorizer(1000);
            var trialDivisionFactorizer = new TrialDivisionFactorizer(1000);

            foreach (var numberPrimeFactorsPair in _numberPrimeFactorsPairs)
            {
                int   number = numberPrimeFactorsPair.Item1;
                int[] distinctPrimeFactors = numberPrimeFactorsPair.Item2.Distinct().ToArray();

                CollectionAssert.AreEquivalent(distinctPrimeFactors, sieveFactorizer.GetDistinctPrimeFactors(number).ToArray());
                CollectionAssert.AreEquivalent(distinctPrimeFactors, trialDivisionFactorizer.GetDistinctPrimeFactors(number).ToArray());
                CollectionAssert.AreEquivalent(distinctPrimeFactors, NaivePrimeDeciderProviderFactorizer.GetDistinctPrimeFactors(number).ToArray());
            }
        }
Пример #5
0
 static COMDIV()
 {
     _factorizer = new TrialDivisionFactorizer(_limit);
 }
Пример #6
0
 static TWOSQRS()
 {
     _factorizer = new TrialDivisionFactorizer(_oneTrillion);
 }
Пример #7
0
 static TWOSQRS()
 {
     _factorizer = new TrialDivisionFactorizer(_oneTrillion);
 }
Пример #8
0
 static ROOTCIPH()
 {
     _factorizer = new TrialDivisionFactorizer(int.MaxValue);
 }