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