mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 23:00:43 -08:00
Handle array size inputs less than 1.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using FsCheck.Xunit;
|
||||
using Reverse.Tests.Generators;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
@@ -7,6 +8,14 @@ namespace Reverse.Tests
|
||||
{
|
||||
public class ReverserTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_CannotAcceptNumberLessThanZero()
|
||||
{
|
||||
Action action = () => new Reverser(0);
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(action);
|
||||
}
|
||||
|
||||
[Property(Arbitrary = new[] { typeof(PositiveIntegerGenerator) })]
|
||||
public void Constructor_CreatesRandomArrayOfSpecifiedLength(int size)
|
||||
{
|
||||
|
||||
@@ -43,6 +43,11 @@ namespace Reverse
|
||||
|
||||
private int[] CreateRandomArray(int size)
|
||||
{
|
||||
if (size < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(size), "Array size must be a positive integer");
|
||||
}
|
||||
|
||||
var array = new int[size];
|
||||
for (int i = 1; i <= size; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user