2021-04-01 17:13:03 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Xunit;
|
|
|
|
|
2021-06-19 16:02:33 +00:00
|
|
|
namespace Jellyfin.Extensions.Tests
|
2021-04-01 17:13:03 +00:00
|
|
|
{
|
|
|
|
public static class CopyToExtensionsTests
|
|
|
|
{
|
2021-09-11 20:31:24 +00:00
|
|
|
public static TheoryData<IReadOnlyList<int>, IList<int>, int, IList<int>> CopyTo_Valid_Correct_TestData()
|
2021-04-01 17:13:03 +00:00
|
|
|
{
|
2023-12-18 21:02:31 +00:00
|
|
|
var data = new TheoryData<IReadOnlyList<int>, IList<int>, int, IList<int>>
|
|
|
|
{
|
|
|
|
{ new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 0, new[] { 0, 1, 2, 3, 4, 5 } },
|
|
|
|
{ new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 2, new[] { 5, 4, 0, 1, 2, 0 } }
|
|
|
|
};
|
2021-09-11 20:31:24 +00:00
|
|
|
|
|
|
|
return data;
|
2021-04-01 17:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[MemberData(nameof(CopyTo_Valid_Correct_TestData))]
|
2023-12-18 21:02:31 +00:00
|
|
|
public static void CopyTo_Valid_Correct(IReadOnlyList<int> source, IList<int> destination, int index, IList<int> expected)
|
2021-04-01 17:13:03 +00:00
|
|
|
{
|
|
|
|
source.CopyTo(destination, index);
|
|
|
|
Assert.Equal(expected, destination);
|
|
|
|
}
|
|
|
|
|
2021-09-11 20:31:24 +00:00
|
|
|
public static TheoryData<IReadOnlyList<int>, IList<int>, int> CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData()
|
2021-04-01 17:13:03 +00:00
|
|
|
{
|
2023-12-18 21:02:31 +00:00
|
|
|
var data = new TheoryData<IReadOnlyList<int>, IList<int>, int>
|
|
|
|
{
|
|
|
|
{ new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, -1 },
|
|
|
|
{ new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 6 },
|
|
|
|
{ new[] { 0, 1, 2 }, Array.Empty<int>(), 0 },
|
|
|
|
{ new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0 }, 0 },
|
|
|
|
{ new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 1 }
|
|
|
|
};
|
2021-09-11 20:31:24 +00:00
|
|
|
|
|
|
|
return data;
|
2021-04-01 17:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[MemberData(nameof(CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData))]
|
2023-12-18 21:02:31 +00:00
|
|
|
public static void CopyTo_Invalid_ThrowsArgumentOutOfRangeException(IReadOnlyList<int> source, IList<int> destination, int index)
|
2021-04-01 17:13:03 +00:00
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => source.CopyTo(destination, index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|