EnumerableMoreTest.cs 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277
  1. //
  2. // EnumerableMoreTest.cs
  3. //
  4. // Author:
  5. // Andreas Noever <[email protected]>
  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. [Ignore ("Takes some time.")]
  425. public void CountOverflowTest ()
  426. {
  427. //BigEnumerable data = new BigEnumerable ((ulong) int.MaxValue + 1);
  428. // Count<TSource> ()
  429. //AssertException<OverflowException> (delegate () { data.Count (); });
  430. // Count<TSource> (Func<TSource, bool>)
  431. //AssertException<OverflowException> (delegate () { data.Count (x => 3 == x); });
  432. // Documentation error: http://msdn2.microsoft.com/en-us/library/bb535181.aspx
  433. // An exception is only rasied if count > int.MaxValue. Not if source contains more than int.MaxValue elements.
  434. // AssertException<OverflowException> (delegate () { data.Count (x => 5 == x); });
  435. }
  436. [Test]
  437. public void LongCountArgumentNullTest ()
  438. {
  439. string [] data = { "2", "1", "5", "3", "4" };
  440. // LongCount<TSource> ()
  441. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LongCount (); });
  442. // LongCount<TSource> (Func<TSource, bool>)
  443. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LongCount (x => true); });
  444. AssertException<ArgumentNullException> (delegate () { data.LongCount ((Func<string, bool>) null); });
  445. }
  446. [Test]
  447. public void LongCountTest ()
  448. {
  449. int [] data = { 5, 2, 3, 1, 6 };
  450. //TODO: Overflow test...
  451. // LongCount<TSource> ()
  452. Assert.AreEqual (5, data.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. [Category ("NotWorking")]
  561. public void SumTest ()
  562. {
  563. string [] data = { "2", "3", "5", "5" };
  564. //TODO: OverflowException
  565. // Sum<TSource> (Func<TSource, int>)
  566. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, int>) (x => int.Parse (x))));
  567. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, int>) (x => int.Parse (x))));
  568. // Sum<TSource> (Func<TSource, Nullable<int>>)
  569. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  570. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  571. // Sum<TSource> (Func<TSource, Int64>)
  572. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
  573. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
  574. // Sum<TSource> (Func<TSource, Nullable<Int64>>)
  575. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
  576. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
  577. // Sum<TSource> (Func<TSource, Single>)
  578. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
  579. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
  580. // Sum<TSource> (Func<TSource, Nullable<Single>>)
  581. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
  582. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
  583. // Sum<TSource> (Func<TSource, Double>)
  584. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
  585. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
  586. // Sum<TSource> (Func<TSource, Nullable<Double>>)
  587. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
  588. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
  589. // Sum<TSource> (Func<TSource, Decimal>)
  590. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
  591. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
  592. // Sum<TSource> (Func<TSource, Nullable<Decimal>>)
  593. Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
  594. Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
  595. // Sum<> ()
  596. Assert.AreEqual (6, ((IEnumerable<int>) new int [] { 1, 2, 3 }).Sum ());
  597. Assert.AreEqual (0, Enumerable.Empty<int> ().Sum ());
  598. // Sum<> ()
  599. Assert.AreEqual (6, ((IEnumerable<Nullable<int>>) new int? [] { 1, 2, 3 }).Sum ());
  600. Assert.AreEqual (0, Enumerable.Empty<int?> ().Sum ());
  601. // Sum<> ()
  602. Assert.AreEqual (6, ((IEnumerable<Int64>) new long [] { 1, 2, 3 }).Sum ());
  603. Assert.AreEqual (0, Enumerable.Empty<long> ().Sum ());
  604. // Sum<> ()
  605. Assert.AreEqual (6, ((IEnumerable<Nullable<Int64>>) new long? [] { 1, 2, 3 }).Sum ());
  606. Assert.AreEqual (0, Enumerable.Empty<long?> ().Sum ());
  607. // Sum<> ()
  608. Assert.AreEqual (6, ((IEnumerable<Single>) new float [] { 1, 2, 3 }).Sum ());
  609. Assert.AreEqual (0, Enumerable.Empty<float> ().Sum ());
  610. // Sum<> ()
  611. Assert.AreEqual (6, ((IEnumerable<Nullable<Single>>) new float? [] { 1, 2, 3 }).Sum ());
  612. Assert.AreEqual (0, Enumerable.Empty<float?> ().Sum ());
  613. // Sum<> ()
  614. Assert.AreEqual (6, ((IEnumerable<Double>) new double [] { 1, 2, 3 }).Sum ());
  615. Assert.AreEqual (0, Enumerable.Empty<double> ().Sum ());
  616. // Sum<> ()
  617. Assert.AreEqual (6, ((IEnumerable<Nullable<Double>>) new double? [] { 1, 2, 3 }).Sum ());
  618. Assert.AreEqual (0, Enumerable.Empty<double?> ().Sum ());
  619. // Sum<> ()
  620. Assert.AreEqual (6, ((IEnumerable<Decimal>) new decimal [] { 1, 2, 3 }).Sum ());
  621. Assert.AreEqual (0, Enumerable.Empty<decimal> ().Sum ());
  622. // Sum<> ()
  623. Assert.AreEqual (6, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 1, 2, 3 }).Sum ());
  624. Assert.AreEqual (0, Enumerable.Empty<decimal?> ().Sum ());
  625. }
  626. [Test]
  627. public void MinArgumentNullTest ()
  628. {
  629. string [] data = { "2", "1", "5", "3", "4" };
  630. // Min<TSource> ()
  631. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> (); });
  632. // Min<TSource> (Func<TSource, int>)
  633. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, int>) (x => 0)); });
  634. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, int>) null); });
  635. // Min<TSource> (Func<TSource, Nullable<int>>)
  636. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
  637. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<int>>) null); });
  638. // Min<TSource> (Func<TSource, Int64>)
  639. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Int64>) (x => 0L)); });
  640. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Int64>) null); });
  641. // Min<TSource> (Func<TSource, Nullable<Int64>>)
  642. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
  643. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Int64>>) null); });
  644. // Min<TSource> (Func<TSource, Single>)
  645. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Single>) (x => 0f)); });
  646. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Single>) null); });
  647. // Min<TSource> (Func<TSource, Nullable<Single>>)
  648. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
  649. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Single>>) null); });
  650. // Min<TSource> (Func<TSource, Double>)
  651. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Double>) (x => 0d)); });
  652. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Double>) null); });
  653. // Min<TSource> (Func<TSource, Nullable<Double>>)
  654. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
  655. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Double>>) null); });
  656. // Min<TSource> (Func<TSource, Decimal>)
  657. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Decimal>) (x => 0m)); });
  658. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Decimal>) null); });
  659. // Min<TSource> (Func<TSource, Nullable<Decimal>>)
  660. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
  661. AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Decimal>>) null); });
  662. // Min<TSource,TSource> (Func<TSource, string>)
  663. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string, string> ((Func<string, string>) (x => "test")); });
  664. AssertException<ArgumentNullException> (delegate () { data.Min<string, string> ((Func<string, string>) null); });
  665. // Min<> ()
  666. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Min (); });
  667. // Min<> ()
  668. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Min (); });
  669. // Min<> ()
  670. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Min (); });
  671. // Min<> ()
  672. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Min (); });
  673. // Min<> ()
  674. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Min (); });
  675. // Min<> ()
  676. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Min (); });
  677. // Min<> ()
  678. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Min (); });
  679. // Min<> ()
  680. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Min (); });
  681. // Min<> ()
  682. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Min (); });
  683. // Min<> ()
  684. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Min (); });
  685. }
  686. [Test]
  687. [Category ("NotWorking")]
  688. public void MinTest ()
  689. {
  690. string [] data = { "2", "1", "5", "3", "4" };
  691. // Min<TSource> ()
  692. Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string> ());
  693. // Min<TSource> (Func<TSource, int>)
  694. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, int>) (x => int.Parse (x))));
  695. // Min<TSource> (Func<TSource, Nullable<int>>)
  696. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  697. // Min<TSource> (Func<TSource, Int64>)
  698. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Int64>) (x => int.Parse (x))));
  699. // Min<TSource> (Func<TSource, Nullable<Int64>>)
  700. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
  701. // Min<TSource> (Func<TSource, Single>)
  702. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Single>) (x => int.Parse (x))));
  703. // Min<TSource> (Func<TSource, Nullable<Single>>)
  704. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
  705. // Min<TSource> (Func<TSource, Double>)
  706. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Double>) (x => int.Parse (x))));
  707. // Min<TSource> (Func<TSource, Nullable<Double>>)
  708. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
  709. // Min<TSource> (Func<TSource, Decimal>)
  710. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Decimal>) (x => int.Parse (x))));
  711. // Min<TSource> (Func<TSource, Nullable<Decimal>>)
  712. Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
  713. // Min<TSource,TSource> (Func<TSource, TSource>)
  714. Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string, string> ((Func<string, string>) (x => x)));
  715. // Min<> ()
  716. Assert.AreEqual (2, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Min ());
  717. // Min<> ()
  718. Assert.AreEqual (2, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Min ());
  719. // Min<> ()
  720. Assert.AreEqual (2, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Min ());
  721. // Min<> ()
  722. Assert.AreEqual (2, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Min ());
  723. // Min<> ()
  724. Assert.AreEqual (2, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Min ());
  725. // Min<> ()
  726. Assert.AreEqual (2, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Min ());
  727. // Min<> ()
  728. Assert.AreEqual (2, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Min ());
  729. // Min<> ()
  730. Assert.AreEqual (2, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Min ());
  731. // Min<> ()
  732. Assert.AreEqual (2, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Min ());
  733. // Min<> ()
  734. Assert.AreEqual (2, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Min ());
  735. }
  736. [Test]
  737. public void MaxArgumentNullTest ()
  738. {
  739. string [] data = { "2", "1", "5", "3", "4" };
  740. // Max<TSource> ()
  741. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> (); });
  742. // Max<TSource> (Func<TSource, int>)
  743. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, int>) (x => 0)); });
  744. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, int>) null); });
  745. // Max<TSource> (Func<TSource, Nullable<int>>)
  746. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
  747. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<int>>) null); });
  748. // Max<TSource> (Func<TSource, Int64>)
  749. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Int64>) (x => 0L)); });
  750. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Int64>) null); });
  751. // Max<TSource> (Func<TSource, Nullable<Int64>>)
  752. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
  753. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Int64>>) null); });
  754. // Max<TSource> (Func<TSource, Single>)
  755. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Single>) (x => 0f)); });
  756. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Single>) null); });
  757. // Max<TSource> (Func<TSource, Nullable<Single>>)
  758. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
  759. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Single>>) null); });
  760. // Max<TSource> (Func<TSource, Double>)
  761. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Double>) (x => 0d)); });
  762. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Double>) null); });
  763. // Max<TSource> (Func<TSource, Nullable<Double>>)
  764. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
  765. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Double>>) null); });
  766. // Max<TSource> (Func<TSource, Decimal>)
  767. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Decimal>) (x => 0m)); });
  768. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Decimal>) null); });
  769. // Max<TSource> (Func<TSource, Nullable<Decimal>>)
  770. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
  771. AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Decimal>>) null); });
  772. // Max<TSource,TSource> (Func<TSource, TSource>)
  773. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string, string> ((Func<string, string>) (x => "test")); });
  774. AssertException<ArgumentNullException> (delegate () { data.Max<string, string> ((Func<string, string>) null); });
  775. // Max<> ()
  776. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Max (); });
  777. // Max<> ()
  778. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Max (); });
  779. // Max<> ()
  780. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Max (); });
  781. // Max<> ()
  782. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Max (); });
  783. // Max<> ()
  784. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Max (); });
  785. // Max<> ()
  786. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Max (); });
  787. // Max<> ()
  788. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Max (); });
  789. // Max<> ()
  790. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Max (); });
  791. // Max<> ()
  792. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Max (); });
  793. // Max<> ()
  794. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Max (); });
  795. }
  796. [Test]
  797. public void MaxTest ()
  798. {
  799. string [] data = { "2", "1", "5", "3", "4" };
  800. // Max<string> ()
  801. Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string> ());
  802. // Max<TSource> (Func<TSource, int>)
  803. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, int>) (x => int.Parse (x))));
  804. // Max<TSource> (Func<TSource, Nullable<int>>)
  805. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  806. // Max<TSource> (Func<TSource, Int64>)
  807. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Int64>) (x => int.Parse (x))));
  808. // Max<TSource> (Func<TSource, Nullable<Int64>>)
  809. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
  810. // Max<TSource> (Func<TSource, Single>)
  811. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Single>) (x => int.Parse (x))));
  812. // Max<TSource> (Func<TSource, Nullable<Single>>)
  813. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
  814. // Max<TSource> (Func<TSource, Double>)
  815. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Double>) (x => int.Parse (x))));
  816. // Max<TSource> (Func<TSource, Nullable<Double>>)
  817. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
  818. // Max<TSource> (Func<TSource, Decimal>)
  819. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Decimal>) (x => int.Parse (x))));
  820. // Max<TSource> (Func<TSource, Nullable<Decimal>>)
  821. Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
  822. // Max<TSource,TSource> (Func<TSource, TSource>)
  823. Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string, string> ((Func<string, string>) (x => x)));
  824. // Max<> ()
  825. Assert.AreEqual (4, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Max ());
  826. // Max<> ()
  827. Assert.AreEqual (4, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Max ());
  828. // Max<> ()
  829. Assert.AreEqual (4, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Max ());
  830. // Max<> ()
  831. Assert.AreEqual (4, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Max ());
  832. // Max<> ()
  833. Assert.AreEqual (4, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Max ());
  834. // Max<> ()
  835. Assert.AreEqual (4, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Max ());
  836. // Max<> ()
  837. Assert.AreEqual (4, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Max ());
  838. // Max<> ()
  839. Assert.AreEqual (4, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Max ());
  840. // Max<> ()
  841. Assert.AreEqual (4, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Max ());
  842. // Max<> ()
  843. Assert.AreEqual (4, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Max ());
  844. }
  845. [Test]
  846. public void AverageArgumentNullTest ()
  847. {
  848. string [] data = { "2", "1", "5", "3", "4" };
  849. // Average<TSource> (Func<TSource, int>)
  850. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, int>) (x => 0)); });
  851. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, int>) null); });
  852. // Average<TSource> (Func<TSource, Nullable<int>>)
  853. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
  854. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<int>>) null); });
  855. // Average<TSource> (Func<TSource, Int64>)
  856. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Int64>) (x => 0L)); });
  857. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Int64>) null); });
  858. // Average<TSource> (Func<TSource, Nullable<Int64>>)
  859. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
  860. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Int64>>) null); });
  861. // Average<TSource> (Func<TSource, Single>)
  862. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Single>) (x => 0f)); });
  863. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Single>) null); });
  864. // Average<TSource> (Func<TSource, Nullable<Single>>)
  865. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
  866. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Single>>) null); });
  867. // Average<TSource> (Func<TSource, Double>)
  868. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Double>) (x => 0d)); });
  869. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Double>) null); });
  870. // Average<TSource> (Func<TSource, Nullable<Double>>)
  871. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
  872. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Double>>) null); });
  873. // Average<TSource> (Func<TSource, Decimal>)
  874. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Decimal>) (x => 0m)); });
  875. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Decimal>) null); });
  876. // Average<TSource> (Func<TSource, Nullable<Decimal>>)
  877. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
  878. AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Decimal>>) null); });
  879. // Average<> ()
  880. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Average (); });
  881. // Average<> ()
  882. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Average (); });
  883. // Average<> ()
  884. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Average (); });
  885. // Average<> ()
  886. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Average (); });
  887. // Average<> ()
  888. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Average (); });
  889. // Average<> ()
  890. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Average (); });
  891. // Average<> ()
  892. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Average (); });
  893. // Average<> ()
  894. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Average (); });
  895. // Average<> ()
  896. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Average (); });
  897. // Average<> ()
  898. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Average (); });
  899. }
  900. [Test]
  901. public void AverageTest ()
  902. {
  903. string [] data = { "2", "1", "5", "3", "4" };
  904. string [] empty = { };
  905. // Average<string> (Func<string, int>)
  906. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, int>) (x => int.Parse (x))));
  907. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, int>) (x => int.Parse (x))); });
  908. // Average<TSource> (Func<TSource, Nullable<int>>)
  909. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
  910. // Average<TSource> (Func<TSource, Int64>)
  911. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long>) (x => int.Parse (x))));
  912. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, long>) (x => int.Parse (x))); });
  913. // Average<TSource> (Func<TSource, Nullable<Int64>>)
  914. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long?>) (x => (int?) int.Parse (x))));
  915. // Average<TSource> (Func<TSource, Single>)
  916. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float>) (x => int.Parse (x))));
  917. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, float>) (x => int.Parse (x))); });
  918. // Average<TSource> (Func<TSource, Nullable<Single>>)
  919. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float?>) (x => (int?) int.Parse (x))));
  920. // Average<TSource> (Func<TSource, Double>)
  921. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double>) (x => int.Parse (x))));
  922. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, double>) (x => int.Parse (x))); });
  923. // Average<TSource> (Func<TSource, Nullable<Double>>)
  924. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double?>) (x => (int?) int.Parse (x))));
  925. // Average<TSource> (Func<TSource, Decimal>)
  926. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal>) (x => int.Parse (x))));
  927. AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, decimal>) (x => int.Parse (x))); });
  928. // Average<TSource> (Func<TSource, Nullable<Decimal>>)
  929. Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal?>) (x => (int?) int.Parse (x))));
  930. // Average<> ()
  931. Assert.AreEqual (3, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Average ());
  932. AssertException<InvalidOperationException> (delegate () { new int [0].Average (); });
  933. // Average<> ()
  934. Assert.AreEqual (3, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Average ());
  935. // Average<> ()
  936. Assert.AreEqual (3, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Average ());
  937. AssertException<InvalidOperationException> (delegate () { new long [0].Average (); });
  938. // Average<> ()
  939. Assert.AreEqual (3, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Average ());
  940. // Average<> ()
  941. Assert.AreEqual (3, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Average ());
  942. AssertException<InvalidOperationException> (delegate () { new float [0].Average (); });
  943. // Average<> ()
  944. Assert.AreEqual (3, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Average ());
  945. // Average<> ()
  946. Assert.AreEqual (3, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Average ());
  947. AssertException<InvalidOperationException> (delegate () { new double [0].Average (); });
  948. // Average<> ()
  949. Assert.AreEqual (3, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Average ());
  950. // Average<> ()
  951. Assert.AreEqual (3, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Average ());
  952. AssertException<InvalidOperationException> (delegate () { new decimal [0].Average (); });
  953. // Average<> ()
  954. Assert.AreEqual (3, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Average ());
  955. }
  956. [Test]
  957. public void WhereArgumentNullTest ()
  958. {
  959. string [] data = { "2", "1", "5", "3", "4" };
  960. // Where<TSource> (Func<TSource, bool>)
  961. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where (x => true); });
  962. AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, bool>) null); });
  963. // Where<TSource> (Func<TSource, int, bool>)
  964. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where ((x, y) => true); });
  965. AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, int, bool>) null); });
  966. }
  967. [Test]
  968. public void WhereTest ()
  969. {
  970. int [] data = { 2, 1, 5, 3, 4 };
  971. int [] expected1 = { 2, 1 };
  972. int [] expected2 = { 2 };
  973. // Where<TSource> (Func<TSource, bool>)
  974. AssertAreSame (expected1, data.Where (x => x < 3));
  975. // Where<TSource> (Func<TSource, int, bool>)
  976. AssertAreSame (expected2, data.Where ((x, y) => x < 3 && y != 1));
  977. }
  978. [Test]
  979. public void SelectArgumentNullTest ()
  980. {
  981. string [] data = { "2", "1", "5", "3", "4" };
  982. // Select<TSource,TResult> (Func<TSource, TResult>)
  983. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select (x => "test"); });
  984. AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, string>) null); });
  985. // Select<TSource,TResult> (Func<TSource, int, TResult>)
  986. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select ((x, y) => "test"); });
  987. AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, int, string>) null); });
  988. }
  989. [Test]
  990. public void SelectTest ()
  991. {
  992. string [] data = { "2", "1", "5", "3", "4" };
  993. string [] expected1 = { "2x", "1x", "5x", "3x", "4x" };
  994. string [] expected2 = { "2x0", "1x1", "5x2", "3x3", "4x4" };
  995. // Select<TSource,TResult> (Func<TSource, TResult>)
  996. AssertAreSame (expected1, data.Select<string, string> (x => x + "x"));
  997. // Select<TSource,TResult> (Func<TSource, int, TResult>)
  998. AssertAreSame (expected2, data.Select<string, string> ((x, y) => x + "x" + y));
  999. }
  1000. [Test]
  1001. public void SelectManyArgumentNullTest ()
  1002. {
  1003. string [] data = { "2", "1", "5", "3", "4" };
  1004. // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
  1005. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data); });
  1006. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null); });
  1007. // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
  1008. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data); });
  1009. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null); });
  1010. // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
  1011. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data, (x, y) => "test"); });
  1012. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null, (x, y) => "test"); });
  1013. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((x, y) => data, (Func<string, string, string>) null); });
  1014. // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
  1015. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data, (x, y) => "test"); });
  1016. AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null, (x, y) => "test"); });
  1017. AssertException<ArgumentNullException> (delegate () { data.SelectMany (x => data, (Func<string, string, string>) null); });
  1018. }
  1019. [Test]
  1020. public void SelectManyTest ()
  1021. {
  1022. string [] data = { "0", "1" };
  1023. string [] expected = { "0", "00", "1", "11" };
  1024. // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
  1025. AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }));
  1026. // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
  1027. AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }));
  1028. // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
  1029. AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }, (x, y) => y));
  1030. // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
  1031. AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }, (x, y) => y));
  1032. }
  1033. [Test]
  1034. public void TakeArgumentNullTest ()
  1035. {
  1036. //string [] data = { "2", "1", "5", "3", "4" };
  1037. // Take<TSource> (int)
  1038. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Take (0); });
  1039. }
  1040. [Test]
  1041. public void TakeTest ()
  1042. {
  1043. int [] data = { 2, 1, 5, 3, 1 };
  1044. int [] expected = { 2, 1 };
  1045. int [] empty = { };
  1046. // Take<TSource> (int)
  1047. AssertAreSame (expected, data.Take (2));
  1048. AssertAreSame (empty, data.Take (-2));
  1049. }
  1050. [Test]
  1051. public void TakeWhileArgumentNullTest ()
  1052. {
  1053. string [] data = { "2", "1", "5", "3", "4" };
  1054. // TakeWhile<TSource> (Func<TSource, bool>)
  1055. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile (x => true); });
  1056. AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, bool>) null); });
  1057. // TakeWhile<TSource> (Func<TSource, int, bool>)
  1058. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile ((x, y) => true); });
  1059. AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, int, bool>) null); });
  1060. }
  1061. [Test]
  1062. public void TakeWhileTest ()
  1063. {
  1064. int [] data = { 2, 1, 5, 3, 1 };
  1065. int [] expected = { 2, 1 };
  1066. // TakeWhile<TSource> (Func<TSource, bool>)
  1067. AssertAreSame (expected, data.TakeWhile (x => x != 5));
  1068. // TakeWhile<TSource> (Func<TSource, int, bool>)
  1069. AssertAreSame (expected, data.TakeWhile ((x, y) => y != 2));
  1070. }
  1071. [Test]
  1072. public void SkipArgumentNullTest ()
  1073. {
  1074. //string [] data = { "2", "1", "5", "3", "4" };
  1075. // Skip<TSource> (int)
  1076. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Skip (0); });
  1077. }
  1078. [Test]
  1079. public void SkipTest ()
  1080. {
  1081. int [] data = { 2, 1, 5, 3, 1 };
  1082. int [] expected = { 5, 3, 1 };
  1083. // Skip<string> (TSource)
  1084. AssertAreSame (expected, data.Skip (2));
  1085. AssertAreSame (data, data.Skip (-2));
  1086. }
  1087. [Test]
  1088. public void SkipWhileArgumentNullTest ()
  1089. {
  1090. string [] data = { "2", "1", "5", "3", "4" };
  1091. // SkipWhile<TSource> (Func<TSource, bool>)
  1092. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile (x => true); });
  1093. AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, bool>) null); });
  1094. // SkipWhile<TSource> (Func<TSource, int, bool>)
  1095. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile ((x, y) => true); });
  1096. AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, int, bool>) null); });
  1097. }
  1098. [Test]
  1099. public void SkipWhileTest ()
  1100. {
  1101. int [] data = { 2, 1, 5, 3, 1 };
  1102. int [] expected = { 5, 3, 1 };
  1103. // SkipWhile<TSource> (Func<TSource, bool>)
  1104. AssertAreSame (expected, data.SkipWhile (x => x != 5));
  1105. // SkipWhile<TSource> (Func<TSource, int, bool>)
  1106. AssertAreSame (expected, data.SkipWhile ((x, y) => y != 2));
  1107. }
  1108. [Test]
  1109. [Category ("NotWorking")]
  1110. public void JoinArgumentNullTest ()
  1111. {
  1112. string [] data = { "2", "1", "5", "3", "4" };
  1113. // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
  1114. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test"); });
  1115. AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
  1116. AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
  1117. AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
  1118. AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null); });
  1119. // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
  1120. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1121. AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1122. AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1123. AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
  1124. AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null, EqualityComparer<string>.Default); });
  1125. }
  1126. [Test]
  1127. public void JoinTest ()
  1128. {
  1129. string [] dataOuter1 = { "2", "1", "5", "3", "4" };
  1130. string [] dataInner1 = { "7", "3", "5", "8", "9" };
  1131. string [] expected1 = { "55", "33" };
  1132. string [] dataOuter2 = { "2", "1", "3", "4" };
  1133. string [] dataInner2 = { "7", "5", "8", "9" };
  1134. string [] expected2 = { };
  1135. // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
  1136. AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y));
  1137. AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y));
  1138. // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
  1139. AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
  1140. AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
  1141. }
  1142. [Test]
  1143. [Category ("NotWorking")]
  1144. public void GroupJoinArgumentNullTest ()
  1145. {
  1146. string [] data = { "2", "1", "5", "3", "4" };
  1147. // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
  1148. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test"); });
  1149. AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
  1150. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
  1151. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
  1152. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null); });
  1153. // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
  1154. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1155. AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1156. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
  1157. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
  1158. AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null, EqualityComparer<string>.Default); });
  1159. }
  1160. [Test]
  1161. public void GroupJoinTest ()
  1162. {
  1163. string [] dataOuter1 = { "2", "1", "5", "3", "4" };
  1164. string [] dataInner1 = { "7", "3", "5", "3", "9" };
  1165. string [] expected1 = { "2", "1", "55", "333", "4" };
  1166. string [] dataOuter2 = { "2", "1", "5", "8", "4" };
  1167. string [] dataInner2 = { "7", "3", "6", "3", "9" };
  1168. string [] expected2 = { "2", "1", "5", "8", "4" };
  1169. // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
  1170. AssertAreSame (expected1, (dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
  1171. AssertAreSame (expected2, (dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
  1172. // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
  1173. AssertAreSame (expected1, dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
  1174. AssertAreSame (expected2, dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
  1175. }
  1176. [Test]
  1177. public void OrderByArgumentNullTest ()
  1178. {
  1179. string [] data = { "2", "1", "5", "3", "4" };
  1180. // OrderBy<TSource,TKey> (Func<TSource, TKey>)
  1181. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test"); });
  1182. AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null); });
  1183. // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1184. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test", Comparer<string>.Default); });
  1185. AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null, Comparer<string>.Default); });
  1186. }
  1187. [Test]
  1188. public void OrderByTest ()
  1189. {
  1190. int [] data = { 2, 1, 5, 3, 4 };
  1191. int [] expected = { 1, 2, 3, 4, 5 };
  1192. // OrderBy<TSource,TKey> (Func<TSource, TKey>)
  1193. AssertAreSame (expected, data.OrderBy (x => x));
  1194. // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1195. AssertAreSame (expected, data.OrderBy (x => x, Comparer<int>.Default));
  1196. }
  1197. [Test]
  1198. public void OrderByDescendingArgumentNullTest ()
  1199. {
  1200. string [] data = { "2", "1", "5", "3", "4" };
  1201. // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
  1202. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test"); });
  1203. AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null); });
  1204. // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1205. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test", Comparer<string>.Default); });
  1206. AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null, Comparer<string>.Default); });
  1207. }
  1208. [Test]
  1209. public void OrderByDescendingTest ()
  1210. {
  1211. int [] data = { 2, 1, 5, 3, 4 };
  1212. int [] expected = { 5, 4, 3, 2, 1 };
  1213. // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
  1214. AssertAreSame (expected, data.OrderByDescending (x => x));
  1215. // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1216. AssertAreSame (expected, data.OrderByDescending (x => x, Comparer<int>.Default));
  1217. }
  1218. [Test]
  1219. public void ThenByArgumentNullTest ()
  1220. {
  1221. string [] data = { "2", "1", "5", "3", "4" };
  1222. // ThenBy<TSource,TKey> (Func<TSource, TKey>)
  1223. AssertException<ArgumentNullException> (delegate () {
  1224. ((IOrderedEnumerable<string>) null).ThenBy (x => "test");
  1225. });
  1226. AssertException<ArgumentNullException> (delegate () {
  1227. data.OrderBy (x => x).ThenBy ((Func<string, string>) null);
  1228. });
  1229. // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1230. AssertException<ArgumentNullException> (delegate () {
  1231. ((IOrderedEnumerable<string>) null).ThenBy (x => "test", Comparer<string>.Default);
  1232. });
  1233. AssertException<ArgumentNullException> (delegate () {
  1234. data.OrderBy (x => x).ThenBy ((Func<string, string>) null, Comparer<string>.Default);
  1235. });
  1236. }
  1237. [Test]
  1238. public void ThenByTest ()
  1239. {
  1240. int [] data = { 2, 1, 5, 3, 4 };
  1241. int [] expected = { 1, 2, 3, 4, 5 };
  1242. // ThenBy<TSource,TKey> (Func<TSource, TKey>)
  1243. AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x));
  1244. // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1245. AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x, Comparer<int>.Default));
  1246. }
  1247. [Test]
  1248. public void ThenByDescendingArgumentNullTest ()
  1249. {
  1250. string [] data = { "2", "1", "5", "3", "4" };
  1251. // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
  1252. AssertException<ArgumentNullException> (delegate () {
  1253. ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test");
  1254. });
  1255. AssertException<ArgumentNullException> (delegate () {
  1256. data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null);
  1257. });
  1258. // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1259. AssertException<ArgumentNullException> (delegate () {
  1260. ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test", Comparer<string>.Default);
  1261. });
  1262. AssertException<ArgumentNullException> (delegate () {
  1263. data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null, Comparer<string>.Default);
  1264. });
  1265. }
  1266. [Test]
  1267. public void ThenByDescendingTest ()
  1268. {
  1269. int [] data = { 2, 1, 5, 3, 4 };
  1270. int [] expected = { 5, 4, 3, 2, 1 };
  1271. // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
  1272. AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x));
  1273. // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
  1274. AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x, Comparer<int>.Default));
  1275. }
  1276. [Test]
  1277. [Category ("NotWorking")]
  1278. public void GroupByArgumentNullTest ()
  1279. {
  1280. string [] data = { "2", "1", "5", "3", "4" };
  1281. // GroupBy<string,string> (Func<string, string>)
  1282. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test")); });
  1283. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null); });
  1284. // GroupBy<string,string> (Func<string, string>, IEqualityComparer<string>)
  1285. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1286. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1287. // GroupBy<string,string,string> (Func<string, string>, Func<string, string>)
  1288. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
  1289. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
  1290. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
  1291. // GroupBy<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
  1292. 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); });
  1293. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1294. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1295. // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>)
  1296. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
  1297. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
  1298. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null); });
  1299. // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>)
  1300. 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")); });
  1301. 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")); });
  1302. 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")); });
  1303. 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); });
  1304. // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
  1305. 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); });
  1306. 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); });
  1307. AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1308. // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
  1309. 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); });
  1310. 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); });
  1311. 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); });
  1312. 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); });
  1313. }
  1314. [Test]
  1315. [Category ("NotWorking")]
  1316. public void GroupByTest ()
  1317. {
  1318. string [] data = { "2", "1", "5", "3", "4", "3" };
  1319. Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
  1320. expected.Add ("2", new List<string> () { "2" });
  1321. expected.Add ("1", new List<string> () { "1" });
  1322. expected.Add ("5", new List<string> () { "5" });
  1323. expected.Add ("3", new List<string> () { "3", "3" });
  1324. expected.Add ("4", new List<string> () { "4" });
  1325. Dictionary<string, IEnumerable<string>> expected2 = new Dictionary<string, IEnumerable<string>> ();
  1326. expected2.Add ("2", new List<string> () { "22" });
  1327. expected2.Add ("1", new List<string> () { "11" });
  1328. expected2.Add ("5", new List<string> () { "55" });
  1329. expected2.Add ("3", new List<string> () { "33", "33" });
  1330. expected2.Add ("4", new List<string> () { "44" });
  1331. string [] expected3 = new string [] { "22", "11", "55", "333", "44" };
  1332. // GroupBy<int,int> (Func<int, int>)
  1333. AssertAreSame (expected, data.GroupBy (x => x));
  1334. // GroupBy<int,int> (Func<int, int>, IEqualityComparer<int>)
  1335. AssertAreSame (expected, data.GroupBy (x => x, EqualityComparer<string>.Default));
  1336. // GroupBy<int,int,int> (Func<int, int>, Func<int, int>)
  1337. AssertAreSame (expected2, data.GroupBy (x => x, x => x + x));
  1338. // GroupBy<int,int,int> (Func<int, int>, Func<int, int>, IEqualityComparer<int>)
  1339. AssertAreSame (expected2, data.GroupBy (x => x, x => x + x, EqualityComparer<string>.Default));
  1340. // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>)
  1341. AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
  1342. // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>)
  1343. AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
  1344. // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
  1345. AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
  1346. // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
  1347. AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
  1348. }
  1349. [Test]
  1350. public void ConcatArgumentNullTest ()
  1351. {
  1352. string [] data = { "2", "1", "5", "3", "4" };
  1353. // Concat<TSource> (IEnumerable<TSource>)
  1354. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Concat (data); });
  1355. AssertException<ArgumentNullException> (delegate () { data.Concat ((IEnumerable<string>) null); });
  1356. }
  1357. [Test]
  1358. public void ConcatTest ()
  1359. {
  1360. int [] data1 = { 2, 1, 5, 3, 4 };
  1361. int [] data2 = { 1, 2, 3, 4, 5 };
  1362. int [] expected = { 2, 1, 5, 3, 4, 1, 2, 3, 4, 5 };
  1363. // Concat<TSource> (IEnumerable<TSource>)
  1364. AssertAreSame (expected, data1.Concat (data2));
  1365. }
  1366. [Test]
  1367. public void DistinctArgumentNullTest ()
  1368. {
  1369. //string [] data = { "2", "1", "5", "3", "4" };
  1370. // Distinct<TSource> ()
  1371. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (); });
  1372. // Distinct<TSource> (IEqualityComparer<TSource>)
  1373. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (EqualityComparer<string>.Default); });
  1374. }
  1375. [Test]
  1376. public void DistinctTest ()
  1377. {
  1378. int [] data = { 2, 1, 5, 3, 4, 2, 5, 3, 1, 8 };
  1379. int [] expected = { 2, 1, 5, 3, 4, 8 };
  1380. // Distinct<TSource> ()
  1381. AssertAreSame (expected, data.Distinct ());
  1382. // Distinct<iTSourcent> (IEqualityComparer<TSource>)
  1383. AssertAreSame (expected, data.Distinct (EqualityComparer<int>.Default));
  1384. }
  1385. [Test]
  1386. public void UnionArgumentNullTest ()
  1387. {
  1388. string [] data = { "2", "1", "5", "3", "4" };
  1389. // Union<TSource> (IEnumerable<TSource>)
  1390. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data); });
  1391. AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null); });
  1392. // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1393. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data, EqualityComparer<string>.Default); });
  1394. AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
  1395. }
  1396. [Test]
  1397. public void UnionTest ()
  1398. {
  1399. int [] data1 = { 2, 1, 5, 7, 3, 4 };
  1400. int [] data2 = { 1, 2, 3, 8, 4, 5 };
  1401. int [] expected = { 2, 1, 5, 7, 3, 4, 8 };
  1402. // Union<TSource> (IEnumerable<TSource>)
  1403. AssertAreSame (expected, data1.Union (data2));
  1404. // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1405. AssertAreSame (expected, data1.Union (data2, EqualityComparer<int>.Default));
  1406. }
  1407. [Test]
  1408. public void IntersectArgumentNullTest ()
  1409. {
  1410. string [] data = { "2", "1", "5", "3", "4" };
  1411. // Intersect<TSource> (IEnumerable<TSource>)
  1412. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data); });
  1413. AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null); });
  1414. // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1415. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data, EqualityComparer<string>.Default); });
  1416. AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
  1417. }
  1418. [Test]
  1419. public void IntersectTest ()
  1420. {
  1421. int [] data1 = { 2, 1, 5, 7, 3, 4 };
  1422. int [] data2 = { 1, 2, 3, 8, 4, 5 };
  1423. int [] expected = { 2, 1, 5, 3, 4 };
  1424. // Intersect<TSource> (IEnumerable<TSource>)
  1425. AssertAreSame (expected, data1.Intersect (data2));
  1426. // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1427. AssertAreSame (expected, data1.Intersect (data2, EqualityComparer<int>.Default));
  1428. }
  1429. [Test]
  1430. public void ExceptArgumentNullTest ()
  1431. {
  1432. string [] data = { "2", "1", "5", "3", "4" };
  1433. // Except<TSource> (IEnumerable<TSource>)
  1434. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data); });
  1435. AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null); });
  1436. // Except<TSource> (IEnumerable<string>, IEqualityComparer<TSource>)
  1437. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data, EqualityComparer<string>.Default); });
  1438. AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
  1439. }
  1440. [Test]
  1441. public void ExceptTest ()
  1442. {
  1443. int [] data1 = { 2, 1, 5, 7, 3, 4 };
  1444. int [] data2 = { 1, 2, 3, 8, 4, 5 };
  1445. int [] expected = { 7 };
  1446. // Except<TSource> (IEnumerable<TSource>)
  1447. AssertAreSame (expected, data1.Except (data2));
  1448. // Except<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1449. AssertAreSame (expected, data1.Except (data2, EqualityComparer<int>.Default));
  1450. }
  1451. [Test]
  1452. public void ReverseArgumentNullTest ()
  1453. {
  1454. //string [] data = { "2", "1", "5", "3", "4" };
  1455. // Reverse<TSource> ()
  1456. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Reverse (); });
  1457. }
  1458. [Test]
  1459. public void ReverseTest ()
  1460. {
  1461. int [] data = { 2, 1, 5, 7, 3, 4 };
  1462. int [] expected = { 4, 3, 7, 5, 1, 2 };
  1463. // Reverse<TSource> ()
  1464. AssertAreSame (expected, data.Reverse ());
  1465. }
  1466. [Test]
  1467. public void SequenceEqualArgumentNullTest ()
  1468. {
  1469. string [] data = { "2", "1", "5", "3", "4" };
  1470. // SequenceEqual<TSource> (IEnumerable<TSource>)
  1471. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data); });
  1472. AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null); });
  1473. // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1474. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data, EqualityComparer<string>.Default); });
  1475. AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
  1476. }
  1477. [Test]
  1478. public void SequenceEqualTest ()
  1479. {
  1480. int [] data1 = { 2, 1, 5, 7, 3, 4 };
  1481. int [] data2 = { 2, 1, 5, 7, 3, 4 };
  1482. int [] data3 = { 2, 1, 5, 7, 3, 4, 5 };
  1483. int [] data4 = { 2, 1, 5, 7, 3 };
  1484. int [] data5 = { 2, 1, 5, 8, 3, 4 };
  1485. // SequenceEqual<TSource> (IEnumerable<TSource>)
  1486. Assert.IsTrue (data1.SequenceEqual (data2));
  1487. Assert.IsFalse (data1.SequenceEqual (data3));
  1488. Assert.IsFalse (data1.SequenceEqual (data4));
  1489. Assert.IsFalse (data1.SequenceEqual (data5));
  1490. // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
  1491. Assert.IsTrue (data1.SequenceEqual (data2, EqualityComparer<int>.Default));
  1492. Assert.IsFalse (data1.SequenceEqual (data3, EqualityComparer<int>.Default));
  1493. Assert.IsFalse (data1.SequenceEqual (data4, EqualityComparer<int>.Default));
  1494. Assert.IsFalse (data1.SequenceEqual (data5, EqualityComparer<int>.Default));
  1495. }
  1496. [Test]
  1497. public void AsEnumerableArgumentNullTest ()
  1498. {
  1499. //string [] data = { "2", "1", "5", "3", "4" };
  1500. }
  1501. [Test]
  1502. public void AsEnumerableTest ()
  1503. {
  1504. int [] data = { 2, 1, 5, 7, 3, 4 };
  1505. // AsEnumerable<TSource> ()
  1506. Assert.AreSame (data, data.AsEnumerable ());
  1507. }
  1508. [Test]
  1509. public void ToArrayArgumentNullTest ()
  1510. {
  1511. //string [] data = { "2", "1", "5", "3", "4" };
  1512. // ToArray<TSource> ()
  1513. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToArray (); });
  1514. }
  1515. [Test]
  1516. public void ToArrayTest ()
  1517. {
  1518. int [] data = { 2, 3, 4, 5 };
  1519. int [] expected = { 2, 3, 4, 5 };
  1520. // ToArray<TSource> ()
  1521. AssertAreSame (expected, data.ToArray ());
  1522. }
  1523. [Test]
  1524. public void ToListArgumentNullTest ()
  1525. {
  1526. //string [] data = { "2", "1", "5", "3", "4" };
  1527. // ToList<string> ()
  1528. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToList (); });
  1529. }
  1530. [Test]
  1531. public void ToListTest ()
  1532. {
  1533. int [] data = { 2, 4, 5, 1 };
  1534. int [] expected = { 2, 4, 5, 1 };
  1535. // ToList<int> ()
  1536. AssertAreSame (expected, data.ToList ());
  1537. }
  1538. [Test]
  1539. [Category ("NotWorking")]
  1540. public void ToDictionaryArgumentNullTest ()
  1541. {
  1542. string [] data = { "2", "1", "5", "3", "4" };
  1543. // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
  1544. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test"); });
  1545. AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null); });
  1546. // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
  1547. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", EqualityComparer<string>.Default); });
  1548. AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, EqualityComparer<string>.Default); });
  1549. // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
  1550. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test"); });
  1551. AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test"); });
  1552. AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null); });
  1553. // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
  1554. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test", EqualityComparer<string>.Default); });
  1555. AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test", EqualityComparer<string>.Default); });
  1556. AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null, EqualityComparer<string>.Default); });
  1557. }
  1558. [Test]
  1559. [Category ("NotWorking")]
  1560. public void ToDictionaryTest ()
  1561. {
  1562. string [] data = { "2", "1", "5", "3", "4" };
  1563. Dictionary<string, string> expected = new Dictionary<string, string> ();
  1564. expected.Add ("k2", "2");
  1565. expected.Add ("k1", "1");
  1566. expected.Add ("k5", "5");
  1567. expected.Add ("k3", "3");
  1568. expected.Add ("k4", "4");
  1569. // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
  1570. AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x));
  1571. AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key"); });
  1572. // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
  1573. AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, EqualityComparer<string>.Default));
  1574. AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", EqualityComparer<string>.Default); });
  1575. // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
  1576. AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x));
  1577. AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x); });
  1578. // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
  1579. AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x, EqualityComparer<string>.Default));
  1580. AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x, EqualityComparer<string>.Default); });
  1581. }
  1582. [Test]
  1583. public void ToLookupArgumentNullTest ()
  1584. {
  1585. string [] data = { "2", "1", "5", "3", "4" };
  1586. // ToLookup<string,string> (Func<string, string>)
  1587. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test")); });
  1588. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null); });
  1589. // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
  1590. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1591. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1592. // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
  1593. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
  1594. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
  1595. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
  1596. // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
  1597. 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); });
  1598. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1599. AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
  1600. }
  1601. [Test]
  1602. public void ToLookupTest ()
  1603. {
  1604. string [] data = { "23", "12", "55", "42", "41" };
  1605. Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
  1606. expected.Add ("2", new List<string> () { "23" });
  1607. expected.Add ("1", new List<string> () { "12" });
  1608. expected.Add ("5", new List<string> () { "55" });
  1609. expected.Add ("4", new List<string> () { "42", "41" });
  1610. // ToLookup<string,string> (Func<string, string>)
  1611. AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup ((x => x [0].ToString ())));
  1612. // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
  1613. AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), EqualityComparer<string>.Default));
  1614. // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
  1615. AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x));
  1616. // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
  1617. AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x, EqualityComparer<string>.Default));
  1618. }
  1619. [Test]
  1620. public void DefaultIfEmptyArgumentNullTest ()
  1621. {
  1622. //string [] data = { "2", "1", "5", "3", "4" };
  1623. // DefaultIfEmpty<string> ()
  1624. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> (); });
  1625. // DefaultIfEmpty<string> (string)
  1626. AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> ((string) "default"); });
  1627. }
  1628. [Test]
  1629. public void DefaultIfEmptyTest ()
  1630. {
  1631. string [] data = { "2", "1", "5", "3", "4" };
  1632. string [] empty = { };
  1633. string [] default1 = { null };
  1634. string [] default2 = { "default" };
  1635. // DefaultIfEmpty<string> ()
  1636. AssertAreSame (data, data.DefaultIfEmpty ());
  1637. AssertAreSame (default1, empty.DefaultIfEmpty ());
  1638. // DefaultIfEmpty<string> (string)
  1639. AssertAreSame (data, data.DefaultIfEmpty ("default"));
  1640. AssertAreSame (default2, empty.DefaultIfEmpty ("default"));
  1641. }
  1642. [Test]
  1643. public void OfTypeArgumentNullTest ()
  1644. {
  1645. //string [] data = { "2", "1", "5", "3", "4" };
  1646. // OfType<string> ()
  1647. AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).OfType<string> (); });
  1648. }
  1649. [Test]
  1650. public void OfTypeTest ()
  1651. {
  1652. object [] data = { "2", 2, "1", "5", "3", "4" };
  1653. string [] expected = { "2", "1", "5", "3", "4" };
  1654. // OfType<string> ()
  1655. AssertAreSame (expected, data.OfType<string> ());
  1656. }
  1657. [Test]
  1658. public void CastArgumentNullTest ()
  1659. {
  1660. //string [] data = { "2", "1", "5", "3", "4" };
  1661. // Cast<string> ()
  1662. AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).Cast<string> (); });
  1663. }
  1664. [Test]
  1665. public void CastTest ()
  1666. {
  1667. object [] data = { 1, 2, 3 };
  1668. int [] expected = { 1, 2, 3 };
  1669. // Cast<string> ()
  1670. AssertAreSame (expected, data.Cast<int> ());
  1671. AssertException<InvalidCastException> (delegate () { data.Cast<IEnumerable> ().GetEnumerator ().MoveNext (); });
  1672. data.Cast<IEnumerable> ();
  1673. }
  1674. [Test]
  1675. public void RangeArgumentNullTest ()
  1676. {
  1677. //string [] data = { "2", "1", "5", "3", "4" };
  1678. }
  1679. [Test]
  1680. public void RangeTest ()
  1681. {
  1682. int [] expected = { 2, 3, 4, 5 };
  1683. // Range<> (int)
  1684. AssertAreSame (expected, Enumerable.Range (2, 4));
  1685. AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (2, -3); });
  1686. AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (int.MaxValue - 5, 7); });
  1687. Enumerable.Range (int.MaxValue - 5, 6);
  1688. }
  1689. }
  1690. }