public void When_One_Set_In_List_Bigger_Than_Five_Set() { var bigListOneSet = ObjectMother.Builder.ThreeUniqueBooksOneDuplicate(8M); var builder = new BookSetBuilder(5); var sut = builder.Build(bigListOneSet.Books.ToList()); sut.Count().Should().Be(1); }
public void One_Thousands_Books_Five_Of_Each_Should_Give_Two_HundredSets() { var books = ObjectMother.Builder.OneThousandBooks(8M); var builder = new BookSetBuilder(5); var sut = builder.Build(books.ToList()); sut.Count().Should().Be(200); }
public void When_Two_Sets_In_List_We_Get_Two_Sets() { var bookBasket = ObjectMother.Builder.Two_Two_Two_One_One(8M); var builder = new BookSetBuilder(5); var sut = builder.Build(bookBasket.Books.ToList()); sut.Count.Should().Be(2); }
public decimal Apply(BookBasket bookBasket) { var booksToDiscount = bookBasket.Books.ToList(); if (bookBasket.AllSame()) { //todo move this into own class return(booksToDiscount.Count() * _fullPrice); } bool hasDuplicates = bookBasket.HasDuplicates(); if (hasDuplicates) { var bookSetBuilder = new BookSetBuilder(_setCount); var set = bookSetBuilder.Build(booksToDiscount); decimal total = 0M; int setCount = 0; foreach (var item in set.Keys) { total += Calculate(set[item].Count, set[item]); setCount += set[item].Count; } if (IncompleteSet(booksToDiscount, setCount)) { total += (booksToDiscount.Count - setCount) * _fullPrice; } return(total); } var noOfUniqueBooks = bookBasket.Books.Count(); return(Calculate(noOfUniqueBooks, booksToDiscount)); }