public static int Run(string[] hand1, string[] hand2, IConsole console) { try { // Execute var winner = ProjectEulerProblem54.GetWinner(hand1, hand2); // Display result if (winner == 0) { console.Out.WriteLine("TIE. No Winner!"); } else if (winner == 1) { console.Out.WriteLine("Player 1 wins!"); } else if (winner == 2) { console.Out.WriteLine("Player 2 wins!"); } return(0); } catch (ArgumentException e) { console.Error.WriteLine($"Error: { e.Message }"); return(1); } }
public void GetWinner_WhenHand1OrHand2HasMoreThan5_ThrowsArgumentException(string hand1, string hand2) { Action actual = () => ProjectEulerProblem54.GetWinner(hand1.Split(" "), hand2.Split(" ")); Assert.Throws <ArgumentException>(actual); }
public void GetWinner_WhenHand1AndHand2AreValid_ReturnsValidResult(string hand1, string hand2, int expected) { var actual = ProjectEulerProblem54.GetWinner(hand1.Split(" "), hand2.Split(" ")); Assert.Equal(expected, actual); }
public void GetWinner_WhenAnyCardHasLessThan2Characters_ThrowsArgumentException(string hand1, string hand2) { Action actual = () => ProjectEulerProblem54.GetWinner(hand1.Split(" "), hand2.Split(" ")); Assert.Throws <ArgumentException>(actual); }
public void GetWinner_WhenHand1OrHand2IsNull_ThrowsArgumentNullException(string hand1, string hand2) { Action actual = () => ProjectEulerProblem54.GetWinner(hand1?.Split(" "), hand2?.Split(" ")); Assert.Throws <ArgumentNullException>(actual); }