Exemple #1
0
        private decimal DiscountForSetSize(List <Book> books, int evaluationSetSize)
        {
            var discountAmount = 0m;

            var splitterOptions = new SetSplitterOptions
            {
                MaximumSetSize = evaluationSetSize
            };

            var splitter    = new SetSplitter(splitterOptions);
            var setsOfBooks = splitter.Split(books);

            foreach (var setOfBooks in setsOfBooks)
            {
                var quantityOfBooks = setOfBooks.Books.Count;
                var basePriceOfSet  = setOfBooks.Books.Sum(x => x.Price);

                switch (quantityOfBooks)
                {
                case 1:
                    discountAmount += 0;
                    break;

                case 2:
                    discountAmount += basePriceOfSet * 0.05m;
                    break;

                case 3:
                    discountAmount += basePriceOfSet * 0.1m;
                    break;

                case 4:
                    discountAmount += basePriceOfSet * 0.2m;
                    break;

                case 5:
                    discountAmount += basePriceOfSet * 0.25m;
                    break;

                default:
                    throw new Exception($"Not sure how to handle this amount of books in the set: {quantityOfBooks}");
                }
            }

            return(discountAmount);
        }
Exemple #2
0
 public SetSplitter(SetSplitterOptions splitterOptions)
 {
     options = splitterOptions;
 }