Beispiel #1
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public object FunctionHandler(InputModel input, ILambdaContext context)
        {
            if (input == null)
            {
                return(new List <int> {
                    42
                });
            }

            if (input.WorkStart > input.BusiestHour || input.BusiestHour > input.WorkEnd)
            {
                return(new List <int>());
            }

            var weightCalculator = new WeightCalculator();
            var spreadCalculator = new SpreadCalculator();

            var weights = weightCalculator.Calculate(input);
            var spread  = spreadCalculator.Calculate(input, weights);

            return(spread);
        }
        public void SpreadCalculateWithStaticWeightsTest()
        {
            var calculator = new SpreadCalculator();

            var input = new InputModel
            {
                WorkStart   = 9,
                WorkEnd     = 18,
                BusiestHour = 16
            };
            var weights = Enumerable.Repeat(1.0, 9).ToList();

            var customersForMonth = Enumerable.Repeat(0, 1000)
                                    .Select(x => calculator.Calculate(input, weights));

            //customers per hour. indicating number of customers from the interval start time till the next interval
            //9 - .5 - 10 - .5 - 11 - .5 - 12 - .5 - 13 - .5 - 14 - .5 - 15 - .5 - 16 - .5 - 17 - .5
            Assert.All(customersForMonth, (spread) => Assert.Equal(18, spread.Count));

            var totalCustomersPerDay = customersForMonth.Select(spread => spread.Sum());

            Assert.True(Math.Abs(13 - totalCustomersPerDay.Average()) < 0.5);
        }