Esempio n. 1
0
        public void Amount_SampleExample_5()
        {
            var cars   = new[] { 0, 1, 0, 1, 1 };
            var solver = new PassingCars(cars);

            var passingTotal = solver.Amount();

            passingTotal.Should().Be(5);
        }
Esempio n. 2
0
        public void Amount_OnePair_1()
        {
            var cars   = new[] { 0, 1 };
            var solver = new PassingCars(cars);

            var passingTotal = solver.Amount();

            passingTotal.Should().Be(1);
        }
Esempio n. 3
0
        public void Amount_MoreThanBillion_MinusOne()
        {
            var cars = Enumerable.Repeat(0, 1_000_000)
                       .Concat(Enumerable.Repeat(1, 1_000_000))
                       .ToArray();
            var solver = new PassingCars(cars);

            var passingTotal = solver.Amount();

            passingTotal.Should().Be(-1);
        }
Esempio n. 4
0
        public void Amount_AllEastBeforeAllWest_Multiplication(int amountWest, int amountEast)
        {
            var cars = Enumerable.Repeat(0, amountEast)
                       .Concat(Enumerable.Repeat(1, amountWest))
                       .ToArray();
            var solver = new PassingCars(cars);

            var passingTotal = solver.Amount();

            passingTotal.Should().Be(amountEast * amountWest);
        }
Esempio n. 5
0
        public void Amount_LargeRandom_Fast()
        {
            var random = new Random(DateTime.UtcNow.Millisecond);
            var cars   = Enumerable.Range(1, 1_000_000).Select(n => random.Next(0, 2)).ToArray();

            var stopWatch    = Stopwatch.StartNew();
            var solver       = new PassingCars(cars);
            var passingTotal = solver.Amount();

            stopWatch.Start();

            stopWatch.ElapsedMilliseconds.Should().BeLessOrEqualTo(1000);
            _outputHelper.WriteLine($"elapsed {stopWatch.Elapsed}");
        }