The Tenth Frame Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace ScratchPadTest | |
{ | |
public class TenthFrame : Frame | |
{ | |
public class IllegalFrameException : Exception { } | |
public int ThirdThrow { get; private set; } | |
public override int Total { get { return base.Total + ThirdThrow; } } | |
public TenthFrame(int firstThrow, int secondThrow, int thirdThrow) | |
{ | |
ValidateIndividualThrows(firstThrow, secondThrow, thirdThrow); | |
CheckConsecutiveThrows(firstThrow, secondThrow); | |
CheckConsecutiveThrows(secondThrow, thirdThrow); | |
CheckForIllegalThirdThrow(firstThrow, secondThrow, thirdThrow); | |
FirstThrow = firstThrow; | |
SecondThrow = secondThrow; | |
ThirdThrow = thirdThrow; | |
} | |
private static void CheckForIllegalThirdThrow(int first, int second, int third) | |
{ | |
if (first + second < Mark && third > 0) | |
throw new IllegalFrameException(); | |
} | |
private static void CheckConsecutiveThrows(int first, int second) | |
{ | |
if (first != Mark && first + second > Mark) | |
throw new IllegalFrameException(); | |
} | |
private static void ValidateIndividualThrows(params int[] throws) | |
{ | |
if (throws.Any(th => th < 0)) | |
throw new UnderflowException(); | |
if (throws.Any(th => th > Mark)) | |
throw new OverflowException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment