private static IEnumerable<Variant> GenerateVariants(Variant variant, Potter aBook, IEnumerable<Variant> alreadyGenerated) { return variant.Piles .Where(pile => !pile.Contains(aBook)) .Select(pile => CreateNewVariant(variant, pile, aBook)) .Where(newVariant => alreadyGenerated.All(v => !v.Equals(newVariant))); }
private static Variant CreateNewVariant(Variant variant, Pile selectedPile, Potter aBook) { var newPile = new Pile(selectedPile.Books); newPile.Add(aBook); var newVariant = new Variant(variant.Piles.Where(p => p != selectedPile)); newVariant.Add(newPile); return newVariant; }
public void TestFullPriceGivenTwoEqualBooks() { var listOfBooks = new List<BookTitle>(); listOfBooks.Add(BookTitle.Fifth); listOfBooks.Add(BookTitle.Fifth); Potter.Potter potter = new Potter.Potter(listOfBooks); Assert.AreEqual(40, potter.Total()); }
private IEnumerable<Variant> GenerateVariants(IEnumerable<Variant> variants, Potter aBook) { var newVariants = new List<Variant>(); foreach (var curVariant in variants) { foreach (var newVariant in GenerateVariants(curVariant, aBook, newVariants)) { newVariants.Add(newVariant); } if (curVariant.Piles.Count() < _maxPiles) { var variantWithASignelBook = new Variant(curVariant.Piles); variantWithASignelBook.Add(new Pile(new[] {aBook})); newVariants.Add(variantWithASignelBook); } } if (newVariants.Count() == 0) { newVariants.Add(new Variant(new[]{new Pile(new[] {aBook})})); } return newVariants; }
public void Remove(Potter book) { _books.Remove(book); UpdateHash(); }
public bool Contains(Potter aBook) { return Books.Contains(aBook); }
public void Add(Potter book) { _books.Add(book); UpdateHash(); }
public void TestFullValueWithOneBook() { Potter.Potter potter = new Potter.Potter(1); Assert.AreEqual(20, potter.Total()); }
public void Test5PercentOffWhenTwoBooks() { Potter.Potter potter = new Potter.Potter(2); Assert.AreEqual(38, potter.Total()); }
public void Test25PercentOffWhenFourBooks() { Potter.Potter potter = new Potter.Potter(5); Assert.AreEqual(75, potter.Total()); }
public void Test10PercentOffWhenThreeBooks() { Potter.Potter potter = new Potter.Potter(3); Assert.AreEqual(54, potter.Total()); }