コード例 #1
0
        public void TestStopsCalculation()
        {
            var random = new Random();

            for (int i = 0; i < testIterations; i++)
            {
                var randomMglt        = random.Next(10, 100);
                var randomConsumables = random.Next(1, 5);

                var consumableTimeValues = Enum.GetValues(typeof(ConsumableTime));
                var randomTime           = (ConsumableTime)consumableTimeValues.GetValue(random.Next(consumableTimeValues.Length));

                var starship = new Starship()
                {
                    MGLT        = randomMglt.ToString(),
                    Consumables = $"{randomConsumables} {randomTime}"
                };

                var hoursToRefill = randomMglt * randomConsumables * (int)randomTime;
                var stopsExpected = numberOfStops / hoursToRefill - (numberOfStops % hoursToRefill == 0 ? 1 : 0);

                Assert.Equal(stopsExpected, starship.CalculateStops(numberOfStops));
                Assert.Equal(0, starship.CalculateStops(hoursToRefill));
                Assert.Equal(0, starship.CalculateStops(hoursToRefill - 1));
                Assert.Equal(1, starship.CalculateStops(hoursToRefill + 1));
            }
        }