Debian Codegraph @

external/rx/Ix/NET/Tests/Tests.Multiple.cs

raw
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 #if NUNIT
7 using NUnit.Framework;
8 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
9 using TestMethodAttribute = NUnit.Framework.TestAttribute;
10 using TestInitializeAttribute = NUnit.Framework.SetUpAttribute;
11 #else
12 using Microsoft.VisualStudio.TestTools.UnitTesting;
13 #endif
14
15 namespace Tests
16 {
17 public partial class Tests
18 {
19 [TestMethod]
20 public void Concat_Arguments()
21 {
22 AssertThrows<ArgumentNullException>(() => EnumerableEx.Concat(default(IEnumerable<int>[])));
23 AssertThrows<ArgumentNullException>(() => EnumerableEx.Concat(default(IEnumerable<IEnumerable<int>>)));
24 }
25
26 [TestMethod]
27 public void Concat1()
28 {
29 var res = new[]
30 {
31 new[] { 1, 2, 3 },
32 new[] { 4, 5 }
33 }.Concat();
34
35 Assert.IsTrue(Enumerable.SequenceEqual(res, new[] { 1, 2, 3, 4, 5 }));
36 }
37
38 [TestMethod]
39 public void Concat2()
40 {
41 var i = 0;
42 var xss = Enumerable.Range(0, 3).Select(x => Enumerable.Range(0, x + 1)).Do(_ => ++i);
43
44 var res = xss.Concat().Select(x => i + " - " + x).ToList();
45
46 Assert.IsTrue(Enumerable.SequenceEqual(res, new[] {
47 "1 - 0",
48 "2 - 0",
49 "2 - 1",
50 "3 - 0",
51 "3 - 1",
52 "3 - 2",
53 }));
54 }
55
56 [TestMethod]
57 public void Concat3()
58 {
59 var res = EnumerableEx.Concat(
60 new[] { 1, 2, 3 },
61 new[] { 4, 5 }
62 );
63
64 Assert.IsTrue(Enumerable.SequenceEqual(res, new[] { 1, 2, 3, 4, 5 }));
65 }
66
67 [TestMethod]
68 public void SelectMany_Arguments()
69 {
70 AssertThrows<ArgumentNullException>(() => EnumerableEx.SelectMany<int, int>(null, new[] { 1 }));
71 AssertThrows<ArgumentNullException>(() => EnumerableEx.SelectMany<int, int>(new[] { 1 }, null));
72 }
73
74 [TestMethod]
75 public void SelectMany()
76 {
77 var res = new[] { 1, 2 }.SelectMany(new[] { 'a', 'b', 'c' }).ToList();
78 Assert.IsTrue(Enumerable.SequenceEqual(res, new[] { 'a', 'b', 'c', 'a', 'b', 'c' }));
79 }
80 }
81 }