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