Ejemplo n.º 1
0
        public void Tests(int day, int part, string input, string expectedResult)
        {
            ISolution solution = SolutionFactory.GetSolution(day, part);
            string    result   = solution.Solve(input);

            Assert.That(result, Is.EqualTo(expectedResult));
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            int day  = int.Parse(args[0]);
            int part = int.Parse(args[1]);

            ISolution instance = SolutionFactory.GetSolution(day, part);

            // Load the data
            var    locationUri       = new UriBuilder(Assembly.GetExecutingAssembly().CodeBase);
            string location          = Uri.UnescapeDataString(locationUri.Path);
            string locationDirectory = Path.GetDirectoryName(location);
            string inputFileName     = Path.Combine(locationDirectory, "Input", $"day{day:D2}.txt");
            string data = File.ReadAllText(inputFileName);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            string result = instance.Solve(data);

            stopwatch.Stop();

            Console.WriteLine(result);
            Console.WriteLine($"Result obtained in {stopwatch.ElapsedMilliseconds}ms");
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            int day        = int.Parse(args[0]);
            int part       = int.Parse(args[1]);
            int executions = args.Length == 2 ? 1 : int.Parse(args[2]);

            // Load the data
            var    locationUri       = new UriBuilder(Assembly.GetExecutingAssembly().Location !);
            string location          = Uri.UnescapeDataString(locationUri.Path);
            string locationDirectory = Path.GetDirectoryName(location) !;
            string inputFileName     = Path.Combine(locationDirectory, "Input", $"day{day:D2}.txt");
            string data = File.ReadAllText(inputFileName);

            string result = string.Empty;
            var    times  = new List <double>(executions);

            if (executions > 1)
            {
                // This is a timing run, so warm things up first.
                for (int warmup = 0; warmup < 5; warmup++)
                {
                    ISolution instance = SolutionFactory.GetSolution(day, part);
                    instance.Solve(data);
                }
            }

            for (int i = 0; i < executions; i++)
            {
                ISolution instance = SolutionFactory.GetSolution(day, part);

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                result = instance.Solve(data);

                stopwatch.Stop();

                times.Add(stopwatch.Elapsed.TotalMilliseconds);
            }

            Console.WriteLine(result);

            if (executions == 1)
            {
                Console.WriteLine($"Result obtained in {times[0]}ms");
            }
            else
            {
                Console.WriteLine($"Processing executed {executions} times:");
                Console.WriteLine($"\tAvg: {times.Average():0.00}ms");
                Console.WriteLine($"\tMin: {times.Min():0.00}ms");
                Console.WriteLine($"\tMax: {times.Max():0.00}ms");
            }
        }