1
0

Tests.Multiple.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. using System;
  3. using System.Text;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Microsoft.VisualStudio.TestTools.UnitTesting;
  7. namespace Tests
  8. {
  9. public partial class Tests
  10. {
  11. [TestMethod]
  12. public void Concat_Arguments()
  13. {
  14. AssertThrows<ArgumentNullException>(() => EnumerableEx.Concat(default(IEnumerable<int>[])));
  15. AssertThrows<ArgumentNullException>(() => EnumerableEx.Concat(default(IEnumerable<IEnumerable<int>>)));
  16. }
  17. [TestMethod]
  18. public void Concat1()
  19. {
  20. var res = new[]
  21. {
  22. new[] { 1, 2, 3 },
  23. new[] { 4, 5 }
  24. }.Concat();
  25. Assert.IsTrue(Enumerable.SequenceEqual(res, new[] { 1, 2, 3, 4, 5 }));
  26. }
  27. [TestMethod]
  28. public void Concat2()
  29. {
  30. var i = 0;
  31. var xss = Enumerable.Range(0, 3).Select(x => Enumerable.Range(0, x + 1)).Do(_ => ++i);
  32. var res = xss.Concat().Select(x => i + " - " + x).ToList();
  33. Assert.IsTrue(Enumerable.SequenceEqual(res, new[] {
  34. "1 - 0",
  35. "2 - 0",
  36. "2 - 1",
  37. "3 - 0",
  38. "3 - 1",
  39. "3 - 2",
  40. }));
  41. }
  42. [TestMethod]
  43. public void Concat3()
  44. {
  45. var res = EnumerableEx.Concat(
  46. new[] { 1, 2, 3 },
  47. new[] { 4, 5 }
  48. );
  49. Assert.IsTrue(Enumerable.SequenceEqual(res, new[] { 1, 2, 3, 4, 5 }));
  50. }
  51. [TestMethod]
  52. public void SelectMany_Arguments()
  53. {
  54. AssertThrows<ArgumentNullException>(() => EnumerableEx.SelectMany<int, int>(null, new[] { 1 }));
  55. AssertThrows<ArgumentNullException>(() => EnumerableEx.SelectMany<int, int>(new[] { 1 }, null));
  56. }
  57. [TestMethod]
  58. public void SelectMany()
  59. {
  60. var res = new[] { 1, 2 }.SelectMany(new[] { 'a', 'b', 'c' }).ToList();
  61. Assert.IsTrue(Enumerable.SequenceEqual(res, new[] { 'a', 'b', 'c', 'a', 'b', 'c' }));
  62. }
  63. }
  64. }