public void Five_Books_Should_Leave_One()
 {
     var bookSet = new BookSet(1, 2, 3, 4, 5);
     var result = bookSet.PopCart(4);
     result = bookSet.PopCart(5);
     Assert.That(result.Length, Is.EqualTo(1));
 }
Ejemplo n.º 2
0
 public decimal CostWith(int book)
 {
     var set = new BookSet();
     foreach (var b in _books)
     {
         set.Add(b);
     }
     set.Add(book);
     return set.Cost();
 }
Ejemplo n.º 3
0
        private decimal GetMinPriceForSet(BookSet originalBookSet, decimal minPrice)
        {
            if (originalBookSet.IsEmpty())
                return 0m;

            for (int includeAtMost = 2; includeAtMost <= 5; includeAtMost++)
            {
                var bookSet = originalBookSet.Clone();
                var cart = bookSet.PopCart(includeAtMost);
                minPrice = Math.Min(minPrice,
                    GetPrice(cart, 8m) + GetMinPriceForSet(bookSet, minPrice));
            }
            return minPrice;
        }