public void IsPrimeTest()
        {
            var cts = new CancellationTokenSource();

            var primeFinderModel = new PrimeFinderModel(20);

            primeFinderModel.FindMaxPrime(cts);
            Assert.AreEqual(19, primeFinderModel.MaxPrime);

            primeFinderModel = new PrimeFinderModel(100);
            primeFinderModel.FindMaxPrime(cts);
            Assert.AreEqual(97, primeFinderModel.MaxPrime);

            primeFinderModel = new PrimeFinderModel(7000);
            primeFinderModel.FindMaxPrime(cts);
            Assert.AreEqual(6997, primeFinderModel.MaxPrime);

            primeFinderModel = new PrimeFinderModel(19000);
            primeFinderModel.FindMaxPrime(cts);
            Assert.AreEqual(18979, primeFinderModel.MaxPrime);

            primeFinderModel = new PrimeFinderModel(2000000);
            primeFinderModel.FindMaxPrime(cts);
            Assert.AreEqual(1999993, primeFinderModel.MaxPrime);
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor for PrimeFinderViewModel
        /// </summary>
        public PrimeFinderViewModel(IDataService dataService)
        {
            WindowTitle = "Prime Number Generator";

            StatusMessage = "Running";

            // Start the timer
            PrimeTimer = new PrimeTimerModel(60);

            // Listen for timer tick events
            PrimeTimer.DispatcherTimer.Tick += new EventHandler(OnTick);

            // Listen for the timer completed event
            PrimeTimer.TimerCompleted += new EventHandler(OnTimerCompleted);

            // Start the prime finder
            PrimeFinder = new PrimeFinderModel(100000000);
            PrimeFinder.Start();

            // Listen for the PrimeFound event
            PrimeFinder.PrimeFound += new EventHandler(OnPrimeFound);
        }