public void TwoBooks_16Bucks() { BookSet set = new BookSet(); set.AddBook(0); set.AddBook(1); Assert.AreEqual(15.2d, set.CalculatePrice()); }
internal decimal GetPriceFor(BookSet bookSet) { var countOfBooksInSet = bookSet.Books.Count(b => b!=null); var discountMultiplier = _discountByCount.ContainsKey(countOfBooksInSet) ? _discountByCount[countOfBooksInSet] : 1; return (countOfBooksInSet * 8M) * discountMultiplier; }
public BookSet Clone() { BookSet set = new BookSet(); for (int i = 0; i < _set.Length; i++) if (_set[i] > 0) set.AddBook(i); return set; }
private static BookSet[] InitialiseEnoughSetsForHighestFrequencyBook(int setSize, int highestFrequency) { var sets = new BookSet[highestFrequency]; foreach (var i in Enumerable.Range(0, highestFrequency)) { sets[i] = new BookSet(setSize); } return sets; }
public double CalculatePriceIfBookWasAddedToSet(BookSet potentialSet, int index) { double total = 0; foreach (BookSet set in _booksets) if (set == potentialSet) { BookSet copy = potentialSet.Clone(); copy.AddBook(index); total += copy.CalculatePrice(); } else total += set.CalculatePrice(); return total; }
public void OneBook_8Bucks() { BookSet set = new BookSet(); set.AddBook(0); Assert.AreEqual(8, set.CalculatePrice()); }
public void EmptySet_CostsNothing() { BookSet set = new BookSet(); Assert.AreEqual(0, set.CalculatePrice()); }
private BookSet CreateNewBookSetContainingBook(int index) { BookSet set = new BookSet(); set.AddBook(index); return set; }