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