public void Prime24IsNotPrime() { // Arrange Prime my_primes = new Prime(); // Act bool actual = my_primes.IsPrime(24); // Assert Assert.IsFalse(actual); }
public void PrimeGetNextLargePrime() { // Arrange Prime my_primes = new Prime(); // Act int actual = my_primes.GetNext(1000000007); int expected = 1000000009; Assert.AreEqual(expected, actual); }
static void Main(string[] args) { const int PrimesCount = 100; List<int> primes; Prime prime = new Prime(PrimesCount); Stopwatch sw = new Stopwatch(); // 同期で呼び出す sw.Reset(); sw.Start(); primes = prime.GetPrimes(); sw.Stop(); Console.WriteLine("同期で呼び出す"); Console.WriteLine($"{nameof(sw.Elapsed)} = {sw.Elapsed}"); Console.WriteLine($"{nameof(primes.Count)} = {primes.Count}"); #if DEBUG Debug.WriteLine(string.Join(" ", primes.GetRange(0, 20))); #endif // 同期で呼び出す sw.Reset(); sw.Start(); // 非同期はこの呼び方でもよいが.... Task<List<int>> task = prime.GetPrimesAsync(); task.Start(); // 利用する側(Programクラス)が非同期で呼び出す方が望ましい //Task<List<int>> task = Task.Run(() => prime.GetPrimes(PrimesCount)); sw.Stop(); // タスクが終了するまで待つ。が... // task.ResultがWaitを兼ねている。 // つまり、Resultを取得できるようになるまで待機する。 //task.Wait(); primes = task.Result; Console.WriteLine("\n非同期で呼び出す"); Console.WriteLine($"{nameof(sw.Elapsed)} = {sw.Elapsed}"); Console.WriteLine($"{nameof(primes.Count)} = {primes.Count}"); // 列挙で呼び出す Console.WriteLine(""); prime.Reset(); prime.PrimeCount = PrimesCount; foreach (var item in prime) { Console.Write($"{item} "); } Console.WriteLine("\n\nPush any key!"); Console.ReadKey(); }
public void PrimeIntegerEnsureICanCreateASequenceOfTen() { // Arrange Prime my_primes = new Prime(); // Act int[] actual = my_primes.GetSequence(10); int[] expected = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; // Assert CollectionAssert.AreEqual(expected, actual); }
public void PrimeEnsureICanGetNext() { // Arrange Prime my_primes = new Prime(); // Act int actual = my_primes.GetNext(5); int expected = 7; // Assert Assert.AreEqual(expected, actual); }
static void Main(string[] args) { const int PRIMECOUNT = 10001; //int numberFound = 0; long current = 1; Prime p = new Prime(); for (int i = 1; i <= PRIMECOUNT; i++) { current++; if(!p.isPrime(current)) { current = p.findNextPrime(current); } } Console.WriteLine("The " + PRIMECOUNT + "th prime number is " + current); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public void PrimeIs2Prime() { // Arrange Prime my_primes = new Prime(); // Act bool actual = my_primes.IsPrime(2); // Assert Assert.IsTrue(actual); }
public void PrimeEnsureICanCreateInstance() { Prime my_primes = new Prime(); Assert.IsNotNull(my_primes); }
private void OnAddPrimeButtonClick(string s) { try { decimal primePrice = decimal.Parse(InputPrimePrice); if (InputPrimeName == string.Empty || InputPrimeEnd < DateTime.Now) throw new ArgumentNullException(); var newPrime = new Prime { Label = InputPrimeName, Price = primePrice, StartDate = DateTime.Now, EndDate = InputPrimeEnd }; var userId = Employee.Id; ServiceSalaire.addPrime(userId, newPrime); // Update the employee Employee = ServiceSalaire.GetUserById(userId); } catch (ArgumentNullException) { MessageBox.Show("Les paramètres sont invalides, recommencer", "Erreur de paramètres", MessageBoxButton.OK, MessageBoxImage.Error); } catch (FormatException) { MessageBox.Show("Merci d'indiquer un nombre pour le montant.", "Erreur de montant", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception) { MessageBox.Show("Le service n'est pas disponible pour le moment", "Service non disponible", MessageBoxButton.OK, MessageBoxImage.Error); } }