public void SmallGrid(int value)
        {
            //When
            int[] primes     = _primeFinder.FindPrimes(value);
            var   result     = _renderer.Output(primes);
            var   knownTable = "table string";

            //Then
            Console.WriteLine(result);
            // Later validate the result against a known correct table string.
            // Assert.True(result == knownTable, $"The rendered grid and known grid match for input {values}");
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            int primeCount = 0;

            // A little sanity testing.
            try
            {
                primeCount = Int32.Parse(args[0]);
            }
            catch (FormatException)
            {
                Console.WriteLine($"{args[0]}: Bad Format");
                return;
            }
            catch (OverflowException)
            {
                Console.WriteLine($"{args[0]}: Overflow");
                return;
            }

            if (primeCount < 1)
            {
                Console.WriteLine("Please enter an integer greater than 0");
                return;
            }

            // The required objects
            var          primeFinder = new PrimesFinder();
            IPrimeOutput outputGenerator;

            int[] primes = primeFinder.FindPrimes(primeCount);
            // It's a shame you can't just print the array directly like Swift and Python
            string primesDisplay = String.Join(", ", primes);

            Console.WriteLine($"The first {primeCount} primes are {primesDisplay}");

            // What to do with the primes though?
            // Coding against an interface really is lovely.
            if (args.Length > 1)
            {
                if (args[1] == "-csv")
                {
                    outputGenerator = new CsvSaver();
                }
                else
                {
                    Console.WriteLine($"The argument {args[1]} cannot be parsed, did you mean -csv ?");
                    return;
                }
            }
            else
            {
                outputGenerator = new GridRender();
            }
            outputGenerator.Output(primes);
        }
        private void Callback(object state)
        {
            _logger.LogInformation("Start load");

            Stopwatch stopwatch = Stopwatch.StartNew();

            int[] primes = _primesFinder.FindPrimes(_settings);
            stopwatch.Stop();

            _logger.LogInformation("Load finish. Time: {Time}", stopwatch.Elapsed);

            _jsonWorker.WriteResult(new Result(true, stopwatch.Elapsed.ToString(), primes));

            _hostApplicationLifetime.StopApplication();
        }