ConcatTest.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.Text;
  7. using System.Linq;
  8. using Xunit;
  9. namespace Tests
  10. {
  11. public class ConcatTest : Tests
  12. {
  13. [Fact]
  14. public void Concat_Arguments()
  15. {
  16. AssertThrows<ArgumentNullException>(() => EnumerableEx.Concat(default(IEnumerable<int>[])));
  17. AssertThrows<ArgumentNullException>(() => EnumerableEx.Concat(default(IEnumerable<IEnumerable<int>>)));
  18. }
  19. [Fact]
  20. public void Concat1()
  21. {
  22. var res = new[]
  23. {
  24. new[] { 1, 2, 3 },
  25. new[] { 4, 5 }
  26. }.Concat();
  27. Assert.True(Enumerable.SequenceEqual(res, new[] { 1, 2, 3, 4, 5 }));
  28. }
  29. [Fact]
  30. public void Concat2()
  31. {
  32. var i = 0;
  33. var xss = Enumerable.Range(0, 3).Select(x => Enumerable.Range(0, x + 1)).Do(_ => ++i);
  34. var res = xss.Concat().Select(x => i + " - " + x).ToList();
  35. Assert.True(Enumerable.SequenceEqual(res, new[] {
  36. "1 - 0",
  37. "2 - 0",
  38. "2 - 1",
  39. "3 - 0",
  40. "3 - 1",
  41. "3 - 2",
  42. }));
  43. }
  44. [Fact]
  45. public void Concat3()
  46. {
  47. var res = EnumerableEx.Concat(
  48. new[] { 1, 2, 3 },
  49. new[] { 4, 5 }
  50. );
  51. Assert.True(Enumerable.SequenceEqual(res, new[] { 1, 2, 3, 4, 5 }));
  52. }
  53. }
  54. }