static void Main(string[] args) { int n; int maxThreads; if(!int.TryParse(args[0],out n)) throw new InvalidOperationException("O primeiro argumento deve ser um inteiro válido"); if(!int.TryParse(args[1],out maxThreads)) throw new InvalidOperationException("O segundo argumento deve ser um inteiro válido"); var watch = Stopwatch.StartNew(); ICalculaPrimos algoritmo = new CrivoEratostenesParallel(n, maxThreads); var primos = algoritmo.Calcula(); Console.WriteLine("{0}.", string.Join(", ", primos.ToArray())); Console.WriteLine("Calculado em {0} ms.", watch.ElapsedMilliseconds); Console.WriteLine("Digite qualquer tecla para encerrar."); Console.ReadLine(); }
public void Posso_achar_o_numeros_primos_ate_30_usando_4_threads() { var limite = 30; var maxThreads = 4; ICalculaPrimos crivoEratostenes = new CrivoEratostenesParallel(limite,maxThreads); IList<int> valores = crivoEratostenes.Calcula(); Assert.That(valores.Count, Is.EqualTo(10)); Assert.That(valores.Contains(2)); Assert.That(valores.Contains(3)); Assert.That(valores.Contains(5)); Assert.That(valores.Contains(7)); Assert.That(valores.Contains(11)); Assert.That(valores.Contains(13)); Assert.That(valores.Contains(17)); Assert.That(valores.Contains(19)); Assert.That(valores.Contains(23)); Assert.That(valores.Contains(29)); }