PageRenderTime 40ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/System.Core/Test/System.Linq/EnumerableMoreTest.cs

https://bitbucket.org/steenlund/mono-2.6.7-for-amiga
C# | 2291 lines | 1306 code | 591 blank | 394 comment | 45 complexity | 3b236678c428ead1f3704154f63f7ae3 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, LGPL-2.1
  1. //
  2. // EnumerableMoreTest.cs
  3. //
  4. // Author:
  5. // Andreas Noever <andreas.noever@gmail.com>
  6. //
  7. // (C) 2007 Andreas Noever
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Linq;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Linq {
  34. [TestFixture]
  35. public class EnumerableMoreTest {
  36. class BigEnumerable : IEnumerable<int> {
  37. public readonly ulong Count;
  38. public BigEnumerable (ulong Count)
  39. {
  40. this.Count = Count;
  41. }
  42. #region IEnumerable<int> Members
  43. public IEnumerator<int> GetEnumerator ()
  44. {
  45. return new BigEnumerator (this);
  46. }
  47. #endregion
  48. #region IEnumerable Members
  49. IEnumerator IEnumerable.GetEnumerator ()
  50. {
  51. throw new NotImplementedException ();
  52. }
  53. #endregion
  54. }
  55. class BigEnumerator : IEnumerator<int> {
  56. BigEnumerable Parent;
  57. private ulong current;
  58. public BigEnumerator (BigEnumerable parent)
  59. {
  60. Parent = parent;
  61. }
  62. public int Current
  63. {
  64. get { return 3; }
  65. }
  66. public void Dispose ()
  67. {
  68. }
  69. object IEnumerator.Current
  70. {
  71. get { throw new NotImplementedException (); }
  72. }
  73. public bool MoveNext ()
  74. {
  75. if (current == Parent.Count)
  76. return false;
  77. current++;
  78. return true;
  79. }
  80. public void Reset ()
  81. {
  82. throw new NotImplementedException ();
  83. }
  84. }
  85. public static void AssertException<T> (Action action) where T : Exception
  86. {
  87. try {
  88. action ();
  89. }
  90. catch (T) {
  91. return;
  92. }
  93. Assert.Fail ("Expected: " + typeof (T).Name);
  94. }
  95. static void AssertAreSame<K, V> (K expectedKey, IEnumerable<V> expectedValues, IGrouping<K, V> actual)
  96. {
  97. if (expectedValues == null) {
  98. Assert.IsNull (actual);
  99. return;
  100. }
  101. Assert.IsNotNull (actual);
  102. Assert.AreEqual (expectedKey, actual.Key);
  103. var ee = expectedValues.GetEnumerator ();
  104. var ea = actual.GetEnumerator ();
  105. while (ee.MoveNext ()) {
  106. Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
  107. Assert.AreEqual (ee.Current, ea.Current);
  108. }
  109. if (ea.MoveNext ())
  110. Assert.Fail ("Unexpected element: " + ee.Current);
  111. }
  112. static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, IEnumerable<IGrouping<K, V>> actual)
  113. {
  114. if (expected == null) {
  115. Assert.IsNull (actual);
  116. return;
  117. }
  118. Assert.IsNotNull (actual);
  119. var ee = expected.GetEnumerator ();
  120. var ea = actual.GetEnumerator ();
  121. while (ee.MoveNext ()) {
  122. Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
  123. AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
  124. }
  125. if (ea.MoveNext ())
  126. Assert.Fail ("Unexpected element: " + ee.Current.Key);
  127. }
  128. static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, ILookup<K, V> actual)
  129. {
  130. if (expected == null) {
  131. Assert.IsNull (actual);
  132. return;
  133. }
  134. Assert.IsNotNull (actual);
  135. var ee = expected.GetEnumerator ();
  136. var ea = actual.GetEnumerator ();
  137. while (ee.MoveNext ()) {
  138. Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
  139. AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
  140. }
  141. if (ea.MoveNext ())
  142. Assert.Fail ("Unexpected element: " + ee.Current.Key);
  143. }
  144. static void AssertAreSame<K, V> (IDictionary<K, V> expected, IDictionary<K, V> actual)
  145. {
  146. if (expected == null) {
  147. Assert.IsNull (actual);
  148. return;
  149. }
  150. Assert.IsNotNull (actual);
  151. var ee = expected.GetEnumerator ();
  152. var ea = actual.GetEnumerator ();
  153. while (ee.MoveNext ()) {
  154. Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + ", " + ee.Current.Value + "' expected.");
  155. Assert.AreEqual (ee.Current.Key, ea.Current.Key);
  156. Assert.AreEqual (ee.Current.Value, ea.Current.Value);
  157. }
  158. if (ea.MoveNext ())
  159. Assert.Fail ("Unexpected element: " + ee.Current.Key + ", " + ee.Current.Value);
  160. }
  161. static void AssertAreSame<T> (IEnumerable<T> expected, IEnumerable<T> actual)
  162. {
  163. if (expected == null) {
  164. Assert.IsNull (actual);
  165. return;
  166. }
  167. Assert.IsNotNull (actual);
  168. IEnumerator<T> ee = expected.GetEnumerator ();
  169. IEnumerator<T> ea = actual.GetEnumerator ();
  170. while (ee.MoveNext ()) {
  171. Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
  172. Assert.AreEqual (ee.Current, ea.Current);
  173. }
  174. if (ea.MoveNext ())
  175. Assert.Fail ("Unexpected element: " + ea.Current);
  176. }
  177. [Test]
  178. public void FirstArgumentNullTest ()
  179. {
  180. string [] data = { "2", "1", "5", "3", "4" };
  181. // First<TSource> ()
  182. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).First (); });
  183. // First<TSource> (Func<TSource, bool>)
  184. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).First ((x => true)); });
  185. AssertException<ArgumentNullException> (delegate () { data.First ((Func<string, bool>) null); });
  186. }
  187. [Test]
  188. public void FirstTest ()
  189. {
  190. int [] data = { 2, 1, 5, 3, 4 };
  191. int [] empty = { };
  192. // First<TSource> ()
  193. Assert.AreEqual (2, data.First ());
  194. AssertException<InvalidOperationException> (delegate () { empty.First (); });
  195. // First<TSource> (Func<TSource, bool>)
  196. Assert.AreEqual (5, data.First (x => x == 5));
  197. AssertException<InvalidOperationException> (delegate () { empty.First (x => x == 5); });
  198. AssertException<InvalidOperationException> (delegate () { data.First (x => x == 6); });
  199. }
  200. [Test]
  201. public void FirstOrDefaultArgumentNullTest ()
  202. {
  203. string [] data = { "2", "1", "5", "3", "4" };
  204. // FirstOrDefault<TSource> ()
  205. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).FirstOrDefault (); });
  206. // FirstOrDefault<TSource> (Func<string, bool>)
  207. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).FirstOrDefault ((x => true)); });
  208. AssertException<ArgumentNullException> (delegate () { data.FirstOrDefault ((Func<string, bool>) null); });
  209. }
  210. [Test]
  211. public void FirstOrDefaultTest ()
  212. {
  213. int [] data = { 2, 1, 5, 3, 4 };
  214. int [] empty = { };
  215. // FirstOrDefault<TSource> ()
  216. Assert.AreEqual (2, data.FirstOrDefault ());
  217. Assert.AreEqual (0, empty.FirstOrDefault ());
  218. // FirstOrDefault<TSource> (Func<TSource, bool>)
  219. Assert.AreEqual (5, data.FirstOrDefault (x => x == 5));
  220. Assert.AreEqual (0, empty.FirstOrDefault (x => x == 5));
  221. Assert.AreEqual (0, data.FirstOrDefault (x => x == 6));
  222. }
  223. [Test]
  224. public void LastArgumentNullTest ()
  225. {
  226. string [] data = { "2", "1", "5", "3", "4" };
  227. // Last<TSource> ()
  228. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Last (); });
  229. // Last<TSource> (Func<TSource, bool>)
  230. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Last (x => true); });
  231. AssertException<ArgumentNullException> (delegate () { data.Last ((Func<string, bool>) null); });
  232. }
  233. [Test]
  234. public void LastTest ()
  235. {
  236. int [] data = { 2, 1, 1, 3, 4, 5 };
  237. int [] empty = { };
  238. // Last<TSource> ()
  239. Assert.AreEqual (5, data.Last ());
  240. AssertException<InvalidOperationException> (delegate () { empty.Last (); });
  241. // Last<TSource> (Func<TSource, bool>)
  242. Assert.AreEqual (4, data.Last (x => x < 5));
  243. AssertException<InvalidOperationException> (delegate () { empty.Last (x => x == 5); });
  244. AssertException<InvalidOperationException> (delegate () { data.Last (x => x == 6); });
  245. }
  246. [Test]
  247. public void LastOrDefaultArgumentNullTest ()
  248. {
  249. string [] data = { "2", "1", "5", "3", "4" };
  250. // LastOrDefault<TSource> ()
  251. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LastOrDefault (); });
  252. // LastOrDefault<TSource> (Func<TSource, bool>)
  253. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LastOrDefault (x => true); });
  254. AssertException<ArgumentNullException> (delegate () { data.LastOrDefault ((Func<string, bool>) null); });
  255. }
  256. [Test]
  257. public void LastOrDefaultTest ()
  258. {
  259. int [] data = { 2, 1, 5, 3, 4 };
  260. int [] empty = { };
  261. // LastOrDefault<TSource> ()
  262. Assert.AreEqual (4, data.LastOrDefault ());
  263. Assert.AreEqual (0, empty.LastOrDefault ());
  264. // LastOrDefault<TSource> (Func<TSource, bool>)
  265. Assert.AreEqual (3, data.LastOrDefault (x => x < 4));
  266. Assert.AreEqual (0, empty.LastOrDefault (x => x == 5));
  267. Assert.AreEqual (0, data.LastOrDefault (x => x == 6));
  268. }
  269. [Test]
  270. public void SingleArgumentNullTest ()
  271. {
  272. string [] data = { "2", "1", "5", "3", "4" };
  273. // Single<TSource> ()
  274. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Single (); });
  275. // Single<TSource> (Func<TSource, bool>)
  276. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Single ((x => true)); });
  277. AssertException<ArgumentNullException> (delegate () { data.Single ((Func<string, bool>) null); });
  278. }
  279. [Test]
  280. public void SingleTest ()
  281. {
  282. int [] data = { 2 };
  283. int [] data2 = { 2, 3, 5 };
  284. int [] empty = { };
  285. // Single<TSource> ()
  286. Assert.AreEqual (2, data.Single ());
  287. AssertException<InvalidOperationException> (delegate () { data2.Single (); });
  288. AssertException<InvalidOperationException> (delegate () { empty.Single (); });
  289. // Single<TSource> (Func<TSource, bool>)
  290. Assert.AreEqual (5, data2.Single (x => x == 5));
  291. AssertException<InvalidOperationException> (delegate () { data2.Single (x => false); });
  292. AssertException<InvalidOperationException> (delegate () { data2.Single (x => true); });
  293. AssertException<InvalidOperationException> (delegate () { empty.Single (x => true); });
  294. }
  295. [Test]
  296. public void SingleOrDefaultArgumentNullTest ()
  297. {
  298. string [] data = { "2", "1", "5", "3", "4" };
  299. // SingleOrDefault<TSource> ()
  300. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SingleOrDefault (); });
  301. // SingleOrDefault<TSource> (Func<TSource, bool>)
  302. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SingleOrDefault (x => true); });
  303. AssertException<ArgumentNullException> (delegate () { data.SingleOrDefault ((Func<string, bool>) null); });
  304. }
  305. [Test]
  306. public void SingleOrDefaultTest ()
  307. {
  308. int [] data = { 2 };
  309. int [] data2 = { 2, 3, 5 };
  310. int [] empty = { };
  311. // SingleOrDefault<TSource> ()
  312. Assert.AreEqual (2, data.SingleOrDefault ());
  313. Assert.AreEqual (0, empty.SingleOrDefault ());
  314. AssertException<InvalidOperationException> (delegate () { data2.SingleOrDefault (); });
  315. // SingleOrDefault<TSource> (Func<TSource, bool>)
  316. Assert.AreEqual (3, data2.SingleOrDefault (x => x == 3));
  317. Assert.AreEqual (0, data2.SingleOrDefault (x => false));
  318. AssertException<InvalidOperationException> (delegate () { data2.SingleOrDefault (x => true); });
  319. }
  320. [Test]
  321. public void ElementAtArgumentNullTest ()
  322. {
  323. //string [] data = { "2", "1", "5", "3", "4" };
  324. // ElementAt<TSource> (int)
  325. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ElementAt (0); });
  326. }
  327. [Test]
  328. public void ElementAtTest ()
  329. {
  330. int [] data = { 2, 3, 4, 5 };
  331. // ElementAt<string> (int)
  332. Assert.AreEqual (2, data.ElementAt (0));
  333. Assert.AreEqual (4, data.ElementAt (2));
  334. AssertException<ArgumentOutOfRangeException> (delegate () { data.ElementAt (-1); });
  335. AssertException<ArgumentOutOfRangeException> (delegate () { data.ElementAt (4); });
  336. AssertException<ArgumentOutOfRangeException> (delegate () { data.ElementAt (6); });
  337. }
  338. [Test]
  339. public void ElementAtOrDefaultArgumentNullTest ()
  340. {
  341. //string [] data = { "2", "1", "5", "3", "4" };
  342. // ElementAtOrDefault<TSource> (int)
  343. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ElementAtOrDefault (0); });
  344. }
  345. [Test]
  346. public void ElementAtOrDefaultTest ()
  347. {
  348. int [] data = { 2, 3, 4, 5 };
  349. int [] empty = { };
  350. // ElementAtOrDefault<TSource> (int)
  351. Assert.AreEqual (2, data.ElementAtOrDefault (0));
  352. Assert.AreEqual (4, data.ElementAtOrDefault (2));
  353. Assert.AreEqual (0, data.ElementAtOrDefault (-1));
  354. Assert.AreEqual (0, data.ElementAtOrDefault (4));
  355. Assert.AreEqual (0, empty.ElementAtOrDefault (4));
  356. }
  357. [Test]
  358. public void EmptyTest ()
  359. {
  360. IEnumerable<string> empty = Enumerable.Empty<string> ();
  361. Assert.IsFalse (empty.GetEnumerator ().MoveNext ());
  362. }
  363. [Test]
  364. public void AnyArgumentNullTest ()
  365. {
  366. string [] data = { "2", "1", "5", "3", "4" };
  367. // Any<TSource> ()
  368. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Any (); });
  369. // Any<TSource> (Func<TSource, bool>)
  370. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Any (x => true); });
  371. AssertException<ArgumentNullException> (delegate () { data.Any ((Func<string, bool>) null); });
  372. }
  373. [Test]
  374. public void AnyTest ()
  375. {
  376. int [] data = { 5, 2, 3, 1, 6 };
  377. int [] empty = { };
  378. // Any<TSource> ()
  379. Assert.IsTrue (data.Any ());
  380. Assert.IsFalse (empty.Any ());
  381. // Any<TSource> (Func<TSource, bool>)
  382. Assert.IsTrue (data.Any (x => x == 5));
  383. Assert.IsFalse (data.Any (x => x == 9));
  384. Assert.IsFalse (empty.Any (x => true));
  385. }
  386. [Test]
  387. public void AllArgumentNullTest ()
  388. {
  389. string [] data = { "2", "1", "5", "3", "4" };
  390. // All<TSource> (Func<TSource, bool>)
  391. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).All (x => true); });
  392. AssertException<ArgumentNullException> (delegate () { data.All ((Func<string, bool>) null); });
  393. }
  394. [Test]
  395. public void AllTest ()
  396. {
  397. int [] data = { 5, 2, 3, 1, 6 };
  398. int [] empty = { };
  399. // All<TSource> (Func<TSource, bool>)
  400. Assert.IsTrue (data.All (x => true));
  401. Assert.IsFalse (data.All (x => x != 1));
  402. Assert.IsTrue (empty.All (x => false));
  403. }
  404. [Test]
  405. public void CountArgumentNullTest ()
  406. {
  407. string [] data = { "2", "1", "5", "3", "4" };
  408. // Count<TSource> ()
  409. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Count (); });
  410. // Count<TSource> (Func<TSource, bool>)
  411. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Count (x => true); });
  412. AssertException<ArgumentNullException> (delegate () { data.Count ((Func<string, bool>) null); });
  413. }
  414. [Test]
  415. public void CountTest ()
  416. {
  417. int [] data = { 5, 2, 3, 1, 6 };
  418. // Count<TSource> ()
  419. Assert.AreEqual (5, data.Count ());
  420. // Count<TSource> (Func<TSource, bool>)
  421. Assert.AreEqual (3, data.Count (x => x < 5));
  422. }
  423. //[Test]
  424. public void CountOverflowTest ()
  425. {
  426. //BigEnumerable data = new BigEnumerable ((ulong) int.MaxValue + 1);
  427. // Count<TSource> ()
  428. //AssertException<OverflowException> (delegate () { data.Count (); });
  429. // Count<TSource> (Func<TSource, bool>)
  430. //AssertException<OverflowException> (delegate () { data.Count (x => 3 == x); });
  431. // Documentation error: http://msdn2.microsoft.com/en-us/library/bb535181.aspx
  432. // An exception is only rasied if count > int.MaxValue. Not if source contains more than int.MaxValue elements.
  433. // AssertException<OverflowException> (delegate () { data.Count (x => 5 == x); });
  434. }
  435. [Test]
  436. public void LongCountArgumentNullTest ()
  437. {
  438. string [] data = { "2", "1", "5", "3", "4" };
  439. // LongCount<TSource> ()
  440. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LongCount (); });
  441. // LongCount<TSource> (Func<TSource, bool>)
  442. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LongCount (x => true); });
  443. AssertException<ArgumentNullException> (delegate () { data.LongCount ((Func<string, bool>) null); });
  444. }
  445. [Test]
  446. public void LongCountTest ()
  447. {
  448. int [] data = { 5, 2, 3, 1, 6 };
  449. //TODO: Overflow test...
  450. // LongCount<TSource> ()
  451. Assert.AreEqual (5, data.LongCount ());
  452. Assert.AreEqual (5, Enumerable.Range (0, 5).LongCount ());
  453. // LongCount<TSource> (Func<TSource, bool>)
  454. Assert.AreEqual (3, data.LongCount (x => x < 5));
  455. }
  456. [Test]
  457. public void ContainsArgumentNullTest ()
  458. {
  459. //string [] data = { "2", "1", "5", "3", "4" };
  460. // Contains<TSource> (TSource)
  461. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Contains ("2"); });
  462. // Contains<TSource> (TSource, IEqualityComparer<TSource>)
  463. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Contains ("2", (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  464. }
  465. [Test]
  466. public void ContainsTest ()
  467. {
  468. int [] data = { 5, 2, 3, 1, 6 };
  469. // Contains<TSource> (TSource)
  470. Assert.IsTrue (data.Contains (2));
  471. Assert.IsFalse (data.Contains (0));
  472. // Contains<TSource> (TSource, IEqualityComparer<TSource>)
  473. Assert.IsTrue (data.Contains (2, EqualityComparer<int>.Default));
  474. Assert.IsFalse (data.Contains (0, EqualityComparer<int>.Default));
  475. }
  476. [Test]
  477. public void AggregateArgumentNullTest ()
  478. {
  479. string [] data = { "2", "1", "5", "3", "4" };
  480. // Aggregate<TSource> (Func<TSource, TSource, TSource>)
  481. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ((x, y) => "test"); });
  482. AssertException<ArgumentNullException> (delegate () { data.Aggregate ((Func<string, string, string>) null); });
  483. // Aggregate<TSource,TAccumulate> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
  484. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ("initial", (x, y) => "test"); });
  485. AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (Func<string, string, string>) null); });
  486. // Aggregate<TSource,TAccumulate,TResult> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)
  487. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ("initial", (x, y) => "test", x => "test"); });
  488. AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (Func<string, string, string>) null, x => "test"); });
  489. AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (x, y) => "test", (Func<string, string>) null); });
  490. }
  491. [Test]
  492. public void AggregateTest ()
  493. {
  494. string [] data = { "2", "1", "5", "3", "4" };
  495. string [] empty = { };
  496. // Aggregate<TSource> (Func<TSource, TSource, TSource>)
  497. Assert.AreEqual ("21534", data.Aggregate ((x, y) => x + y));
  498. AssertException<InvalidOperationException> (delegate () { empty.Aggregate ((x, y) => x + y); }); //only this overload throws
  499. // Aggregate<TSource,TAccumulate> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
  500. Assert.AreEqual ("initial21534", (data.Aggregate ("initial", (x, y) => x + y)));
  501. // Aggregate<TSource,TAccumulate,TResult> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)
  502. Assert.AreEqual ("INITIAL21534", data.Aggregate ("initial", (x, y) => x + y, (x => x.ToUpper ())));
  503. }
  504. [Test]
  505. public void SumArgumentNullTest ()
  506. {
  507. string [] data = { "2", "1", "5", "3", "4" };
  508. // Sum<TSource> (Func<TSource, int>)
  509. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, int>) (x => 0)); });
  510. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, int>) null); });
  511. // Sum<TSource> (Func<TSource, Nullable<int>>)
  512. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
  513. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<int>>) null); });
  514. // Sum<TSource> (Func<TSource, Int64>)
  515. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Int64>) (x => 0L)); });
  516. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Int64>) null); });
  517. // Sum<TSource> (Func<TSource, Nullable<Int64>>)
  518. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
  519. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Int64>>) null); });
  520. // Sum<TSource> (Func<TSource, Single>)
  521. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Single>) (x => 0f)); });
  522. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Single>) null); });
  523. // Sum<TSource> (Func<TSource, Nullable<Single>>)
  524. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
  525. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Single>>) null); });
  526. // Sum<TSource> (Func<TSource, Double>)
  527. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Double>) (x => 0d)); });
  528. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Double>) null); });
  529. // Sum<TSource> (Func<TSource, Nullable<Double>>)
  530. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
  531. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Double>>) null); });
  532. // Sum<TSource> (Func<TSource, Decimal>)
  533. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Decimal>) (x => 0m)); });
  534. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Decimal>) null); });
  535. // Sum<TSource> (Func<TSource, Nullable<Decimal>>)
  536. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
  537. AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Decimal>>) null); });
  538. // Sum (IEnumerable<int>)
  539. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Sum (); });
  540. // Sum (IEnumerable<int?>)
  541. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Sum (); });
  542. // Sum (IEnumerable<long>)
  543. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Sum (); });
  544. // Sum (IEnumerable<long?>)
  545. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Sum (); });
  546. // Sum (IEnumerable<float>)
  547. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Sum (); });
  548. // Sum (IEnumerable<float?>)
  549. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Sum (); });
  550. // Sum (IEnumerable<double>)
  551. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Sum (); });
  552. // Sum (IEnumerable<double?>)
  553. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Sum (); });
  554. // Sum (IEnumerable<decimal>)
  555. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Sum (); });
  556. // Sum (IEnumerable<decimal?>)
  557. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Sum (); });
  558. }
  559. [Test]
  560. public void SumTest ()
  561. {
  562. string [] data = { "2", "3", "5", "5" };
  563. //TODO: OverflowException
  564. // Sum<TSource> (Func<TSource, int>)
  565. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, int>) (x => int.Parse (x))));
  566. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, int>) (x => int.Parse (x))));
  567. // Sum<TSource> (Func<TSource, Nullable<int>>)
  568. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  569. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  570. // Sum<TSource> (Func<TSource, Int64>)
  571. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
  572. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
  573. // Sum<TSource> (Func<TSource, Nullable<Int64>>)
  574. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
  575. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
  576. // Sum<TSource> (Func<TSource, Single>)
  577. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
  578. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
  579. // Sum<TSource> (Func<TSource, Nullable<Single>>)
  580. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
  581. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
  582. // Sum<TSource> (Func<TSource, Double>)
  583. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
  584. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
  585. // Sum<TSource> (Func<TSource, Nullable<Double>>)
  586. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
  587. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
  588. // Sum<TSource> (Func<TSource, Decimal>)
  589. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
  590. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
  591. // Sum<TSource> (Func<TSource, Nullable<Decimal>>)
  592. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
  593. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
  594. // Sum<> ()
  595. Assert.AreEqual (6, ((IEnumerable<int>) new int [] { 1, 2, 3 }).Sum ());
  596. Assert.AreEqual (0, Enumerable.Empty<int> ().Sum ());
  597. // Sum<> ()
  598. Assert.AreEqual (6, ((IEnumerable<Nullable<int>>) new int? [] { 1, 2, 3 }).Sum ());
  599. Assert.AreEqual (0, Enumerable.Empty<int?> ().Sum ());
  600. // Sum<> ()
  601. Assert.AreEqual (6, ((IEnumerable<Int64>) new long [] { 1, 2, 3 }).Sum ());
  602. Assert.AreEqual (0, Enumerable.Empty<long> ().Sum ());
  603. // Sum<> ()
  604. Assert.AreEqual (6, ((IEnumerable<Nullable<Int64>>) new long? [] { 1, 2, 3 }).Sum ());
  605. Assert.AreEqual (0, Enumerable.Empty<long?> ().Sum ());
  606. // Sum<> ()
  607. Assert.AreEqual (6, ((IEnumerable<Single>) new float [] { 1, 2, 3 }).Sum ());
  608. Assert.AreEqual (0, Enumerable.Empty<float> ().Sum ());
  609. // Sum<> ()
  610. Assert.AreEqual (6, ((IEnumerable<Nullable<Single>>) new float? [] { 1, 2, 3 }).Sum ());
  611. Assert.AreEqual (0, Enumerable.Empty<float?> ().Sum ());
  612. // Sum<> ()
  613. Assert.AreEqual (6, ((IEnumerable<Double>) new double [] { 1, 2, 3 }).Sum ());
  614. Assert.AreEqual (0, Enumerable.Empty<double> ().Sum ());
  615. // Sum<> ()
  616. Assert.AreEqual (6, ((IEnumerable<Nullable<Double>>) new double? [] { 1, 2, 3 }).Sum ());
  617. Assert.AreEqual (0, Enumerable.Empty<double?> ().Sum ());
  618. // Sum<> ()
  619. Assert.AreEqual (6, ((IEnumerable<Decimal>) new decimal [] { 1, 2, 3 }).Sum ());
  620. Assert.AreEqual (0, Enumerable.Empty<decimal> ().Sum ());
  621. // Sum<> ()
  622. Assert.AreEqual (6, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 1, 2, 3 }).Sum ());
  623. Assert.AreEqual (0, Enumerable.Empty<decimal?> ().Sum ());
  624. }
  625. [Test]
  626. public void MinArgumentNullTest ()
  627. {
  628. string [] data = { "2", "1", "5", "3", "4" };
  629. // Min<TSource> ()
  630. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> (); });
  631. // Min<TSource> (Func<TSource, int>)
  632. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, int>) (x => 0)); });
  633. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, int>) null); });
  634. // Min<TSource> (Func<TSource, Nullable<int>>)
  635. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
  636. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<int>>) null); });
  637. // Min<TSource> (Func<TSource, Int64>)
  638. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Int64>) (x => 0L)); });
  639. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Int64>) null); });
  640. // Min<TSource> (Func<TSource, Nullable<Int64>>)
  641. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
  642. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Int64>>) null); });
  643. // Min<TSource> (Func<TSource, Single>)
  644. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Single>) (x => 0f)); });
  645. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Single>) null); });
  646. // Min<TSource> (Func<TSource, Nullable<Single>>)
  647. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
  648. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Single>>) null); });
  649. // Min<TSource> (Func<TSource, Double>)
  650. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Double>) (x => 0d)); });
  651. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Double>) null); });
  652. // Min<TSource> (Func<TSource, Nullable<Double>>)
  653. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
  654. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Double>>) null); });
  655. // Min<TSource> (Func<TSource, Decimal>)
  656. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Decimal>) (x => 0m)); });
  657. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Decimal>) null); });
  658. // Min<TSource> (Func<TSource, Nullable<Decimal>>)
  659. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
  660. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Decimal>>) null); });
  661. // Min<TSource,TSource> (Func<TSource, string>)
  662. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string, string> ((Func<string, string>) (x => "test")); });
  663. AssertException<ArgumentNullException> (delegate () { data.Min<string, string> ((Func<string, string>) null); });
  664. // Min<> ()
  665. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Min (); });
  666. // Min<> ()
  667. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Min (); });
  668. // Min<> ()
  669. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Min (); });
  670. // Min<> ()
  671. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Min (); });
  672. // Min<> ()
  673. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Min (); });
  674. // Min<> ()
  675. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Min (); });
  676. // Min<> ()
  677. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Min (); });
  678. // Min<> ()
  679. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Min (); });
  680. // Min<> ()
  681. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Min (); });
  682. // Min<> ()
  683. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Min (); });
  684. }
  685. [Test]
  686. public void MinTest ()
  687. {
  688. string [] data = { "2", "1", "5", "3", "4" };
  689. // Min<TSource> ()
  690. Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string> ());
  691. // Min<TSource> (Func<TSource, int>)
  692. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, int>) (x => int.Parse (x))));
  693. // Min<TSource> (Func<TSource, Nullable<int>>)
  694. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  695. // Min<TSource> (Func<TSource, Int64>)
  696. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Int64>) (x => int.Parse (x))));
  697. // Min<TSource> (Func<TSource, Nullable<Int64>>)
  698. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
  699. // Min<TSource> (Func<TSource, Single>)
  700. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Single>) (x => int.Parse (x))));
  701. // Min<TSource> (Func<TSource, Nullable<Single>>)
  702. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
  703. // Min<TSource> (Func<TSource, Double>)
  704. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Double>) (x => int.Parse (x))));
  705. // Min<TSource> (Func<TSource, Nullable<Double>>)
  706. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
  707. // Min<TSource> (Func<TSource, Decimal>)
  708. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Decimal>) (x => int.Parse (x))));
  709. // Min<TSource> (Func<TSource, Nullable<Decimal>>)
  710. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
  711. // Min<TSource,TSource> (Func<TSource, TSource>)
  712. Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string, string> ((Func<string, string>) (x => x)));
  713. // Min<> ()
  714. Assert.AreEqual (2, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Min ());
  715. // Min<> ()
  716. Assert.AreEqual (2, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Min ());
  717. // Min<> ()
  718. Assert.AreEqual (2, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Min ());
  719. // Min<> ()
  720. Assert.AreEqual (2, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Min ());
  721. // Min<> ()
  722. Assert.AreEqual (2, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Min ());
  723. // Min<> ()
  724. Assert.AreEqual (2, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Min ());
  725. // Min<> ()
  726. Assert.AreEqual (2, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Min ());
  727. // Min<> ()
  728. Assert.AreEqual (2, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Min ());
  729. // Min<> ()
  730. Assert.AreEqual (2, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Min ());
  731. // Min<> ()
  732. Assert.AreEqual (2, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Min ());
  733. }
  734. [Test]
  735. public void MaxArgumentNullTest ()
  736. {
  737. string [] data = { "2", "1", "5", "3", "4" };
  738. // Max<TSource> ()
  739. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> (); });
  740. // Max<TSource> (Func<TSource, int>)
  741. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, int>) (x => 0)); });
  742. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, int>) null); });
  743. // Max<TSource> (Func<TSource, Nullable<int>>)
  744. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
  745. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<int>>) null); });
  746. // Max<TSource> (Func<TSource, Int64>)
  747. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Int64>) (x => 0L)); });
  748. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Int64>) null); });
  749. // Max<TSource> (Func<TSource, Nullable<Int64>>)
  750. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
  751. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Int64>>) null); });
  752. // Max<TSource> (Func<TSource, Single>)
  753. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Single>) (x => 0f)); });
  754. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Single>) null); });
  755. // Max<TSource> (Func<TSource, Nullable<Single>>)
  756. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
  757. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Single>>) null); });
  758. // Max<TSource> (Func<TSource, Double>)
  759. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Double>) (x => 0d)); });
  760. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Double>) null); });
  761. // Max<TSource> (Func<TSource, Nullable<Double>>)
  762. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
  763. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Double>>) null); });
  764. // Max<TSource> (Func<TSource, Decimal>)
  765. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Decimal>) (x => 0m)); });
  766. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Decimal>) null); });
  767. // Max<TSource> (Func<TSource, Nullable<Decimal>>)
  768. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
  769. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Decimal>>) null); });
  770. // Max<TSource,TSource> (Func<TSource, TSource>)
  771. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string, string> ((Func<string, string>) (x => "test")); });
  772. AssertException<ArgumentNullException> (delegate () { data.Max<string, string> ((Func<string, string>) null); });
  773. // Max<> ()
  774. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Max (); });
  775. // Max<> ()
  776. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Max (); });
  777. // Max<> ()
  778. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Max (); });
  779. // Max<> ()
  780. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Max (); });
  781. // Max<> ()
  782. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Max (); });
  783. // Max<> ()
  784. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Max (); });
  785. // Max<> ()
  786. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Max (); });
  787. // Max<> ()
  788. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Max (); });
  789. // Max<> ()
  790. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Max (); });
  791. // Max<> ()
  792. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Max (); });
  793. }
  794. [Test]
  795. public void MaxTest ()
  796. {
  797. string [] data = { "2", "1", "5", "3", "4" };
  798. // Max<string> ()
  799. Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string> ());
  800. // Max<TSource> (Func<TSource, int>)
  801. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, int>) (x => int.Parse (x))));
  802. // Max<TSource> (Func<TSource, Nullable<int>>)
  803. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  804. // Max<TSource> (Func<TSource, Int64>)
  805. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Int64>) (x => int.Parse (x))));
  806. // Max<TSource> (Func<TSource, Nullable<Int64>>)
  807. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
  808. // Max<TSource> (Func<TSource, Single>)
  809. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Single>) (x => int.Parse (x))));
  810. // Max<TSource> (Func<TSource, Nullable<Single>>)
  811. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
  812. // Max<TSource> (Func<TSource, Double>)
  813. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Double>) (x => int.Parse (x))));
  814. // Max<TSource> (Func<TSource, Nullable<Double>>)
  815. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
  816. // Max<TSource> (Func<TSource, Decimal>)
  817. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Decimal>) (x => int.Parse (x))));
  818. // Max<TSource> (Func<TSource, Nullable<Decimal>>)
  819. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
  820. // Max<TSource,TSource> (Func<TSource, TSource>)
  821. Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string, string> ((Func<string, string>) (x => x)));
  822. // Max<> ()
  823. Assert.AreEqual (4, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Max ());
  824. // Max<> ()
  825. Assert.AreEqual (4, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Max ());
  826. // Max<> ()
  827. Assert.AreEqual (4, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Max ());
  828. // Max<> ()
  829. Assert.AreEqual (4, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Max ());
  830. // Max<> ()
  831. Assert.AreEqual (4, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Max ());
  832. // Max<> ()
  833. Assert.AreEqual (4, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Max ());
  834. // Max<> ()
  835. Assert.AreEqual (4, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Max ());
  836. // Max<> ()
  837. Assert.AreEqual (4, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Max ());
  838. // Max<> ()
  839. Assert.AreEqual (4, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Max ());
  840. // Max<> ()
  841. Assert.AreEqual (4, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Max ());
  842. }
  843. [Test]
  844. public void AverageArgumentNullTest ()
  845. {
  846. string [] data = { "2", "1", "5", "3", "4" };
  847. // Average<TSource> (Func<TSource, int>)
  848. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, int>) (x => 0)); });
  849. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, int>) null); });
  850. // Average<TSource> (Func<TSource, Nullable<int>>)
  851. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
  852. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<int>>) null); });
  853. // Average<TSource> (Func<TSource, Int64>)
  854. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Int64>) (x => 0L)); });
  855. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Int64>) null); });
  856. // Average<TSource> (Func<TSource, Nullable<Int64>>)
  857. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
  858. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Int64>>) null); });
  859. // Average<TSource> (Func<TSource, Single>)
  860. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Single>) (x => 0f)); });
  861. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Single>) null); });
  862. // Average<TSource> (Func<TSource, Nullable<Single>>)
  863. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
  864. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Single>>) null); });
  865. // Average<TSource> (Func<TSource, Double>)
  866. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Double>) (x => 0d)); });
  867. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Double>) null); });
  868. // Average<TSource> (Func<TSource, Nullable<Double>>)
  869. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
  870. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Double>>) null); });
  871. // Average<TSource> (Func<TSource, Decimal>)
  872. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Decimal>) (x => 0m)); });
  873. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Decimal>) null); });
  874. // Average<TSource> (Func<TSource, Nullable<Decimal>>)
  875. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
  876. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Decimal>>) null); });
  877. // Average<> ()
  878. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Average (); });
  879. // Average<> ()
  880. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Average (); });
  881. // Average<> ()
  882. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Average (); });
  883. // Average<> ()
  884. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Average (); });
  885. // Average<> ()
  886. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Average (); });
  887. // Average<> ()
  888. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Average (); });
  889. // Average<> ()
  890. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Average (); });
  891. // Average<> ()
  892. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Average (); });
  893. // Average<> ()
  894. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Average (); });
  895. // Average<> ()
  896. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Average (); });
  897. }
  898. [Test]
  899. public void AverageTest ()
  900. {
  901. string [] data = { "2", "1", "5", "3", "4" };
  902. string [] empty = { };
  903. // Average<string> (Func<string, int>)
  904. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, int>) (x => int.Parse (x))));
  905. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, int>) (x => int.Parse (x))); });
  906. // Average<TSource> (Func<TSource, Nullable<int>>)
  907. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  908. // Average<TSource> (Func<TSource, Int64>)
  909. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long>) (x => int.Parse (x))));
  910. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, long>) (x => int.Parse (x))); });
  911. // Average<TSource> (Func<TSource, Nullable<Int64>>)
  912. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long?>) (x => (int?) int.Parse (x))));
  913. // Average<TSource> (Func<TSource, Single>)
  914. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float>) (x => int.Parse (x))));
  915. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, float>) (x => int.Parse (x))); });
  916. // Average<TSource> (Func<TSource, Nullable<Single>>)
  917. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float?>) (x => (int?) int.Parse (x))));
  918. // Average<TSource> (Func<TSource, Double>)
  919. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double>) (x => int.Parse (x))));
  920. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, double>) (x => int.Parse (x))); });
  921. // Average<TSource> (Func<TSource, Nullable<Double>>)
  922. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double?>) (x => (int?) int.Parse (x))));
  923. // Average<TSource> (Func<TSource, Decimal>)
  924. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal>) (x => int.Parse (x))));
  925. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, decimal>) (x => int.Parse (x))); });
  926. // Average<TSource> (Func<TSource, Nullable<Decimal>>)
  927. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal?>) (x => (int?) int.Parse (x))));
  928. // Average<> ()
  929. Assert.AreEqual (3, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Average ());
  930. AssertException<InvalidOperationException> (delegate () { new int [0].Average (); });
  931. // Average<> ()
  932. Assert.AreEqual (3, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Average ());
  933. // Average<> ()
  934. Assert.AreEqual (3, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Average ());
  935. AssertException<InvalidOperationException> (delegate () { new long [0].Average (); });
  936. // Average<> ()
  937. Assert.AreEqual (3, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Average ());
  938. // Average<> ()
  939. Assert.AreEqual (3, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Average ());
  940. AssertException<InvalidOperationException> (delegate () { new float [0].Average (); });
  941. // Average<> ()
  942. Assert.AreEqual (3, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Average ());
  943. // Average<> ()
  944. Assert.AreEqual (3, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Average ());
  945. AssertException<InvalidOperationException> (delegate () { new double [0].Average (); });
  946. // Average<> ()
  947. Assert.AreEqual (3, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Average ());
  948. // Average<> ()
  949. Assert.AreEqual (3, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Average ());
  950. AssertException<InvalidOperationException> (delegate () { new decimal [0].Average (); });
  951. // Average<> ()
  952. Assert.AreEqual (3, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Average ());
  953. }
  954. [Test]
  955. public void WhereArgumentNullTest ()
  956. {
  957. string [] data = { "2", "1", "5", "3", "4" };
  958. // Where<TSource> (Func<TSource, bool>)
  959. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where (x => true); });
  960. AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, bool>) null); });
  961. // Where<TSource> (Func<TSource, int, bool>)
  962. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where ((x, y) => true); });
  963. AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, int, bool>) null); });
  964. }
  965. [Test]
  966. public void WhereTest ()
  967. {
  968. int [] data = { 2, 1, 5, 3, 4 };
  969. int [] expected1 = { 2, 1 };
  970. int [] expected2 = { 2 };
  971. // Where<TSource> (Func<TSource, bool>)
  972. AssertAreSame (expected1, data.Where (x => x < 3));
  973. // Where<TSource> (Func<TSource, int, bool>)
  974. AssertAreSame (expected2, data.Where ((x, y) => x < 3 && y != 1));
  975. }
  976. [Test]
  977. public void SelectArgumentNullTest ()
  978. {
  979. string [] data = { "2", "1", "5", "3", "4" };
  980. // Select<TSource,TResult> (Func<TSource, TResult>)
  981. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select (x => "test"); });
  982. AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, string>) null); });
  983. // Select<TSource,TResult> (Func<TSource, int, TResult>)
  984. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select ((x, y) => "test"); });
  985. AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, int, string>) null); });
  986. }
  987. [Test]
  988. public void SelectTest ()
  989. {
  990. string [] data = { "2", "1", "5", "3", "4" };
  991. string [] expected1 = { "2x", "1x", "5x", "3x", "4x" };
  992. string [] expected2 = { "2x0", "1x1", "5x2", "3x3", "4x4" };
  993. // Select<TSource,TResult> (Func<TSource, TResult>)
  994. AssertAreSame (expected1, data.Select<string, string> (x => x + "x"));
  995. // Select<TSource,TResult> (Func<TSource, int, TResult>)
  996. AssertAreSame (expected2, data.Select<string, string> ((x, y) => x + "x" + y));
  997. }
  998. [Test]
  999. public void SelectManyArgumentNullTest ()
  1000. {
  1001. string [] data = { "2", "1", "5", "3", "4" };
  1002. // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
  1003. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data); });
  1004. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null); });
  1005. // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
  1006. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data); });
  1007. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null); });
  1008. // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
  1009. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data, (x, y) => "test"); });
  1010. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null, (x, y) => "test"); });
  1011. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((x, y) => data, (Func<string, string, string>) null); });
  1012. // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
  1013. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data, (x, y) => "test"); });
  1014. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null, (x, y) => "test"); });
  1015. AssertException<ArgumentNullException> (delegate () { data.SelectMany (x => data, (Func<string, string, string>) null); });
  1016. }
  1017. [Test]
  1018. public void SelectManyTest ()
  1019. {
  1020. string [] data = { "0", "1" };
  1021. string [] expected = { "0", "00", "1", "11" };
  1022. // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
  1023. AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }));
  1024. // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
  1025. AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }));
  1026. // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
  1027. AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }, (x, y) => y));
  1028. // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
  1029. AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }, (x, y) => y));
  1030. }
  1031. [Test]
  1032. public void TakeArgumentNullTest ()
  1033. {
  1034. //string [] data = { "2", "1", "5", "3", "4" };
  1035. // Take<TSource> (int)
  1036. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Take (0); });
  1037. }
  1038. [Test]
  1039. public void TakeTest ()
  1040. {
  1041. int [] data = { 2, 1, 5, 3, 1 };
  1042. int [] expected = { 2, 1 };
  1043. int [] empty = { };
  1044. // Take<TSource> (int)
  1045. AssertAreSame (expected, data.Take (2));
  1046. AssertAreSame (empty, data.Take (-2));
  1047. }
  1048. [Test]
  1049. public void TakeWhileArgumentNullTest ()
  1050. {
  1051. string [] data = { "2", "1", "5", "3", "4" };
  1052. // TakeWhile<TSource> (Func<TSource, bool>)
  1053. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile (x => true); });
  1054. AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, bool>) null); });
  1055. // TakeWhile<TSource> (Func<TSource, int, bool>)
  1056. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile ((x, y) => true); });
  1057. AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, int, bool>) null); });
  1058. }
  1059. [Test]
  1060. public void TakeWhileTest ()
  1061. {
  1062. int [] data = { 2, 1, 5, 3, 1 };
  1063. int [] expected = { 2, 1 };
  1064. // TakeWhile<TSource> (Func<TSource, bool>)
  1065. AssertAreSame (expected, data.TakeWhile (x => x != 5));
  1066. // TakeWhile<TSource> (Func<TSource, int, bool>)
  1067. AssertAreSame (expected, data.TakeWhile ((x, y) => y != 2));
  1068. }
  1069. [Test]
  1070. public void SkipArgumentNullTest ()
  1071. {
  1072. //string [] data = { "2", "1", "5", "3", "4" };
  1073. // Skip<TSource> (int)
  1074. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Skip (0); });
  1075. }
  1076. [Test]
  1077. public void SkipTest ()
  1078. {
  1079. int [] data = { 2, 1, 5, 3, 1 };
  1080. int [] expected = { 5, 3, 1 };
  1081. // Skip<string> (TSource)
  1082. AssertAreSame (expected, data.Skip (2));
  1083. AssertAreSame (data, data.Skip (-2));
  1084. }
  1085. [Test]
  1086. public void SkipWhileArgumentNullTest ()
  1087. {
  1088. string [] data = { "2", "1", "5", "3", "4" };
  1089. // SkipWhile<TSource> (Func<TSource, bool>)
  1090. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile (x => true); });
  1091. AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, bool>) null); });
  1092. // SkipWhile<TSource> (Func<TSource, int, bool>)
  1093. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile ((x, y) => true); });
  1094. AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, int, bool>) null); });
  1095. }
  1096. [Test]
  1097. public void SkipWhileTest ()
  1098. {
  1099. int [] data = { 2, 1, 5, 3, 1 };
  1100. int [] expected = { 5, 3, 1 };
  1101. // SkipWhile<TSource> (Func<TSource, bool>)
  1102. AssertAreSame (expected, data.SkipWhile (x => x != 5));
  1103. // SkipWhile<TSource> (Func<TSource, int, bool>)
  1104. AssertAreSame (expected, data.SkipWhile ((x, y) => y != 2));
  1105. }
  1106. [Test]
  1107. public void JoinArgumentNullTest ()
  1108. {
  1109. string [] data = { "2", "1", "5", "3", "4" };
  1110. // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
  1111. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test"); });
  1112. AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
  1113. AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
  1114. AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
  1115. AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null); });
  1116. // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
  1117. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1118. AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1119. AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1120. AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
  1121. AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null, EqualityComparer<string>.Default); });
  1122. }
  1123. [Test]
  1124. public void JoinTest ()
  1125. {
  1126. string [] dataOuter1 = { "2", "1", "5", "3", "4" };
  1127. string [] dataInner1 = { "7", "3", "5", "8", "9" };
  1128. string [] expected1 = { "55", "33" };
  1129. string [] dataOuter2 = { "2", "1", "3", "4" };
  1130. string [] dataInner2 = { "7", "5", "8", "9" };
  1131. string [] expected2 = { };
  1132. // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
  1133. AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y));
  1134. AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y));
  1135. // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
  1136. AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
  1137. AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
  1138. }
  1139. [Test]
  1140. public void GroupJoinArgumentNullTest ()
  1141. {
  1142. string [] data = { "2", "1", "5", "3", "4" };
  1143. // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
  1144. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test"); });
  1145. AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
  1146. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
  1147. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
  1148. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null); });
  1149. // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
  1150. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1151. AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1152. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1153. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
  1154. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null, EqualityComparer<string>.Default); });
  1155. }
  1156. [Test]
  1157. public void GroupJoinTest ()
  1158. {
  1159. string [] dataOuter1 = { "2", "1", "5", "3", "4" };
  1160. string [] dataInner1 = { "7", "3", "5", "3", "9" };
  1161. string [] expected1 = { "2", "1", "55", "333", "4" };
  1162. string [] dataOuter2 = { "2", "1", "5", "8", "4" };
  1163. string [] dataInner2 = { "7", "3", "6", "3", "9" };
  1164. string [] expected2 = { "2", "1", "5", "8", "4" };
  1165. // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
  1166. AssertAreSame (expected1, (dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
  1167. AssertAreSame (expected2, (dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
  1168. // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
  1169. AssertAreSame (expected1, dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
  1170. AssertAreSame (expected2, dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
  1171. }
  1172. [Test]
  1173. public void OrderByArgumentNullTest ()
  1174. {
  1175. string [] data = { "2", "1", "5", "3", "4" };
  1176. // OrderBy<TSource,TKey> (Func<TSource, TKey>)
  1177. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test"); });
  1178. AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null); });
  1179. // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1180. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test", Comparer<string>.Default); });
  1181. AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null, Comparer<string>.Default); });
  1182. }
  1183. [Test]
  1184. public void OrderByTest ()
  1185. {
  1186. int [] data = { 2, 1, 5, 3, 4 };
  1187. int [] expected = { 1, 2, 3, 4, 5 };
  1188. // OrderBy<TSource,TKey> (Func<TSource, TKey>)
  1189. AssertAreSame (expected, data.OrderBy (x => x));
  1190. // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1191. AssertAreSame (expected, data.OrderBy (x => x, Comparer<int>.Default));
  1192. }
  1193. [Test]
  1194. public void OrderByDescendingArgumentNullTest ()
  1195. {
  1196. string [] data = { "2", "1", "5", "3", "4" };
  1197. // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
  1198. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test"); });
  1199. AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null); });
  1200. // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1201. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test", Comparer<string>.Default); });
  1202. AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null, Comparer<string>.Default); });
  1203. }
  1204. [Test]
  1205. public void OrderByDescendingTest ()
  1206. {
  1207. int [] data = { 2, 1, 5, 3, 4 };
  1208. int [] expected = { 5, 4, 3, 2, 1 };
  1209. // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
  1210. AssertAreSame (expected, data.OrderByDescending (x => x));
  1211. // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1212. AssertAreSame (expected, data.OrderByDescending (x => x, Comparer<int>.Default));
  1213. }
  1214. [Test]
  1215. public void ThenByArgumentNullTest ()
  1216. {
  1217. string [] data = { "2", "1", "5", "3", "4" };
  1218. // ThenBy<TSource,TKey> (Func<TSource, TKey>)
  1219. AssertException<ArgumentNullException> (delegate () {
  1220. ((IOrderedEnumerable<string>) null).ThenBy (x => "test");
  1221. });
  1222. AssertException<ArgumentNullException> (delegate () {
  1223. data.OrderBy (x => x).ThenBy ((Func<string, string>) null);
  1224. });
  1225. // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1226. AssertException<ArgumentNullException> (delegate () {
  1227. ((IOrderedEnumerable<string>) null).ThenBy (x => "test", Comparer<string>.Default);
  1228. });
  1229. AssertException<ArgumentNullException> (delegate () {
  1230. data.OrderBy (x => x).ThenBy ((Func<string, string>) null, Comparer<string>.Default);
  1231. });
  1232. }
  1233. [Test]
  1234. public void ThenByTest ()
  1235. {
  1236. int [] data = { 2, 1, 5, 3, 4 };
  1237. int [] expected = { 1, 2, 3, 4, 5 };
  1238. // ThenBy<TSource,TKey> (Func<TSource, TKey>)
  1239. AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x));
  1240. // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1241. AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x, Comparer<int>.Default));
  1242. }
  1243. [Test]
  1244. public void ThenByDescendingArgumentNullTest ()
  1245. {
  1246. string [] data = { "2", "1", "5", "3", "4" };
  1247. // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
  1248. AssertException<ArgumentNullException> (delegate () {
  1249. ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test");
  1250. });
  1251. AssertException<ArgumentNullException> (delegate () {
  1252. data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null);
  1253. });
  1254. // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1255. AssertException<ArgumentNullException> (delegate () {
  1256. ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test", Comparer<string>.Default);
  1257. });
  1258. AssertException<ArgumentNullException> (delegate () {
  1259. data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null, Comparer<string>.Default);
  1260. });
  1261. }
  1262. [Test]
  1263. public void ThenByDescendingTest ()
  1264. {
  1265. int [] data = { 2, 1, 5, 3, 4 };
  1266. int [] expected = { 5, 4, 3, 2, 1 };
  1267. // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
  1268. AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x));
  1269. // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1270. AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x, Comparer<int>.Default));
  1271. }
  1272. [Test]
  1273. [Category ("NotWorking")]
  1274. public void GroupByArgumentNullTest ()
  1275. {
  1276. string [] data = { "2", "1", "5", "3", "4" };
  1277. // GroupBy<string,string> (Func<string, string>)
  1278. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test")); });
  1279. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null); });
  1280. // GroupBy<string,string> (Func<string, string>, IEqualityComparer<string>)
  1281. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1282. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1283. // GroupBy<string,string,string> (Func<string, string>, Func<string, string>)
  1284. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
  1285. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
  1286. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
  1287. // GroupBy<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
  1288. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1289. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1290. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1291. // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>)
  1292. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
  1293. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
  1294. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null); });
  1295. // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>)
  1296. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
  1297. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
  1298. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
  1299. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null); });
  1300. // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
  1301. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1302. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1303. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1304. // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
  1305. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1306. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1307. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1308. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1309. }
  1310. [Test]
  1311. [Category ("NotWorking")]
  1312. public void GroupByTest ()
  1313. {
  1314. string [] data = { "2", "1", "5", "3", "4", "3" };
  1315. Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
  1316. expected.Add ("2", new List<string> () { "2" });
  1317. expected.Add ("1", new List<string> () { "1" });
  1318. expected.Add ("5", new List<string> () { "5" });
  1319. expected.Add ("3", new List<string> () { "3", "3" });
  1320. expected.Add ("4", new List<string> () { "4" });
  1321. Dictionary<string, IEnumerable<string>> expected2 = new Dictionary<string, IEnumerable<string>> ();
  1322. expected2.Add ("2", new List<string> () { "22" });
  1323. expected2.Add ("1", new List<string> () { "11" });
  1324. expected2.Add ("5", new List<string> () { "55" });
  1325. expected2.Add ("3", new List<string> () { "33", "33" });
  1326. expected2.Add ("4", new List<string> () { "44" });
  1327. string [] expected3 = new string [] { "22", "11", "55", "333", "44" };
  1328. // GroupBy<int,int> (Func<int, int>)
  1329. AssertAreSame (expected, data.GroupBy (x => x));
  1330. // GroupBy<int,int> (Func<int, int>, IEqualityComparer<int>)
  1331. AssertAreSame (expected, data.GroupBy (x => x, EqualityComparer<string>.Default));
  1332. // GroupBy<int,int,int> (Func<int, int>, Func<int, int>)
  1333. AssertAreSame (expected2, data.GroupBy (x => x, x => x + x));
  1334. // GroupBy<int,int,int> (Func<int, int>, Func<int, int>, IEqualityComparer<int>)
  1335. AssertAreSame (expected2, data.GroupBy (x => x, x => x + x, EqualityComparer<string>.Default));
  1336. // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>)
  1337. AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
  1338. // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>)
  1339. AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
  1340. // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
  1341. AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
  1342. // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
  1343. AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
  1344. }
  1345. [Test]
  1346. public void ConcatArgumentNullTest ()
  1347. {
  1348. string [] data = { "2", "1", "5", "3", "4" };
  1349. // Concat<TSource> (IEnumerable<TSource>)
  1350. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Concat (data); });
  1351. AssertException<ArgumentNullException> (delegate () { data.Concat ((IEnumerable<string>) null); });
  1352. }
  1353. [Test]
  1354. public void ConcatTest ()
  1355. {
  1356. int [] data1 = { 2, 1, 5, 3, 4 };
  1357. int [] data2 = { 1, 2, 3, 4, 5 };
  1358. int [] expected = { 2, 1, 5, 3, 4, 1, 2, 3, 4, 5 };
  1359. // Concat<TSource> (IEnumerable<TSource>)
  1360. AssertAreSame (expected, data1.Concat (data2));
  1361. }
  1362. [Test]
  1363. public void DistinctArgumentNullTest ()
  1364. {
  1365. //string [] data = { "2", "1", "5", "3", "4" };
  1366. // Distinct<TSource> ()
  1367. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (); });
  1368. // Distinct<TSource> (IEqualityComparer<TSource>)
  1369. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (EqualityComparer<string>.Default); });
  1370. }
  1371. [Test]
  1372. public void DistinctTest ()
  1373. {
  1374. int [] data = { 2, 1, 5, 3, 4, 2, 5, 3, 1, 8 };
  1375. int [] expected = { 2, 1, 5, 3, 4, 8 };
  1376. // Distinct<TSource> ()
  1377. AssertAreSame (expected, data.Distinct ());
  1378. // Distinct<iTSourcent> (IEqualityComparer<TSource>)
  1379. AssertAreSame (expected, data.Distinct (EqualityComparer<int>.Default));
  1380. }
  1381. [Test]
  1382. public void UnionArgumentNullTest ()
  1383. {
  1384. string [] data = { "2", "1", "5", "3", "4" };
  1385. // Union<TSource> (IEnumerable<TSource>)
  1386. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data); });
  1387. AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null); });
  1388. // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1389. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data, EqualityComparer<string>.Default); });
  1390. AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
  1391. }
  1392. [Test]
  1393. public void UnionTest ()
  1394. {
  1395. int [] data1 = { 2, 1, 5, 7, 3, 4 };
  1396. int [] data2 = { 1, 2, 3, 8, 4, 5 };
  1397. int [] expected = { 2, 1, 5, 7, 3, 4, 8 };
  1398. // Union<TSource> (IEnumerable<TSource>)
  1399. AssertAreSame (expected, data1.Union (data2));
  1400. // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1401. AssertAreSame (expected, data1.Union (data2, EqualityComparer<int>.Default));
  1402. }
  1403. [Test]
  1404. public void IntersectArgumentNullTest ()
  1405. {
  1406. string [] data = { "2", "1", "5", "3", "4" };
  1407. // Intersect<TSource> (IEnumerable<TSource>)
  1408. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data); });
  1409. AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null); });
  1410. // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1411. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data, EqualityComparer<string>.Default); });
  1412. AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
  1413. }
  1414. [Test]
  1415. public void IntersectTest ()
  1416. {
  1417. int [] data1 = { 2, 1, 5, 7, 3, 4 };
  1418. int [] data2 = { 1, 2, 3, 8, 4, 5 };
  1419. int [] expected = { 2, 1, 5, 3, 4 };
  1420. // Intersect<TSource> (IEnumerable<TSource>)
  1421. AssertAreSame (expected, data1.Intersect (data2));
  1422. // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1423. AssertAreSame (expected, data1.Intersect (data2, EqualityComparer<int>.Default));
  1424. }
  1425. [Test]
  1426. public void ExceptArgumentNullTest ()
  1427. {
  1428. string [] data = { "2", "1", "5", "3", "4" };
  1429. // Except<TSource> (IEnumerable<TSource>)
  1430. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data); });
  1431. AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null); });
  1432. // Except<TSource> (IEnumerable<string>, IEqualityComparer<TSource>)
  1433. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data, EqualityComparer<string>.Default); });
  1434. AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
  1435. }
  1436. [Test]
  1437. public void ExceptTest ()
  1438. {
  1439. int [] data1 = { 2, 1, 5, 7, 3, 4 };
  1440. int [] data2 = { 1, 2, 3, 8, 4, 5 };
  1441. int [] expected = { 7 };
  1442. // Except<TSource> (IEnumerable<TSource>)
  1443. AssertAreSame (expected, data1.Except (data2));
  1444. // Except<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1445. AssertAreSame (expected, data1.Except (data2, EqualityComparer<int>.Default));
  1446. }
  1447. [Test]
  1448. public void ReverseArgumentNullTest ()
  1449. {
  1450. //string [] data = { "2", "1", "5", "3", "4" };
  1451. // Reverse<TSource> ()
  1452. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Reverse (); });
  1453. }
  1454. [Test]
  1455. public void ReverseTest ()
  1456. {
  1457. int [] data = { 2, 1, 5, 7, 3, 4 };
  1458. int [] expected = { 4, 3, 7, 5, 1, 2 };
  1459. // Reverse<TSource> ()
  1460. AssertAreSame (expected, data.Reverse ());
  1461. }
  1462. [Test]
  1463. public void SequenceEqualArgumentNullTest ()
  1464. {
  1465. string [] data = { "2", "1", "5", "3", "4" };
  1466. // SequenceEqual<TSource> (IEnumerable<TSource>)
  1467. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data); });
  1468. AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null); });
  1469. // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1470. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data, EqualityComparer<string>.Default); });
  1471. AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
  1472. }
  1473. [Test]
  1474. public void SequenceEqualTest ()
  1475. {
  1476. int [] data1 = { 2, 1, 5, 7, 3, 4 };
  1477. int [] data2 = { 2, 1, 5, 7, 3, 4 };
  1478. int [] data3 = { 2, 1, 5, 7, 3, 4, 5 };
  1479. int [] data4 = { 2, 1, 5, 7, 3 };
  1480. int [] data5 = { 2, 1, 5, 8, 3, 4 };
  1481. // SequenceEqual<TSource> (IEnumerable<TSource>)
  1482. Assert.IsTrue (data1.SequenceEqual (data2));
  1483. Assert.IsFalse (data1.SequenceEqual (data3));
  1484. Assert.IsFalse (data1.SequenceEqual (data4));
  1485. Assert.IsFalse (data1.SequenceEqual (data5));
  1486. // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1487. Assert.IsTrue (data1.SequenceEqual (data2, EqualityComparer<int>.Default));
  1488. Assert.IsFalse (data1.SequenceEqual (data3, EqualityComparer<int>.Default));
  1489. Assert.IsFalse (data1.SequenceEqual (data4, EqualityComparer<int>.Default));
  1490. Assert.IsFalse (data1.SequenceEqual (data5, EqualityComparer<int>.Default));
  1491. }
  1492. [Test]
  1493. public void AsEnumerableArgumentNullTest ()
  1494. {
  1495. //string [] data = { "2", "1", "5", "3", "4" };
  1496. }
  1497. [Test]
  1498. public void AsEnumerableTest ()
  1499. {
  1500. int [] data = { 2, 1, 5, 7, 3, 4 };
  1501. // AsEnumerable<TSource> ()
  1502. Assert.AreSame (data, data.AsEnumerable ());
  1503. }
  1504. [Test]
  1505. public void ToArrayArgumentNullTest ()
  1506. {
  1507. //string [] data = { "2", "1", "5", "3", "4" };
  1508. // ToArray<TSource> ()
  1509. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToArray (); });
  1510. }
  1511. [Test]
  1512. public void ToArrayTest ()
  1513. {
  1514. int [] data = { 2, 3, 4, 5 };
  1515. int [] expected = { 2, 3, 4, 5 };
  1516. // ToArray<TSource> ()
  1517. AssertAreSame (expected, data.ToArray ());
  1518. }
  1519. [Test]
  1520. public void ToListArgumentNullTest ()
  1521. {
  1522. //string [] data = { "2", "1", "5", "3", "4" };
  1523. // ToList<string> ()
  1524. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToList (); });
  1525. }
  1526. [Test]
  1527. public void ToListTest ()
  1528. {
  1529. int [] data = { 2, 4, 5, 1 };
  1530. int [] expected = { 2, 4, 5, 1 };
  1531. // ToList<int> ()
  1532. AssertAreSame (expected, data.ToList ());
  1533. }
  1534. [Test]
  1535. public void ToDictionaryArgumentNullTest ()
  1536. {
  1537. string [] data = { "2", "1", "5", "3", "4" };
  1538. // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
  1539. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test"); });
  1540. AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null); });
  1541. // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
  1542. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", EqualityComparer<string>.Default); });
  1543. AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, EqualityComparer<string>.Default); });
  1544. // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
  1545. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test"); });
  1546. AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test"); });
  1547. AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null); });
  1548. // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
  1549. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test", EqualityComparer<string>.Default); });
  1550. AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test", EqualityComparer<string>.Default); });
  1551. AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null, EqualityComparer<string>.Default); });
  1552. }
  1553. [Test]
  1554. public void ToDictionaryTest ()
  1555. {
  1556. string [] data = { "2", "1", "5", "3", "4" };
  1557. Dictionary<string, string> expected = new Dictionary<string, string> ();
  1558. expected.Add ("k2", "2");
  1559. expected.Add ("k1", "1");
  1560. expected.Add ("k5", "5");
  1561. expected.Add ("k3", "3");
  1562. expected.Add ("k4", "4");
  1563. // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
  1564. AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x));
  1565. AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key"); });
  1566. // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
  1567. AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, EqualityComparer<string>.Default));
  1568. AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", EqualityComparer<string>.Default); });
  1569. // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
  1570. AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x));
  1571. AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x); });
  1572. // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
  1573. AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x, EqualityComparer<string>.Default));
  1574. AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x, EqualityComparer<string>.Default); });
  1575. }
  1576. [Test]
  1577. public void ToLookupArgumentNullTest ()
  1578. {
  1579. string [] data = { "2", "1", "5", "3", "4" };
  1580. // ToLookup<string,string> (Func<string, string>)
  1581. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test")); });
  1582. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null); });
  1583. // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
  1584. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1585. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1586. // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
  1587. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
  1588. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
  1589. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
  1590. // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
  1591. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1592. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1593. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1594. }
  1595. [Test]
  1596. public void ToLookupTest ()
  1597. {
  1598. string [] data = { "23", "12", "55", "42", "41" };
  1599. Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
  1600. expected.Add ("2", new List<string> () { "23" });
  1601. expected.Add ("1", new List<string> () { "12" });
  1602. expected.Add ("5", new List<string> () { "55" });
  1603. expected.Add ("4", new List<string> () { "42", "41" });
  1604. Assert.AreEqual (expected.Count, ((IEnumerable<string>)data).ToLookup ((x => x [0].ToString ())).Count);
  1605. // ToLookup<string,string> (Func<string, string>)
  1606. AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup ((x => x [0].ToString ())));
  1607. // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
  1608. AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), EqualityComparer<string>.Default));
  1609. // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
  1610. AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x));
  1611. // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
  1612. AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x, EqualityComparer<string>.Default));
  1613. }
  1614. [Test]
  1615. public void ToLookupNullKeyTest ()
  1616. {
  1617. string[] strs = new string[] { "one", null, "two", null, "three" };
  1618. int i = 0;
  1619. var l = strs.ToLookup (s => (s == null) ? null : "numbers", s => (s == null) ? (++i).ToString() : s);
  1620. Assert.AreEqual (2, l.Count);
  1621. Assert.AreEqual (2, l [null].Count());
  1622. Assert.IsTrue (l [null].Contains ("1"));
  1623. Assert.IsTrue (l [null].Contains ("2"));
  1624. Assert.AreEqual (3, l ["numbers"].Count());
  1625. Assert.IsTrue (l ["numbers"].Contains ("one"));
  1626. Assert.IsTrue (l ["numbers"].Contains ("two"));
  1627. Assert.IsTrue (l ["numbers"].Contains ("three"));
  1628. }
  1629. [Test]
  1630. public void DefaultIfEmptyArgumentNullTest ()
  1631. {
  1632. //string [] data = { "2", "1", "5", "3", "4" };
  1633. // DefaultIfEmpty<string> ()
  1634. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> (); });
  1635. // DefaultIfEmpty<string> (string)
  1636. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> ((string) "default"); });
  1637. }
  1638. [Test]
  1639. public void DefaultIfEmptyTest ()
  1640. {
  1641. string [] data = { "2", "1", "5", "3", "4" };
  1642. string [] empty = { };
  1643. string [] default1 = { null };
  1644. string [] default2 = { "default" };
  1645. // DefaultIfEmpty<string> ()
  1646. AssertAreSame (data, data.DefaultIfEmpty ());
  1647. AssertAreSame (default1, empty.DefaultIfEmpty ());
  1648. // DefaultIfEmpty<string> (string)
  1649. AssertAreSame (data, data.DefaultIfEmpty ("default"));
  1650. AssertAreSame (default2, empty.DefaultIfEmpty ("default"));
  1651. }
  1652. [Test]
  1653. public void OfTypeArgumentNullTest ()
  1654. {
  1655. //string [] data = { "2", "1", "5", "3", "4" };
  1656. // OfType<string> ()
  1657. AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).OfType<string> (); });
  1658. }
  1659. [Test]
  1660. public void OfTypeTest ()
  1661. {
  1662. object [] data = { "2", 2, "1", "5", "3", "4" };
  1663. string [] expected = { "2", "1", "5", "3", "4" };
  1664. // OfType<string> ()
  1665. AssertAreSame (expected, data.OfType<string> ());
  1666. }
  1667. [Test]
  1668. public void CastArgumentNullTest ()
  1669. {
  1670. //string [] data = { "2", "1", "5", "3", "4" };
  1671. // Cast<string> ()
  1672. AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).Cast<string> (); });
  1673. }
  1674. [Test]
  1675. public void CastTest ()
  1676. {
  1677. object [] data = { 1, 2, 3 };
  1678. int [] expected = { 1, 2, 3 };
  1679. // Cast<string> ()
  1680. AssertAreSame (expected, data.Cast<int> ());
  1681. AssertException<InvalidCastException> (delegate () { data.Cast<IEnumerable> ().GetEnumerator ().MoveNext (); });
  1682. data.Cast<IEnumerable> ();
  1683. }
  1684. [Test]
  1685. public void RangeArgumentNullTest ()
  1686. {
  1687. //string [] data = { "2", "1", "5", "3", "4" };
  1688. }
  1689. [Test]
  1690. public void RangeTest ()
  1691. {
  1692. int [] expected = { 2, 3, 4, 5 };
  1693. // Range<> (int)
  1694. AssertAreSame (expected, Enumerable.Range (2, 4));
  1695. AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (2, -3); });
  1696. AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (int.MaxValue - 5, 7); });
  1697. Enumerable.Range (int.MaxValue - 5, 6);
  1698. }
  1699. }
  1700. }