Example #1
0
 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)));
 }
Example #2
0
 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;
 }
Example #3
0
 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());
 }
Example #4
0
 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;
 }
Example #5
0
File: Pile.cs Project: darkiri/Kata
 public void Remove(Potter book)
 {
     _books.Remove(book);
     UpdateHash();
 }
Example #6
0
File: Pile.cs Project: darkiri/Kata
 public bool Contains(Potter aBook)
 {
     return Books.Contains(aBook);
 }
Example #7
0
File: Pile.cs Project: darkiri/Kata
 public void Add(Potter book)
 {
     _books.Add(book);
     UpdateHash();
 }
Example #8
0
 public void TestFullValueWithOneBook()
 {
     Potter.Potter potter = new Potter.Potter(1);
     Assert.AreEqual(20, potter.Total());
 }
Example #9
0
 public void Test5PercentOffWhenTwoBooks()
 {
     Potter.Potter potter = new Potter.Potter(2);
     Assert.AreEqual(38, potter.Total());
 }
Example #10
0
 public void Test25PercentOffWhenFourBooks()
 {
     Potter.Potter potter = new Potter.Potter(5);
     Assert.AreEqual(75, potter.Total());
 }
Example #11
0
 public void Test10PercentOffWhenThreeBooks()
 {
     Potter.Potter potter = new Potter.Potter(3);
     Assert.AreEqual(54, potter.Total());
 }