public static void PrimeNumberFactorizationFails(int p) { // Arrange var factorizer = new TrialDivisionFactorizer(); // Act var success = factorizer.TryFactor(p, out _); // Assert Assert.IsFalse(success); }
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(); } } }
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()); } }
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()); } }
static COMDIV() { _factorizer = new TrialDivisionFactorizer(_limit); }
static TWOSQRS() { _factorizer = new TrialDivisionFactorizer(_oneTrillion); }
static ROOTCIPH() { _factorizer = new TrialDivisionFactorizer(int.MaxValue); }