public void VerifiesPrimeFactorsAgainstNaiveFactorizer() { var sieveFactorizer = new SieveOfEratosthenesFactorizer(3481); var trialDivisionFactorizer = new TrialDivisionFactorizer(3481); for (int n = 0; n <= 3481; ++n) { CollectionAssert.AreEquivalent( NaivePrimeDeciderProviderFactorizer.GetPrimeFactors(n).ToArray(), sieveFactorizer.GetPrimeFactors(n).ToArray()); CollectionAssert.AreEquivalent( NaivePrimeDeciderProviderFactorizer.GetPrimeFactors(n).ToArray(), trialDivisionFactorizer.GetPrimeFactors(n).ToArray()); } }
public void VerifiesPrimeFactorsAgainstKnownOutput() { var sieveFactorizer = new SieveOfEratosthenesFactorizer(1000); var trialDivisionFactorizer = new TrialDivisionFactorizer(1000); foreach (var numberPrimeFactorsPair in numberPrimeFactorsPairs) { int number = numberPrimeFactorsPair.Item1; int[] primeFactors = numberPrimeFactorsPair.Item2; CollectionAssert.AreEquivalent(primeFactors, sieveFactorizer.GetPrimeFactors(number).ToArray()); CollectionAssert.AreEquivalent(primeFactors, trialDivisionFactorizer.GetPrimeFactors(number).ToArray()); CollectionAssert.AreEquivalent(primeFactors, NaivePrimeDeciderProviderFactorizer.GetPrimeFactors(number).ToArray()); } }
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(); } } }