Esempio n. 1
0
        static void RunPrimeTest(IPrimeSource prime)
        {
            BigInteger p = 0;

            for (int c = 0; c < 1000; c++)
            {
                p = prime.NextPrime(p);
                int check = FirstPrimes.List[c];
                Assert.AreEqual(p, check);
            }
        }
Esempio n. 2
0
        static void DoGen()
        {
            IPrimeSource gen = null;

            switch (Options.WhichGen)
            {
            case GenType.Division:
                gen = new Methods.TrialDivision();
                break;

            case GenType.Pascal:
                gen = new Methods.PascalRow();
                break;

            case GenType.Fermat:
                gen = new Methods.FermatLittle();
                break;
            }

            TextWriter tw = null;

            try {
                if (Options.OutputFile != null)
                {
                    var fs = File.Open(Options.OutputFile, FileMode.Create, FileAccess.Write, FileShare.Read);
                    tw = new StreamWriter(fs);
                }
                else
                {
                    tw = Console.Out;
                }

                BigInteger p = Options.Start - 1;
                Log.Debug("s = " + p);
                while (p <= Options.End)
                {
                    p = gen.NextPrime(p);
                    tw.WriteLine(p);
                }
            }
            finally {
                if (Options.OutputFile != null && tw != null)
                {
                    tw.Dispose();
                }
            }
        }