CopyToExtensionsTests.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using Xunit;
  4. namespace Jellyfin.Extensions.Tests
  5. {
  6. public static class CopyToExtensionsTests
  7. {
  8. public static IEnumerable<object[]> CopyTo_Valid_Correct_TestData()
  9. {
  10. yield return new object[] { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 0, new[] { 0, 1, 2, 3, 4, 5 } };
  11. yield return new object[] { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 2, new[] { 5, 4, 0, 1, 2, 0 } };
  12. }
  13. [Theory]
  14. [MemberData(nameof(CopyTo_Valid_Correct_TestData))]
  15. public static void CopyTo_Valid_Correct<T>(IReadOnlyList<T> source, IList<T> destination, int index, IList<T> expected)
  16. {
  17. source.CopyTo(destination, index);
  18. Assert.Equal(expected, destination);
  19. }
  20. public static IEnumerable<object[]> CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData()
  21. {
  22. yield return new object[] { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, -1 };
  23. yield return new object[] { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 6 };
  24. yield return new object[] { new[] { 0, 1, 2 }, Array.Empty<int>(), 0 };
  25. yield return new object[] { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0 }, 0 };
  26. yield return new object[] { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 1 };
  27. }
  28. [Theory]
  29. [MemberData(nameof(CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData))]
  30. public static void CopyTo_Invalid_ThrowsArgumentOutOfRangeException<T>(IReadOnlyList<T> source, IList<T> destination, int index)
  31. {
  32. Assert.Throws<ArgumentOutOfRangeException>(() => source.CopyTo(destination, index));
  33. }
  34. }
  35. }