Skip to content

Commit

Permalink
Add tests for Encode's IEnumerable<int> overload
Browse files Browse the repository at this point in the history
In addition to one for cases where a negative
number is included in a set of numbers.
  • Loading branch information
aradalvand committed Aug 6, 2023
1 parent 97e6402 commit b0ddd24
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/Sqids.Tests/BlockListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ string normalEncoded
}

[Fact]
public void Encode_WithTooShortBlockListWords_RemovesFromBlockList()
public void Encode_WithTooShortBlockListWords_DiscardsBlockList()
{
var encoder = new SqidsEncoder(new()
{
Expand Down
23 changes: 19 additions & 4 deletions test/Sqids.Tests/DefaultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,35 @@ public void Encode_SingleNumber_ReturnsRightId(int number, string expected)
[InlineData(new[] { 23, 129, 1892, 83, 9, 0, 12, 38, 9 }, "H2VQqalFJ6kwtUkUK242L")]
public void Encode_MultipleNumbers_ReturnsRightId(int[] numbers, string expected)
{
var encoded = _encoder.Encode(numbers);
encoded.Should().Be(expected);
var encoding1 = _encoder.Encode(numbers); // NOTE: The `params int[]` overload
encoding1.Should().Be(expected);

var encoding2 = _encoder.Encode(numbers.ToList()); // NOTE: The `IEnumerable<int>` overload
encoding2.Should().Be(expected);
}

[Theory]
[InlineData(-1)]
[InlineData(-145)]
[InlineData(int.MinValue)]
public void Encode_NegativeNumber_Throws(int input)
public void Encode_SingleNegativeNumber_Throws(int number)
{
var encoding = () => _encoder.Encode(input);
var encoding = () => _encoder.Encode(number);
encoding.Should().Throw<ArgumentOutOfRangeException>();
}

[Theory]
[InlineData(new[] { 123, 50, -1, 10 })]
[InlineData(new[] { int.MinValue, 1, 2 })]
public void Encode_NegativeNumberAmongMultiple_Throws(int[] numbers)
{
var encoding1 = () => _encoder.Encode(numbers); // NOTE: The `params int[]` overload
encoding1.Should().Throw<ArgumentOutOfRangeException>();

var encoding2 = () => _encoder.Encode(numbers.ToList()); // NOTE: The `IEnumerable<int>` overload
encoding2.Should().Throw<ArgumentOutOfRangeException>();
}

[Fact]
public void Encode_EmptyArray_ReturnsEmptyString()
{
Expand Down

0 comments on commit b0ddd24

Please sign in to comment.