private static bool isEdgeCaseOfType(List <Book> books, EdgeCaseType edgeCaseType) { if (edgeCaseType == EdgeCaseType.TotalIsEightWithFiveDistinct) { return(books.Count == 8 && books.Distinct().Count() == 5); } if (edgeCaseType == EdgeCaseType.TotalIsTwentyThreeWithFiveDistinct) { return(books.Count == 23 && books.Distinct().Count() == 5); } return(false); }
private static bool isEdgeCase(List <Book> books, out EdgeCaseType edgeCaseType) { if (isEdgeCaseOfType(books, EdgeCaseType.TotalIsEightWithFiveDistinct)) { edgeCaseType = EdgeCaseType.TotalIsEightWithFiveDistinct; return(true); } if (isEdgeCaseOfType(books, EdgeCaseType.TotalIsTwentyThreeWithFiveDistinct)) { edgeCaseType = EdgeCaseType.TotalIsTwentyThreeWithFiveDistinct; return(true); } edgeCaseType = default(EdgeCaseType); return(false); }
private decimal CalculateEdgeCaseCombinations(List <Book> books, EdgeCaseType edgeCaseType) { // My brain hurt trying to create a generic solver switch (edgeCaseType) { case EdgeCaseType.TotalIsEightWithFiveDistinct: return((4 * Rules.DiscountFor(4) * Rules.UnitCost) * 2); case EdgeCaseType.TotalIsTwentyThreeWithFiveDistinct: return(((5 * Rules.DiscountFor(5) * Rules.UnitCost) * 3) + ((4 * Rules.DiscountFor(4) * Rules.UnitCost) * 2)); default: throw new NotImplementedException("Unknown edge case"); } }