| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361 |
- //
- // EnumerableMoreTest.cs
- //
- // Author:
- // Andreas Noever <[email protected]>
- //
- // (C) 2007 Andreas Noever
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using NUnit.Framework;
- namespace MonoTests.System.Linq {
- [TestFixture]
- public class EnumerableMoreTest {
- class BigEnumerable : IEnumerable<int> {
- public readonly ulong Count;
- public BigEnumerable (ulong Count)
- {
- this.Count = Count;
- }
- #region IEnumerable<int> Members
- public IEnumerator<int> GetEnumerator ()
- {
- return new BigEnumerator (this);
- }
- #endregion
- #region IEnumerable Members
- IEnumerator IEnumerable.GetEnumerator ()
- {
- throw new NotImplementedException ();
- }
- #endregion
- }
- class BigEnumerator : IEnumerator<int> {
- BigEnumerable Parent;
- private ulong current;
- public BigEnumerator (BigEnumerable parent)
- {
- Parent = parent;
- }
- public int Current
- {
- get { return 3; }
- }
- public void Dispose ()
- {
- }
- object IEnumerator.Current
- {
- get { throw new NotImplementedException (); }
- }
- public bool MoveNext ()
- {
- if (current == Parent.Count)
- return false;
- current++;
- return true;
- }
- public void Reset ()
- {
- throw new NotImplementedException ();
- }
- }
- public static void AssertException<T> (Action action) where T : Exception
- {
- try {
- action ();
- }
- catch (T) {
- return;
- }
- Assert.Fail ("Expected: " + typeof (T).Name);
- }
- static void AssertAreSame<K, V> (K expectedKey, IEnumerable<V> expectedValues, IGrouping<K, V> actual)
- {
- if (expectedValues == null) {
- Assert.IsNull (actual);
- return;
- }
- Assert.IsNotNull (actual);
- Assert.AreEqual (expectedKey, actual.Key);
- var ee = expectedValues.GetEnumerator ();
- var ea = actual.GetEnumerator ();
- while (ee.MoveNext ()) {
- Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
- Assert.AreEqual (ee.Current, ea.Current);
- }
- if (ea.MoveNext ())
- Assert.Fail ("Unexpected element: " + ee.Current);
- }
- static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, IEnumerable<IGrouping<K, V>> actual)
- {
- if (expected == null) {
- Assert.IsNull (actual);
- return;
- }
- Assert.IsNotNull (actual);
- var ee = expected.GetEnumerator ();
- var ea = actual.GetEnumerator ();
- while (ee.MoveNext ()) {
- Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
- AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
- }
- if (ea.MoveNext ())
- Assert.Fail ("Unexpected element: " + ee.Current.Key);
- }
- static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, ILookup<K, V> actual)
- {
- if (expected == null) {
- Assert.IsNull (actual);
- return;
- }
- Assert.IsNotNull (actual);
- var ee = expected.GetEnumerator ();
- var ea = actual.GetEnumerator ();
- while (ee.MoveNext ()) {
- Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
- AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
- }
- if (ea.MoveNext ())
- Assert.Fail ("Unexpected element: " + ee.Current.Key);
- }
- static void AssertAreSame<K, V> (IDictionary<K, V> expected, IDictionary<K, V> actual)
- {
- if (expected == null) {
- Assert.IsNull (actual);
- return;
- }
- Assert.IsNotNull (actual);
- var ee = expected.GetEnumerator ();
- var ea = actual.GetEnumerator ();
- while (ee.MoveNext ()) {
- Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + ", " + ee.Current.Value + "' expected.");
- Assert.AreEqual (ee.Current.Key, ea.Current.Key);
- Assert.AreEqual (ee.Current.Value, ea.Current.Value);
- }
- if (ea.MoveNext ())
- Assert.Fail ("Unexpected element: " + ee.Current.Key + ", " + ee.Current.Value);
- }
- static void AssertAreSame<T> (IEnumerable<T> expected, IEnumerable<T> actual)
- {
- if (expected == null) {
- Assert.IsNull (actual);
- return;
- }
- Assert.IsNotNull (actual);
- IEnumerator<T> ee = expected.GetEnumerator ();
- IEnumerator<T> ea = actual.GetEnumerator ();
- while (ee.MoveNext ()) {
- Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
- Assert.AreEqual (ee.Current, ea.Current);
- }
- if (ea.MoveNext ())
- Assert.Fail ("Unexpected element: " + ea.Current);
- }
- [Test]
- public void FirstArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // First<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).First (); });
- // First<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).First ((x => true)); });
- AssertException<ArgumentNullException> (delegate () { data.First ((Func<string, bool>) null); });
- }
- [Test]
- public void FirstTest ()
- {
- int [] data = { 2, 1, 5, 3, 4 };
- int [] empty = { };
- // First<TSource> ()
- Assert.AreEqual (2, data.First ());
- AssertException<InvalidOperationException> (delegate () { empty.First (); });
- // First<TSource> (Func<TSource, bool>)
- Assert.AreEqual (5, data.First (x => x == 5));
- AssertException<InvalidOperationException> (delegate () { empty.First (x => x == 5); });
- AssertException<InvalidOperationException> (delegate () { data.First (x => x == 6); });
- }
- [Test]
- public void FirstOrDefaultArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // FirstOrDefault<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).FirstOrDefault (); });
- // FirstOrDefault<TSource> (Func<string, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).FirstOrDefault ((x => true)); });
- AssertException<ArgumentNullException> (delegate () { data.FirstOrDefault ((Func<string, bool>) null); });
- }
- [Test]
- public void FirstOrDefaultTest ()
- {
- int [] data = { 2, 1, 5, 3, 4 };
- int [] empty = { };
- // FirstOrDefault<TSource> ()
- Assert.AreEqual (2, data.FirstOrDefault ());
- Assert.AreEqual (0, empty.FirstOrDefault ());
- // FirstOrDefault<TSource> (Func<TSource, bool>)
- Assert.AreEqual (5, data.FirstOrDefault (x => x == 5));
- Assert.AreEqual (0, empty.FirstOrDefault (x => x == 5));
- Assert.AreEqual (0, data.FirstOrDefault (x => x == 6));
- }
- [Test]
- public void LastArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Last<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Last (); });
- // Last<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Last (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.Last ((Func<string, bool>) null); });
- }
- [Test]
- public void LastTest ()
- {
- int [] data = { 2, 1, 1, 3, 4, 5 };
- int [] empty = { };
- // Last<TSource> ()
- Assert.AreEqual (5, data.Last ());
- AssertException<InvalidOperationException> (delegate () { empty.Last (); });
- // Last<TSource> (Func<TSource, bool>)
- Assert.AreEqual (4, data.Last (x => x < 5));
- AssertException<InvalidOperationException> (delegate () { empty.Last (x => x == 5); });
- AssertException<InvalidOperationException> (delegate () { data.Last (x => x == 6); });
- }
- [Test]
- public void LastOrDefaultArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // LastOrDefault<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LastOrDefault (); });
- // LastOrDefault<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LastOrDefault (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.LastOrDefault ((Func<string, bool>) null); });
- }
- [Test]
- public void LastOrDefaultTest ()
- {
- int [] data = { 2, 1, 5, 3, 4 };
- int [] empty = { };
- // LastOrDefault<TSource> ()
- Assert.AreEqual (4, data.LastOrDefault ());
- Assert.AreEqual (0, empty.LastOrDefault ());
- // LastOrDefault<TSource> (Func<TSource, bool>)
- Assert.AreEqual (3, data.LastOrDefault (x => x < 4));
- Assert.AreEqual (0, empty.LastOrDefault (x => x == 5));
- Assert.AreEqual (0, data.LastOrDefault (x => x == 6));
- }
- [Test]
- public void SingleArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Single<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Single (); });
- // Single<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Single ((x => true)); });
- AssertException<ArgumentNullException> (delegate () { data.Single ((Func<string, bool>) null); });
- }
- [Test]
- public void SingleTest ()
- {
- int [] data = { 2 };
- int [] data2 = { 2, 3, 5 };
- int [] empty = { };
- // Single<TSource> ()
- Assert.AreEqual (2, data.Single ());
- AssertException<InvalidOperationException> (delegate () { data2.Single (); });
- AssertException<InvalidOperationException> (delegate () { empty.Single (); });
- // Single<TSource> (Func<TSource, bool>)
- Assert.AreEqual (5, data2.Single (x => x == 5));
- AssertException<InvalidOperationException> (delegate () { data2.Single (x => false); });
- AssertException<InvalidOperationException> (delegate () { data2.Single (x => true); });
- AssertException<InvalidOperationException> (delegate () { empty.Single (x => true); });
- }
- [Test]
- public void SingleOrDefaultArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // SingleOrDefault<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SingleOrDefault (); });
- // SingleOrDefault<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SingleOrDefault (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.SingleOrDefault ((Func<string, bool>) null); });
- }
- [Test]
- public void SingleOrDefaultTest ()
- {
- int [] data = { 2 };
- int [] data2 = { 2, 3, 5 };
- int [] empty = { };
- // SingleOrDefault<TSource> ()
- Assert.AreEqual (2, data.SingleOrDefault ());
- Assert.AreEqual (0, empty.SingleOrDefault ());
- AssertException<InvalidOperationException> (delegate () { data2.SingleOrDefault (); });
- // SingleOrDefault<TSource> (Func<TSource, bool>)
- Assert.AreEqual (3, data2.SingleOrDefault (x => x == 3));
- Assert.AreEqual (0, data2.SingleOrDefault (x => false));
- AssertException<InvalidOperationException> (delegate () { data2.SingleOrDefault (x => true); });
- }
- [Test]
- public void ElementAtArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // ElementAt<TSource> (int)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ElementAt (0); });
- }
- [Test]
- public void ElementAtTest ()
- {
- int [] data = { 2, 3, 4, 5 };
- // ElementAt<string> (int)
- Assert.AreEqual (2, data.ElementAt (0));
- Assert.AreEqual (4, data.ElementAt (2));
- AssertException<ArgumentOutOfRangeException> (delegate () { data.ElementAt (-1); });
- AssertException<ArgumentOutOfRangeException> (delegate () { data.ElementAt (4); });
- AssertException<ArgumentOutOfRangeException> (delegate () { data.ElementAt (6); });
- }
- [Test]
- public void ElementAtOrDefaultArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // ElementAtOrDefault<TSource> (int)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ElementAtOrDefault (0); });
- }
- [Test]
- public void ElementAtOrDefaultTest ()
- {
- int [] data = { 2, 3, 4, 5 };
- int [] empty = { };
- // ElementAtOrDefault<TSource> (int)
- Assert.AreEqual (2, data.ElementAtOrDefault (0));
- Assert.AreEqual (4, data.ElementAtOrDefault (2));
- Assert.AreEqual (0, data.ElementAtOrDefault (-1));
- Assert.AreEqual (0, data.ElementAtOrDefault (4));
- Assert.AreEqual (0, empty.ElementAtOrDefault (4));
- }
- [Test]
- public void EmptyTest ()
- {
- IEnumerable<string> empty = Enumerable.Empty<string> ();
- Assert.IsFalse (empty.GetEnumerator ().MoveNext ());
- }
- [Test]
- public void AnyArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Any<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Any (); });
- // Any<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Any (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.Any ((Func<string, bool>) null); });
- }
- [Test]
- public void AnyTest ()
- {
- int [] data = { 5, 2, 3, 1, 6 };
- int [] empty = { };
- // Any<TSource> ()
- Assert.IsTrue (data.Any ());
- Assert.IsFalse (empty.Any ());
- // Any<TSource> (Func<TSource, bool>)
- Assert.IsTrue (data.Any (x => x == 5));
- Assert.IsFalse (data.Any (x => x == 9));
- Assert.IsFalse (empty.Any (x => true));
- }
- [Test]
- public void AllArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // All<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).All (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.All ((Func<string, bool>) null); });
- }
- [Test]
- public void AllTest ()
- {
- int [] data = { 5, 2, 3, 1, 6 };
- int [] empty = { };
- // All<TSource> (Func<TSource, bool>)
- Assert.IsTrue (data.All (x => true));
- Assert.IsFalse (data.All (x => x != 1));
- Assert.IsTrue (empty.All (x => false));
- }
- [Test]
- public void CountArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Count<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Count (); });
- // Count<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Count (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.Count ((Func<string, bool>) null); });
- }
- [Test]
- public void CountTest ()
- {
- int [] data = { 5, 2, 3, 1, 6 };
- // Count<TSource> ()
- Assert.AreEqual (5, data.Count ());
- // Count<TSource> (Func<TSource, bool>)
- Assert.AreEqual (3, data.Count (x => x < 5));
- }
- //[Test]
- public void CountOverflowTest ()
- {
- //BigEnumerable data = new BigEnumerable ((ulong) int.MaxValue + 1);
- // Count<TSource> ()
- //AssertException<OverflowException> (delegate () { data.Count (); });
- // Count<TSource> (Func<TSource, bool>)
- //AssertException<OverflowException> (delegate () { data.Count (x => 3 == x); });
- // Documentation error: http://msdn2.microsoft.com/en-us/library/bb535181.aspx
- // An exception is only rasied if count > int.MaxValue. Not if source contains more than int.MaxValue elements.
- // AssertException<OverflowException> (delegate () { data.Count (x => 5 == x); });
- }
- [Test]
- public void LongCountArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // LongCount<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LongCount (); });
- // LongCount<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LongCount (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.LongCount ((Func<string, bool>) null); });
- }
- [Test]
- public void LongCountTest ()
- {
- int [] data = { 5, 2, 3, 1, 6 };
- //TODO: Overflow test...
- // LongCount<TSource> ()
- Assert.AreEqual (5, data.LongCount ());
- Assert.AreEqual (5, Enumerable.Range (0, 5).LongCount ());
- // LongCount<TSource> (Func<TSource, bool>)
- Assert.AreEqual (3, data.LongCount (x => x < 5));
- }
- [Test]
- public void ContainsArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // Contains<TSource> (TSource)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Contains ("2"); });
- // Contains<TSource> (TSource, IEqualityComparer<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Contains ("2", (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- }
- static void IsFalse(bool b, int[] data) {
- if (b) {
- Console.WriteLine (data.Contains (0));
- object o = null;
- o.ToString ();
- Assert.IsFalse (true);
- }
- //Console.WriteLine ("HIT!");
- }
- [Test]
- public void ContainsTest ()
- {
- int [] data = { 5, 2, 3, 1, 6 };
- ICollection<int> icoll = data;
- // Contains<TSource> (TSource)
- Assert.IsTrue (data.Contains (2));
- for (int i = 0; i < 50; ++i)
- icoll.Contains (i);//Console.WriteLine (data.Contains (0));
- IsFalse (data.Contains (0), data);
- // Contains<TSource> (TSource, IEqualityComparer<TSource>)
- Assert.IsTrue (data.Contains (2, EqualityComparer<int>.Default));
- Assert.IsFalse (data.Contains (0, EqualityComparer<int>.Default));
- }
- [Test]
- public void AggregateArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Aggregate<TSource> (Func<TSource, TSource, TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ((x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Aggregate ((Func<string, string, string>) null); });
- // Aggregate<TSource,TAccumulate> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ("initial", (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (Func<string, string, string>) null); });
- // Aggregate<TSource,TAccumulate,TResult> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ("initial", (x, y) => "test", x => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (Func<string, string, string>) null, x => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (x, y) => "test", (Func<string, string>) null); });
- }
- [Test]
- public void AggregateTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- string [] empty = { };
- // Aggregate<TSource> (Func<TSource, TSource, TSource>)
- Assert.AreEqual ("21534", data.Aggregate ((x, y) => x + y));
- AssertException<InvalidOperationException> (delegate () { empty.Aggregate ((x, y) => x + y); }); //only this overload throws
- // Aggregate<TSource,TAccumulate> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
- Assert.AreEqual ("initial21534", (data.Aggregate ("initial", (x, y) => x + y)));
- // Aggregate<TSource,TAccumulate,TResult> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)
- Assert.AreEqual ("INITIAL21534", data.Aggregate ("initial", (x, y) => x + y, (x => x.ToUpper ())));
- }
- [Test]
- public void SumArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Sum<TSource> (Func<TSource, int>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, int>) (x => 0)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, int>) null); });
- // Sum<TSource> (Func<TSource, Nullable<int>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<int>>) null); });
- // Sum<TSource> (Func<TSource, Int64>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Int64>) (x => 0L)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Int64>) null); });
- // Sum<TSource> (Func<TSource, Nullable<Int64>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Int64>>) null); });
- // Sum<TSource> (Func<TSource, Single>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Single>) (x => 0f)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Single>) null); });
- // Sum<TSource> (Func<TSource, Nullable<Single>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Single>>) null); });
- // Sum<TSource> (Func<TSource, Double>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Double>) (x => 0d)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Double>) null); });
- // Sum<TSource> (Func<TSource, Nullable<Double>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Double>>) null); });
- // Sum<TSource> (Func<TSource, Decimal>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Decimal>) (x => 0m)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Decimal>) null); });
- // Sum<TSource> (Func<TSource, Nullable<Decimal>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
- AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Decimal>>) null); });
- // Sum (IEnumerable<int>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Sum (); });
- // Sum (IEnumerable<int?>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Sum (); });
- // Sum (IEnumerable<long>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Sum (); });
- // Sum (IEnumerable<long?>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Sum (); });
- // Sum (IEnumerable<float>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Sum (); });
- // Sum (IEnumerable<float?>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Sum (); });
- // Sum (IEnumerable<double>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Sum (); });
- // Sum (IEnumerable<double?>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Sum (); });
- // Sum (IEnumerable<decimal>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Sum (); });
- // Sum (IEnumerable<decimal?>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Sum (); });
- }
- [Test]
- public void SumTest ()
- {
- string [] data = { "2", "3", "5", "5" };
- //TODO: OverflowException
- // Sum<TSource> (Func<TSource, int>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, int>) (x => int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, int>) (x => int.Parse (x))));
- // Sum<TSource> (Func<TSource, Nullable<int>>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
- // Sum<TSource> (Func<TSource, Int64>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
- // Sum<TSource> (Func<TSource, Nullable<Int64>>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
- // Sum<TSource> (Func<TSource, Single>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
- // Sum<TSource> (Func<TSource, Nullable<Single>>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
- // Sum<TSource> (Func<TSource, Double>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
- // Sum<TSource> (Func<TSource, Nullable<Double>>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
- // Sum<TSource> (Func<TSource, Decimal>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
- // Sum<TSource> (Func<TSource, Nullable<Decimal>>)
- Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
- Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<int>) new int [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<int> ().Sum ());
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<Nullable<int>>) new int? [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<int?> ().Sum ());
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<Int64>) new long [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<long> ().Sum ());
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<Nullable<Int64>>) new long? [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<long?> ().Sum ());
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<Single>) new float [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<float> ().Sum ());
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<Nullable<Single>>) new float? [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<float?> ().Sum ());
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<Double>) new double [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<double> ().Sum ());
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<Nullable<Double>>) new double? [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<double?> ().Sum ());
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<Decimal>) new decimal [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<decimal> ().Sum ());
- // Sum<> ()
- Assert.AreEqual (6, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 1, 2, 3 }).Sum ());
- Assert.AreEqual (0, Enumerable.Empty<decimal?> ().Sum ());
- }
- [Test]
- public void MinArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Min<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> (); });
- // Min<TSource> (Func<TSource, int>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, int>) (x => 0)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, int>) null); });
- // Min<TSource> (Func<TSource, Nullable<int>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<int>>) null); });
- // Min<TSource> (Func<TSource, Int64>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Int64>) (x => 0L)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Int64>) null); });
- // Min<TSource> (Func<TSource, Nullable<Int64>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Int64>>) null); });
- // Min<TSource> (Func<TSource, Single>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Single>) (x => 0f)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Single>) null); });
- // Min<TSource> (Func<TSource, Nullable<Single>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Single>>) null); });
- // Min<TSource> (Func<TSource, Double>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Double>) (x => 0d)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Double>) null); });
- // Min<TSource> (Func<TSource, Nullable<Double>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Double>>) null); });
- // Min<TSource> (Func<TSource, Decimal>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Decimal>) (x => 0m)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Decimal>) null); });
- // Min<TSource> (Func<TSource, Nullable<Decimal>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Decimal>>) null); });
- // Min<TSource,TSource> (Func<TSource, string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string, string> ((Func<string, string>) (x => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.Min<string, string> ((Func<string, string>) null); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Min (); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Min (); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Min (); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Min (); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Min (); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Min (); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Min (); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Min (); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Min (); });
- // Min<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Min (); });
- }
- [Test]
- public void MinTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Min<TSource> ()
- Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string> ());
- // Min<TSource> (Func<TSource, int>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, int>) (x => int.Parse (x))));
- // Min<TSource> (Func<TSource, Nullable<int>>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
- // Min<TSource> (Func<TSource, Int64>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Int64>) (x => int.Parse (x))));
- // Min<TSource> (Func<TSource, Nullable<Int64>>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
- // Min<TSource> (Func<TSource, Single>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Single>) (x => int.Parse (x))));
- // Min<TSource> (Func<TSource, Nullable<Single>>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
- // Min<TSource> (Func<TSource, Double>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Double>) (x => int.Parse (x))));
- // Min<TSource> (Func<TSource, Nullable<Double>>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
- // Min<TSource> (Func<TSource, Decimal>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Decimal>) (x => int.Parse (x))));
- // Min<TSource> (Func<TSource, Nullable<Decimal>>)
- Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
- // Min<TSource,TSource> (Func<TSource, TSource>)
- Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string, string> ((Func<string, string>) (x => x)));
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Min ());
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Min ());
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Min ());
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Min ());
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Min ());
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Min ());
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Min ());
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Min ());
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Min ());
- // Min<> ()
- Assert.AreEqual (2, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Min ());
- }
- [Test]
- public void MaxArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Max<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> (); });
- // Max<TSource> (Func<TSource, int>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, int>) (x => 0)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, int>) null); });
- // Max<TSource> (Func<TSource, Nullable<int>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<int>>) null); });
- // Max<TSource> (Func<TSource, Int64>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Int64>) (x => 0L)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Int64>) null); });
- // Max<TSource> (Func<TSource, Nullable<Int64>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Int64>>) null); });
- // Max<TSource> (Func<TSource, Single>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Single>) (x => 0f)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Single>) null); });
- // Max<TSource> (Func<TSource, Nullable<Single>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Single>>) null); });
- // Max<TSource> (Func<TSource, Double>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Double>) (x => 0d)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Double>) null); });
- // Max<TSource> (Func<TSource, Nullable<Double>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Double>>) null); });
- // Max<TSource> (Func<TSource, Decimal>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Decimal>) (x => 0m)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Decimal>) null); });
- // Max<TSource> (Func<TSource, Nullable<Decimal>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Decimal>>) null); });
- // Max<TSource,TSource> (Func<TSource, TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string, string> ((Func<string, string>) (x => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.Max<string, string> ((Func<string, string>) null); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Max (); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Max (); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Max (); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Max (); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Max (); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Max (); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Max (); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Max (); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Max (); });
- // Max<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Max (); });
- }
- [Test]
- public void MaxTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Max<string> ()
- Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string> ());
- // Max<TSource> (Func<TSource, int>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, int>) (x => int.Parse (x))));
- // Max<TSource> (Func<TSource, Nullable<int>>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
- // Max<TSource> (Func<TSource, Int64>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Int64>) (x => int.Parse (x))));
- // Max<TSource> (Func<TSource, Nullable<Int64>>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
- // Max<TSource> (Func<TSource, Single>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Single>) (x => int.Parse (x))));
- // Max<TSource> (Func<TSource, Nullable<Single>>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
- // Max<TSource> (Func<TSource, Double>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Double>) (x => int.Parse (x))));
- // Max<TSource> (Func<TSource, Nullable<Double>>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
- // Max<TSource> (Func<TSource, Decimal>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Decimal>) (x => int.Parse (x))));
- // Max<TSource> (Func<TSource, Nullable<Decimal>>)
- Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
- // Max<TSource,TSource> (Func<TSource, TSource>)
- Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string, string> ((Func<string, string>) (x => x)));
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Max ());
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Max ());
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Max ());
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Max ());
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Max ());
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Max ());
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Max ());
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Max ());
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Max ());
- // Max<> ()
- Assert.AreEqual (4, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Max ());
- }
- [Test]
- public void AverageArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Average<TSource> (Func<TSource, int>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, int>) (x => 0)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, int>) null); });
- // Average<TSource> (Func<TSource, Nullable<int>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<int>>) null); });
- // Average<TSource> (Func<TSource, Int64>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Int64>) (x => 0L)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Int64>) null); });
- // Average<TSource> (Func<TSource, Nullable<Int64>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Int64>>) null); });
- // Average<TSource> (Func<TSource, Single>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Single>) (x => 0f)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Single>) null); });
- // Average<TSource> (Func<TSource, Nullable<Single>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Single>>) null); });
- // Average<TSource> (Func<TSource, Double>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Double>) (x => 0d)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Double>) null); });
- // Average<TSource> (Func<TSource, Nullable<Double>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Double>>) null); });
- // Average<TSource> (Func<TSource, Decimal>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Decimal>) (x => 0m)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Decimal>) null); });
- // Average<TSource> (Func<TSource, Nullable<Decimal>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
- AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Decimal>>) null); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Average (); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Average (); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Average (); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Average (); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Average (); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Average (); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Average (); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Average (); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Average (); });
- // Average<> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Average (); });
- }
- [Test]
- public void AverageTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- string [] empty = { };
- // Average<string> (Func<string, int>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, int>) (x => int.Parse (x))));
- AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, int>) (x => int.Parse (x))); });
- // Average<TSource> (Func<TSource, Nullable<int>>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
- // Average<TSource> (Func<TSource, Int64>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long>) (x => int.Parse (x))));
- AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, long>) (x => int.Parse (x))); });
- // Average<TSource> (Func<TSource, Nullable<Int64>>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long?>) (x => (int?) int.Parse (x))));
- // Average<TSource> (Func<TSource, Single>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float>) (x => int.Parse (x))));
- AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, float>) (x => int.Parse (x))); });
- // Average<TSource> (Func<TSource, Nullable<Single>>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float?>) (x => (int?) int.Parse (x))));
- // Average<TSource> (Func<TSource, Double>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double>) (x => int.Parse (x))));
- AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, double>) (x => int.Parse (x))); });
- // Average<TSource> (Func<TSource, Nullable<Double>>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double?>) (x => (int?) int.Parse (x))));
- // Average<TSource> (Func<TSource, Decimal>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal>) (x => int.Parse (x))));
- AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, decimal>) (x => int.Parse (x))); });
- // Average<TSource> (Func<TSource, Nullable<Decimal>>)
- Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal?>) (x => (int?) int.Parse (x))));
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Average ());
- AssertException<InvalidOperationException> (delegate () { new int [0].Average (); });
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Average ());
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Average ());
- AssertException<InvalidOperationException> (delegate () { new long [0].Average (); });
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Average ());
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Average ());
- AssertException<InvalidOperationException> (delegate () { new float [0].Average (); });
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Average ());
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Average ());
- AssertException<InvalidOperationException> (delegate () { new double [0].Average (); });
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Average ());
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Average ());
- AssertException<InvalidOperationException> (delegate () { new decimal [0].Average (); });
- // Average<> ()
- Assert.AreEqual (3, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Average ());
- }
- [Test]
- public void WhereArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Where<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, bool>) null); });
- // Where<TSource> (Func<TSource, int, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where ((x, y) => true); });
- AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, int, bool>) null); });
- }
- [Test]
- public void WhereTest ()
- {
- int [] data = { 2, 1, 5, 3, 4 };
- int [] expected1 = { 2, 1 };
- int [] expected2 = { 2 };
- // Where<TSource> (Func<TSource, bool>)
- AssertAreSame (expected1, data.Where (x => x < 3));
- // Where<TSource> (Func<TSource, int, bool>)
- AssertAreSame (expected2, data.Where ((x, y) => x < 3 && y != 1));
- }
- [Test]
- public void SelectArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Select<TSource,TResult> (Func<TSource, TResult>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select (x => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, string>) null); });
- // Select<TSource,TResult> (Func<TSource, int, TResult>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select ((x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, int, string>) null); });
- }
- [Test]
- public void SelectTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- string [] expected1 = { "2x", "1x", "5x", "3x", "4x" };
- string [] expected2 = { "2x0", "1x1", "5x2", "3x3", "4x4" };
- // Select<TSource,TResult> (Func<TSource, TResult>)
- AssertAreSame (expected1, data.Select<string, string> (x => x + "x"));
- // Select<TSource,TResult> (Func<TSource, int, TResult>)
- AssertAreSame (expected2, data.Select<string, string> ((x, y) => x + "x" + y));
- }
- [Test]
- public void SelectManyArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data); });
- AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null); });
- // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data); });
- AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null); });
- // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data, (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null, (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.SelectMany ((x, y) => data, (Func<string, string, string>) null); });
- // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data, (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null, (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.SelectMany (x => data, (Func<string, string, string>) null); });
- }
- [Test]
- public void SelectManyTest ()
- {
- string [] data = { "0", "1" };
- string [] expected = { "0", "00", "1", "11" };
- // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
- AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }));
- // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
- AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }));
- // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
- AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }, (x, y) => y));
- // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
- AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }, (x, y) => y));
- }
- [Test]
- public void TakeArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // Take<TSource> (int)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Take (0); });
- }
- [Test]
- public void TakeTest ()
- {
- int [] data = { 2, 1, 5, 3, 1 };
- int [] expected = { 2, 1 };
- int [] empty = { };
- // Take<TSource> (int)
- AssertAreSame (expected, data.Take (2));
- AssertAreSame (empty, data.Take (-2));
- }
- [Test]
- public void TakeWhileArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // TakeWhile<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, bool>) null); });
- // TakeWhile<TSource> (Func<TSource, int, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile ((x, y) => true); });
- AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, int, bool>) null); });
- }
- [Test]
- public void TakeWhileTest ()
- {
- int [] data = { 2, 1, 5, 3, 1 };
- int [] expected = { 2, 1 };
- // TakeWhile<TSource> (Func<TSource, bool>)
- AssertAreSame (expected, data.TakeWhile (x => x != 5));
- // TakeWhile<TSource> (Func<TSource, int, bool>)
- AssertAreSame (expected, data.TakeWhile ((x, y) => y != 2));
- }
- [Test]
- public void SkipArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // Skip<TSource> (int)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Skip (0); });
- }
- [Test]
- public void SkipTest ()
- {
- int [] data = { 2, 1, 5, 3, 1 };
- int [] expected = { 5, 3, 1 };
- // Skip<string> (TSource)
- AssertAreSame (expected, data.Skip (2));
- AssertAreSame (data, data.Skip (-2));
- }
- [Test]
- public void SkipWhileArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // SkipWhile<TSource> (Func<TSource, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile (x => true); });
- AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, bool>) null); });
- // SkipWhile<TSource> (Func<TSource, int, bool>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile ((x, y) => true); });
- AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, int, bool>) null); });
- }
- [Test]
- public void SkipWhileTest ()
- {
- int [] data = { 2, 1, 5, 3, 1 };
- int [] expected = { 5, 3, 1 };
- // SkipWhile<TSource> (Func<TSource, bool>)
- AssertAreSame (expected, data.SkipWhile (x => x != 5));
- // SkipWhile<TSource> (Func<TSource, int, bool>)
- AssertAreSame (expected, data.SkipWhile ((x, y) => y != 2));
- }
- [Test]
- public void JoinArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null); });
- // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null, EqualityComparer<string>.Default); });
- }
- [Test]
- public void JoinTest ()
- {
- string [] dataOuter1 = { "2", "1", "5", "3", "4" };
- string [] dataInner1 = { "7", "3", "5", "8", "9" };
- string [] expected1 = { "55", "33" };
- string [] dataOuter2 = { "2", "1", "3", "4" };
- string [] dataInner2 = { "7", "5", "8", "9" };
- string [] expected2 = { };
- // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
- AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y));
- AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y));
- // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
- AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
- AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
- }
- [Test]
- public void JoinTestNullKeys ()
- {
- var l1 = new [] {
- new { Name = "name1", Nullable = (int?) null },
- new { Name = "name2", Nullable = (int?) null }
- };
- var count = l1.Join (l1, i => i.Nullable, i => i.Nullable, (x, y) => x.Name).Count ();
- Assert.AreEqual (0, count);
- }
- [Test]
- public void GroupJoinArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null); });
- // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null, EqualityComparer<string>.Default); });
- }
- [Test]
- public void GroupJoinTest ()
- {
- string [] dataOuter1 = { "2", "1", "5", "3", "4" };
- string [] dataInner1 = { "7", "3", "5", "3", "9" };
- string [] expected1 = { "2", "1", "55", "333", "4" };
- string [] dataOuter2 = { "2", "1", "5", "8", "4" };
- string [] dataInner2 = { "7", "3", "6", "3", "9" };
- string [] expected2 = { "2", "1", "5", "8", "4" };
- // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
- AssertAreSame (expected1, (dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
- AssertAreSame (expected2, (dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
- // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
- AssertAreSame (expected1, dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
- AssertAreSame (expected2, dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
- }
- [Test]
- public void GroupJoinWithNullKeys ()
- {
- string[] l1 = { null };
- string[] l2 = { null, null };
- var res = l1.GroupJoin (l2, x => x, y => y, (a, b) => new { Key = a, Count = b.Count () }).ToArray ();
- Assert.AreEqual (1, res.Length);
- Assert.AreEqual (0, res [0].Count);
- }
- [Test]
- public void OrderByArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // OrderBy<TSource,TKey> (Func<TSource, TKey>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null); });
- // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test", Comparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null, Comparer<string>.Default); });
- }
- [Test]
- public void OrderByTest ()
- {
- int [] data = { 2, 1, 5, 3, 4 };
- int [] expected = { 1, 2, 3, 4, 5 };
- // OrderBy<TSource,TKey> (Func<TSource, TKey>)
- AssertAreSame (expected, data.OrderBy (x => x));
- // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
- AssertAreSame (expected, data.OrderBy (x => x, Comparer<int>.Default));
- }
- [Test]
- public void OrderByDescendingArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null); });
- // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test", Comparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null, Comparer<string>.Default); });
- }
- [Test]
- public void OrderByDescendingTest ()
- {
- int [] data = { 2, 1, 5, 3, 4 };
- int [] expected = { 5, 4, 3, 2, 1 };
- // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
- AssertAreSame (expected, data.OrderByDescending (x => x));
- // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
- AssertAreSame (expected, data.OrderByDescending (x => x, Comparer<int>.Default));
- }
- [Test]
- public void ThenByArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // ThenBy<TSource,TKey> (Func<TSource, TKey>)
- AssertException<ArgumentNullException> (delegate () {
- ((IOrderedEnumerable<string>) null).ThenBy (x => "test");
- });
- AssertException<ArgumentNullException> (delegate () {
- data.OrderBy (x => x).ThenBy ((Func<string, string>) null);
- });
- // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
- AssertException<ArgumentNullException> (delegate () {
- ((IOrderedEnumerable<string>) null).ThenBy (x => "test", Comparer<string>.Default);
- });
- AssertException<ArgumentNullException> (delegate () {
- data.OrderBy (x => x).ThenBy ((Func<string, string>) null, Comparer<string>.Default);
- });
- }
- [Test]
- public void ThenByTest ()
- {
- int [] data = { 2, 1, 5, 3, 4 };
- int [] expected = { 1, 2, 3, 4, 5 };
- // ThenBy<TSource,TKey> (Func<TSource, TKey>)
- AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x));
- // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
- AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x, Comparer<int>.Default));
- }
- [Test]
- public void ThenByDescendingArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
- AssertException<ArgumentNullException> (delegate () {
- ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test");
- });
- AssertException<ArgumentNullException> (delegate () {
- data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null);
- });
- // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
- AssertException<ArgumentNullException> (delegate () {
- ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test", Comparer<string>.Default);
- });
- AssertException<ArgumentNullException> (delegate () {
- data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null, Comparer<string>.Default);
- });
- }
- [Test]
- public void ThenByDescendingTest ()
- {
- int [] data = { 2, 1, 5, 3, 4 };
- int [] expected = { 5, 4, 3, 2, 1 };
- // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
- AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x));
- // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
- AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x, Comparer<int>.Default));
- }
- [Test]
- public void GroupByArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // GroupBy<string,string> (Func<string, string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null); });
- // GroupBy<string,string> (Func<string, string>, IEqualityComparer<string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- // GroupBy<string,string,string> (Func<string, string>, Func<string, string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
- // GroupBy<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
- 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); });
- AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null); });
- // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>)
- 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")); });
- 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")); });
- 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")); });
- 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); });
- // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
- 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); });
- 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); });
- AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
- 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); });
- 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); });
- 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); });
- 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); });
- }
- [Test]
- public void GroupByTest ()
- {
- string [] data = { "2", "1", "5", "3", "4", "3" };
- Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
- expected.Add ("2", new List<string> () { "2" });
- expected.Add ("1", new List<string> () { "1" });
- expected.Add ("5", new List<string> () { "5" });
- expected.Add ("3", new List<string> () { "3", "3" });
- expected.Add ("4", new List<string> () { "4" });
- Dictionary<string, IEnumerable<string>> expected2 = new Dictionary<string, IEnumerable<string>> ();
- expected2.Add ("2", new List<string> () { "22" });
- expected2.Add ("1", new List<string> () { "11" });
- expected2.Add ("5", new List<string> () { "55" });
- expected2.Add ("3", new List<string> () { "33", "33" });
- expected2.Add ("4", new List<string> () { "44" });
- string [] expected3 = new string [] { "22", "11", "55", "333", "44" };
- // GroupBy<int,int> (Func<int, int>)
- AssertAreSame (expected, data.GroupBy (x => x));
- // GroupBy<int,int> (Func<int, int>, IEqualityComparer<int>)
- AssertAreSame (expected, data.GroupBy (x => x, EqualityComparer<string>.Default));
- // GroupBy<int,int,int> (Func<int, int>, Func<int, int>)
- AssertAreSame (expected2, data.GroupBy (x => x, x => x + x));
- // GroupBy<int,int,int> (Func<int, int>, Func<int, int>, IEqualityComparer<int>)
- AssertAreSame (expected2, data.GroupBy (x => x, x => x + x, EqualityComparer<string>.Default));
- // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>)
- AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
- // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>)
- AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
- // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
- AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
- // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
- AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
- }
- class Data {
- public int Number;
- public string String;
- public Data (int number, string str)
- {
- Number = number;
- String = str;
- }
- }
- [Test]
- public void GroupByLastNullGroup ()
- {
- var values = new List<Data> ();
- values.Add (new Data (0, "a"));
- values.Add (new Data (1, "a"));
- values.Add (new Data (2, "b"));
- values.Add (new Data (3, "b"));
- values.Add (new Data (4, null));
- var groups = values.GroupBy (d => d.String);
- Assert.AreEqual (3, groups.Count ());
- }
- [Test]
- public void ConcatArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Concat<TSource> (IEnumerable<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Concat (data); });
- AssertException<ArgumentNullException> (delegate () { data.Concat ((IEnumerable<string>) null); });
- }
- [Test]
- public void ConcatTest ()
- {
- int [] data1 = { 2, 1, 5, 3, 4 };
- int [] data2 = { 1, 2, 3, 4, 5 };
- int [] expected = { 2, 1, 5, 3, 4, 1, 2, 3, 4, 5 };
- // Concat<TSource> (IEnumerable<TSource>)
- AssertAreSame (expected, data1.Concat (data2));
- }
- [Test]
- public void DistinctArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // Distinct<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (); });
- // Distinct<TSource> (IEqualityComparer<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (EqualityComparer<string>.Default); });
- }
- [Test]
- public void DistinctTest ()
- {
- int [] data = { 2, 1, 5, 3, 4, 2, 5, 3, 1, 8 };
- int [] expected = { 2, 1, 5, 3, 4, 8 };
- // Distinct<TSource> ()
- AssertAreSame (expected, data.Distinct ());
- // Distinct<iTSourcent> (IEqualityComparer<TSource>)
- AssertAreSame (expected, data.Distinct (EqualityComparer<int>.Default));
- }
- [Test]
- public void UnionArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Union<TSource> (IEnumerable<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data); });
- AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null); });
- // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data, EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
- }
- [Test]
- public void UnionTest ()
- {
- int [] data1 = { 2, 1, 5, 7, 3, 4 };
- int [] data2 = { 1, 2, 3, 8, 4, 5 };
- int [] expected = { 2, 1, 5, 7, 3, 4, 8 };
- // Union<TSource> (IEnumerable<TSource>)
- AssertAreSame (expected, data1.Union (data2));
- // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
- AssertAreSame (expected, data1.Union (data2, EqualityComparer<int>.Default));
- }
- [Test]
- public void IntersectArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Intersect<TSource> (IEnumerable<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data); });
- AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null); });
- // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data, EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
- }
- [Test]
- public void IntersectTest ()
- {
- int [] data1 = { 2, 1, 5, 7, 3, 4 };
- int [] data2 = { 1, 2, 3, 8, 4, 5 };
- int [] expected = { 2, 1, 5, 3, 4 };
- // Intersect<TSource> (IEnumerable<TSource>)
- AssertAreSame (expected, data1.Intersect (data2));
- // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
- AssertAreSame (expected, data1.Intersect (data2, EqualityComparer<int>.Default));
- }
- [Test]
- public void ExceptArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // Except<TSource> (IEnumerable<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data); });
- AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null); });
- // Except<TSource> (IEnumerable<string>, IEqualityComparer<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data, EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
- }
- [Test]
- public void ExceptTest ()
- {
- int [] data1 = { 2, 1, 5, 7, 3, 4 };
- int [] data2 = { 1, 2, 3, 8, 4, 5 };
- int [] expected = { 7 };
- // Except<TSource> (IEnumerable<TSource>)
- AssertAreSame (expected, data1.Except (data2));
- // Except<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
- AssertAreSame (expected, data1.Except (data2, EqualityComparer<int>.Default));
- }
- [Test]
- public void ReverseArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // Reverse<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Reverse (); });
- }
- [Test]
- public void ReverseTest ()
- {
- int [] data = { 2, 1, 5, 7, 3, 4 };
- int [] expected = { 4, 3, 7, 5, 1, 2 };
- // Reverse<TSource> ()
- AssertAreSame (expected, data.Reverse ());
- }
- [Test]
- public void SequenceEqualArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // SequenceEqual<TSource> (IEnumerable<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data); });
- AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null); });
- // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data, EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
- }
- [Test]
- public void SequenceEqualTest ()
- {
- int [] data1 = { 2, 1, 5, 7, 3, 4 };
- int [] data2 = { 2, 1, 5, 7, 3, 4 };
- int [] data3 = { 2, 1, 5, 7, 3, 4, 5 };
- int [] data4 = { 2, 1, 5, 7, 3 };
- int [] data5 = { 2, 1, 5, 8, 3, 4 };
- // SequenceEqual<TSource> (IEnumerable<TSource>)
- Assert.IsTrue (data1.SequenceEqual (data2));
- Assert.IsFalse (data1.SequenceEqual (data3));
- Assert.IsFalse (data1.SequenceEqual (data4));
- Assert.IsFalse (data1.SequenceEqual (data5));
- // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
- Assert.IsTrue (data1.SequenceEqual (data2, EqualityComparer<int>.Default));
- Assert.IsFalse (data1.SequenceEqual (data3, EqualityComparer<int>.Default));
- Assert.IsFalse (data1.SequenceEqual (data4, EqualityComparer<int>.Default));
- Assert.IsFalse (data1.SequenceEqual (data5, EqualityComparer<int>.Default));
- }
- [Test]
- public void AsEnumerableArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- }
- [Test]
- public void AsEnumerableTest ()
- {
- int [] data = { 2, 1, 5, 7, 3, 4 };
- // AsEnumerable<TSource> ()
- Assert.AreSame (data, data.AsEnumerable ());
- }
- [Test]
- public void ToArrayArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // ToArray<TSource> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToArray (); });
- }
- [Test]
- public void ToArrayTest ()
- {
- int [] data = { 2, 3, 4, 5 };
- int [] expected = { 2, 3, 4, 5 };
- // ToArray<TSource> ()
- AssertAreSame (expected, data.ToArray ());
- }
- [Test]
- public void ToListArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // ToList<string> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToList (); });
- }
- [Test]
- public void ToListTest ()
- {
- int [] data = { 2, 4, 5, 1 };
- int [] expected = { 2, 4, 5, 1 };
- // ToList<int> ()
- AssertAreSame (expected, data.ToList ());
- }
- [Test]
- public void ToDictionaryArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null); });
- // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, EqualityComparer<string>.Default); });
- // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test"); });
- AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null); });
- // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test", EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null, EqualityComparer<string>.Default); });
- }
- [Test]
- public void ToDictionaryTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- Dictionary<string, string> expected = new Dictionary<string, string> ();
- expected.Add ("k2", "2");
- expected.Add ("k1", "1");
- expected.Add ("k5", "5");
- expected.Add ("k3", "3");
- expected.Add ("k4", "4");
- // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
- AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x));
- AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key"); });
- // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
- AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, EqualityComparer<string>.Default));
- AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", EqualityComparer<string>.Default); });
- // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
- AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x));
- AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x); });
- // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
- AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x, EqualityComparer<string>.Default));
- AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x, EqualityComparer<string>.Default); });
- }
- [Test]
- public void ToLookupArgumentNullTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- // ToLookup<string,string> (Func<string, string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null); });
- // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
- AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
- // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
- 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); });
- AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
- }
- [Test]
- public void ToLookupTest ()
- {
- string [] data = { "23", "12", "55", "42", "41" };
- Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
- expected.Add ("2", new List<string> () { "23" });
- expected.Add ("1", new List<string> () { "12" });
- expected.Add ("5", new List<string> () { "55" });
- expected.Add ("4", new List<string> () { "42", "41" });
- Assert.AreEqual (expected.Count, ((IEnumerable<string>)data).ToLookup ((x => x [0].ToString ())).Count);
-
- // ToLookup<string,string> (Func<string, string>)
- AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup ((x => x [0].ToString ())));
- // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
- AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), EqualityComparer<string>.Default));
- // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
- AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x));
- // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
- AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x, EqualityComparer<string>.Default));
- }
-
- [Test]
- public void ToLookupNullKeyTest ()
- {
- string[] strs = new string[] { "one", null, "two", null, "three" };
-
- int i = 0;
- var l = strs.ToLookup (s => (s == null) ? null : "numbers", s => (s == null) ? (++i).ToString() : s);
-
- Assert.AreEqual (2, l.Count);
- Assert.AreEqual (2, l [null].Count());
- Assert.IsTrue (l [null].Contains ("1"));
- Assert.IsTrue (l [null].Contains ("2"));
-
- Assert.AreEqual (3, l ["numbers"].Count());
- Assert.IsTrue (l ["numbers"].Contains ("one"));
- Assert.IsTrue (l ["numbers"].Contains ("two"));
- Assert.IsTrue (l ["numbers"].Contains ("three"));
- }
- [Test]
- public void DefaultIfEmptyArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // DefaultIfEmpty<string> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> (); });
- // DefaultIfEmpty<string> (string)
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> ((string) "default"); });
- }
- [Test]
- public void DefaultIfEmptyTest ()
- {
- string [] data = { "2", "1", "5", "3", "4" };
- string [] empty = { };
- string [] default1 = { null };
- string [] default2 = { "default" };
- // DefaultIfEmpty<string> ()
- AssertAreSame (data, data.DefaultIfEmpty ());
- AssertAreSame (default1, empty.DefaultIfEmpty ());
- // DefaultIfEmpty<string> (string)
- AssertAreSame (data, data.DefaultIfEmpty ("default"));
- AssertAreSame (default2, empty.DefaultIfEmpty ("default"));
- }
- [Test]
- public void OfTypeArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // OfType<string> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).OfType<string> (); });
- }
- [Test]
- public void OfTypeTest ()
- {
- object [] data = { "2", 2, "1", "5", "3", "4" };
- string [] expected = { "2", "1", "5", "3", "4" };
- // OfType<string> ()
- AssertAreSame (expected, data.OfType<string> ());
- }
- [Test]
- public void CastArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- // Cast<string> ()
- AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).Cast<string> (); });
- }
- [Test]
- public void CastTest ()
- {
- object [] data = { 1, 2, 3 };
- int [] expected = { 1, 2, 3 };
- // Cast<string> ()
- AssertAreSame (expected, data.Cast<int> ());
- AssertException<InvalidCastException> (delegate () { data.Cast<IEnumerable> ().GetEnumerator ().MoveNext (); });
- data.Cast<IEnumerable> ();
- }
- [Test]
- public void RangeArgumentNullTest ()
- {
- //string [] data = { "2", "1", "5", "3", "4" };
- }
- [Test]
- public void RangeTest ()
- {
- int [] expected = { 2, 3, 4, 5 };
- // Range<> (int)
- AssertAreSame (expected, Enumerable.Range (2, 4));
- AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (2, -3); });
- AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (int.MaxValue - 5, 7); });
- Enumerable.Range (int.MaxValue - 5, 6);
- }
- [Test]
- public void ExceptMultipleItems ()
- {
- var data = new [] { 1, 2, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10 };
- var expected = new [] { 2, 4, 6, 8, 10 };
- AssertAreSame (expected, data.Except (new [] { 1, 3, 5, 7, 9 }));
- }
- }
- }
|