using System; using System.Collections.Generic; using System.Text; namespace CSharpUnitTesting { public class Book { // Attributes private List _chapters; // Constructors public Book() { _chapters = new List(); } public Book(IEnumerable chapters) { _chapters = new List(chapters); } // Properties // Methods public void AddChapter(string title, int pages, int words) { _chapters.Add(new BookChapter(title, pages, words)); } public bool GetChapter(string title, out BookChapter chapter) { chapter = _chapters.Find((c) => c.GetTitle() == title); return chapter != null; } public int GetChapterCount() { return _chapters.Count; } public int GetPageCount() { int pageCount = 0; _chapters.ForEach((c) => pageCount += c.GetPages()); return pageCount; } public int GetWordCount() { int wordCount = 0; _chapters.ForEach((c) => wordCount += c.GetWordCount()); return wordCount; } public double GetAverageWordsPerChapter() { // There is a bug here...write a test to find it return GetWordCount() / GetChapterCount(); } } }