Concat.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using Xunit;
  8. namespace Tests
  9. {
  10. public class Concat : Tests
  11. {
  12. [Fact]
  13. public void Concat_Arguments()
  14. {
  15. AssertThrows<ArgumentNullException>(() => EnumerableEx.Concat(default(IEnumerable<int>[])));
  16. AssertThrows<ArgumentNullException>(() => EnumerableEx.Concat(default(IEnumerable<IEnumerable<int>>)));
  17. }
  18. [Fact]
  19. public void Concat1()
  20. {
  21. var res = new[]
  22. {
  23. new[] { 1, 2, 3 },
  24. new[] { 4, 5 }
  25. }.Concat();
  26. Assert.True(Enumerable.SequenceEqual(res, new[] { 1, 2, 3, 4, 5 }));
  27. }
  28. [Fact]
  29. public void Concat2()
  30. {
  31. var i = 0;
  32. var xss = Enumerable.Range(0, 3).Select(x => Enumerable.Range(0, x + 1)).Do(_ => ++i);
  33. var res = xss.Concat().Select(x => i + " - " + x).ToList();
  34. Assert.True(Enumerable.SequenceEqual(res, new[] {
  35. "1 - 0",
  36. "2 - 0",
  37. "2 - 1",
  38. "3 - 0",
  39. "3 - 1",
  40. "3 - 2",
  41. }));
  42. }
  43. [Fact]
  44. public void Concat3()
  45. {
  46. var res = EnumerableEx.Concat(
  47. new[] { 1, 2, 3 },
  48. new[] { 4, 5 }
  49. );
  50. Assert.True(Enumerable.SequenceEqual(res, new[] { 1, 2, 3, 4, 5 }));
  51. }
  52. }
  53. }