Exemple #1
0
 public void Add(Book book)
 {
     _books.Add(book);
 }
 private bool ShouldApplyDiscount(Book book)
 {
     return (_books.Any(x => x.GetType() != book.GetType()));
 }
 public void Add(Book book)
 {
     _books.Add(book);
     _total += BOOK_PRICE;
     if (ShouldApplyDiscount(book))
     {
         ApplyDiscount(new PercentageDiscount(5));
     }
 }
Exemple #4
0
 private void AddBook(Book book)
 {
     if (ContainsBook(book))
     {
         throw new ArgumentException("This set already contains this book.");
     }
     Books[book.PositionInSet - 1] = book;
 }
Exemple #5
0
 private static BookSet ShortestSetWithoutBook(IEnumerable<BookSet> sets, Book book)
 {
     return sets.OrderBy(s => s.Books.Count(b => b != null))
                .FirstOrDefault(s => !s.ContainsBook(book));
 }
Exemple #6
0
 private static void AddBookToShortestSetThatDoesNotContainIt(IEnumerable<BookSet> sets, Book book)
 {
     var shortestCandidateSet = ShortestSetWithoutBook(sets, book);
     shortestCandidateSet.AddBook(book);
 }
Exemple #7
0
 private bool ContainsBook(Book book)
 {
     return Books.Length >= book.PositionInSet
         && Books.ElementAt(book.PositionInSet -1) != null;
 }
Exemple #8
0
 private BookSet(int setSize)
 {
     Books = new Book[setSize];
 }