Tests.Multiple.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.Text;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using Xunit;
  9. namespace Tests
  10. {
  11. public partial class 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. [Fact]
  54. public void SelectMany_Arguments()
  55. {
  56. AssertThrows<ArgumentNullException>(() => EnumerableEx.SelectMany<int, int>(null, new[] { 1 }));
  57. AssertThrows<ArgumentNullException>(() => EnumerableEx.SelectMany<int, int>(new[] { 1 }, null));
  58. }
  59. [Fact]
  60. public void SelectMany()
  61. {
  62. var res = new[] { 1, 2 }.SelectMany(new[] { 'a', 'b', 'c' }).ToList();
  63. Assert.True(Enumerable.SequenceEqual(res, new[] { 'a', 'b', 'c', 'a', 'b', 'c' }));
  64. }
  65. }
  66. }