public void ForIndexed() { var iterable0 = Enumerable.Range(0, 12); var actual = Nitre.DropWhile(iterable0, (it, index) => index < 9 || it % 3 == 0).ToList(); Assert.Equal(new List<int> { 10, 11 }, actual); }
public void Repl_QuaternaryTuple_VeryLong() { var expected = new List <string> { "IJKL", "IJKM", "IJKN", "IJKO", "IJKP", "IJKQ", "IJKR", "IJLM", "IJLN", "IJLO", "IJLP", "IJLQ", "IJLR", "IJMN", "IJMO", "IJMP", "IJMQ", "IJMR", "IJNO", "IJNP", "IJNQ", "IJNR", "IJOP", "IJOQ", "IJOR", "IJPQ", "IJPR", "IJQR", "IKLM", "IKLN", "IKLO", "IKLP", "IKLQ", "IKLR", "IKMN", "IKMO", "IKMP", "IKMQ", "IKMR", "IKNO", "IKNP", "IKNQ", "IKNR", "IKOP", "IKOQ", "IKOR", "IKPQ", "IKPR", "IKQR", "ILMN", "ILMO", "ILMP", "ILMQ", "ILMR", "ILNO", "ILNP", "ILNQ", "ILNR", "ILOP", "ILOQ", "ILOR", "ILPQ", "ILPR", "ILQR", "IMNO", "IMNP", "IMNQ", "IMNR", "IMOP", "IMOQ", "IMOR", "IMPQ", "IMPR", "IMQR", "INOP", "INOQ", "INOR", "INPQ", "INPR", "INQR", "IOPQ", "IOPR", "IOQR", "IPQR", "JKLM", "JKLN", "JKLO", "JKLP", "JKLQ", "JKLR", "JKMN", "JKMO", "JKMP", "JKMQ", "JKMR", "JKNO", "JKNP", "JKNQ", "JKNR", "JKOP", "JKOQ", "JKOR", "JKPQ", "JKPR", "JKQR", "JLMN", "JLMO", "JLMP", "JLMQ", "JLMR", "JLNO", "JLNP", "JLNQ", "JLNR", "JLOP", "JLOQ", "JLOR", "JLPQ", "JLPR", "JLQR", "JMNO", "JMNP", "JMNQ", "JMNR", "JMOP", "JMOQ", "JMOR", "JMPQ", "JMPR", "JMQR", "JNOP", "JNOQ", "JNOR", "JNPQ", "JNPR", "JNQR", "JOPQ", "JOPR", "JOQR", "JPQR", "KLMN", "KLMO", "KLMP", "KLMQ", "KLMR", "KLNO", "KLNP", "KLNQ", "KLNR", "KLOP", "KLOQ", "KLOR", "KLPQ", "KLPR", "KLQR", "KMNO", "KMNP", "KMNQ", "KMNR", "KMOP", "KMOQ", "KMOR", "KMPQ", "KMPR", "KMQR", "KNOP", "KNOQ", "KNOR", "KNPQ", "KNPR", "KNQR", "KOPQ", "KOPR", "KOQR", "KPQR", "LMNO", "LMNP", "LMNQ", "LMNR", "LMOP", "LMOQ", "LMOR", "LMPQ", "LMPR", "LMQR", "LNOP", "LNOQ", "LNOR", "LNPQ", "LNPR", "LNQR", "LOPQ", "LOPR", "LOQR", "LPQR", "MNOP", "MNOQ", "MNOR", "MNPQ", "MNPR", "MNQR", "MOPQ", "MOPR", "MOQR", "MPQR", "NOPQ", "NOPR", "NOQR", "NPQR", "OPQR" }; char[] iterable = "IJKLMNOPQR".ToCharArray(); var actual = Nitre.CombinationsQuaternary(iterable).Select(item => new string(new char[] { item.Item1, item.Item2, item.Item3, item.Item4 })).ToList(); Assert.Equal(expected, actual); }
public void WithSevenIterables() { var iterables = new Dictionary <int, IEnumerable <char> >(); for (var i = 0; i < 50; i++) { iterables[i] = Utils.RangeOfChars(3, 65 + i); } var expected2 = new Tuple <char, char, char, char, char, char, char> ( 'A', 'B', 'C', 'D', 'E', 'F', 'I' ); var expected2184 = new Tuple <char, char, char, char, char, char, char> ( 'C', 'D', 'E', 'F', 'G', 'H', 'G' ); var actual = Nitre.Product ( iterables[0], iterables[1], iterables[2], iterables[3], iterables[4], iterables[5], iterables[6] ).ToList(); Assert.StrictEqual(actual.Count, Math.Pow(3, 7)); Assert.Equal(expected2, actual[2]); Assert.Equal(expected2184, actual[2184]); }
public void Repl_QuinaryTuple() { string[] expected = new string[] { "ABCDE", "ABCDF", "ABCDG", "ABCDH", "ABCDI", "ABCDJ", "ABCEF", "ABCEG", "ABCEH", "ABCEI", "ABCEJ", "ABCFG", "ABCFH", "ABCFI", "ABCFJ", "ABCGH", "ABCGI", "ABCGJ", "ABCHI", "ABCHJ", "ABCIJ", "ABDEF", "ABDEG", "ABDEH", "ABDEI", "ABDEJ", "ABDFG", "ABDFH", "ABDFI", "ABDFJ", "ABDGH", "ABDGI", "ABDGJ", "ABDHI", "ABDHJ", "ABDIJ", "ABEFG", "ABEFH", "ABEFI", "ABEFJ", "ABEGH", "ABEGI", "ABEGJ", "ABEHI", "ABEHJ", "ABEIJ", "ABFGH", "ABFGI", "ABFGJ", "ABFHI", "ABFHJ", "ABFIJ", "ABGHI", "ABGHJ", "ABGIJ", "ABHIJ", "ACDEF", "ACDEG", "ACDEH", "ACDEI", "ACDEJ", "ACDFG", "ACDFH", "ACDFI", "ACDFJ", "ACDGH", "ACDGI", "ACDGJ", "ACDHI", "ACDHJ", "ACDIJ", "ACEFG", "ACEFH", "ACEFI", "ACEFJ", "ACEGH", "ACEGI", "ACEGJ", "ACEHI", "ACEHJ", "ACEIJ", "ACFGH", "ACFGI", "ACFGJ", "ACFHI", "ACFHJ", "ACFIJ", "ACGHI", "ACGHJ", "ACGIJ", "ACHIJ", "ADEFG", "ADEFH", "ADEFI", "ADEFJ", "ADEGH", "ADEGI", "ADEGJ", "ADEHI", "ADEHJ", "ADEIJ", "ADFGH", "ADFGI", "ADFGJ", "ADFHI", "ADFHJ", "ADFIJ", "ADGHI", "ADGHJ", "ADGIJ", "ADHIJ", "AEFGH", "AEFGI", "AEFGJ", "AEFHI", "AEFHJ", "AEFIJ", "AEGHI", "AEGHJ", "AEGIJ", "AEHIJ", "AFGHI", "AFGHJ", "AFGIJ", "AFHIJ", "AGHIJ", "BCDEF", "BCDEG", "BCDEH", "BCDEI", "BCDEJ", "BCDFG", "BCDFH", "BCDFI", "BCDFJ", "BCDGH", "BCDGI", "BCDGJ", "BCDHI", "BCDHJ", "BCDIJ", "BCEFG", "BCEFH", "BCEFI", "BCEFJ", "BCEGH", "BCEGI", "BCEGJ", "BCEHI", "BCEHJ", "BCEIJ", "BCFGH", "BCFGI", "BCFGJ", "BCFHI", "BCFHJ", "BCFIJ", "BCGHI", "BCGHJ", "BCGIJ", "BCHIJ", "BDEFG", "BDEFH", "BDEFI", "BDEFJ", "BDEGH", "BDEGI", "BDEGJ", "BDEHI", "BDEHJ", "BDEIJ", "BDFGH", "BDFGI", "BDFGJ", "BDFHI", "BDFHJ", "BDFIJ", "BDGHI", "BDGHJ", "BDGIJ", "BDHIJ", "BEFGH", "BEFGI", "BEFGJ", "BEFHI", "BEFHJ", "BEFIJ", "BEGHI", "BEGHJ", "BEGIJ", "BEHIJ", "BFGHI", "BFGHJ", "BFGIJ", "BFHIJ", "BGHIJ", "CDEFG", "CDEFH", "CDEFI", "CDEFJ", "CDEGH", "CDEGI", "CDEGJ", "CDEHI", "CDEHJ", "CDEIJ", "CDFGH", "CDFGI", "CDFGJ", "CDFHI", "CDFHJ", "CDFIJ", "CDGHI", "CDGHJ", "CDGIJ", "CDHIJ", "CEFGH", "CEFGI", "CEFGJ", "CEFHI", "CEFHJ", "CEFIJ", "CEGHI", "CEGHJ", "CEGIJ", "CEHIJ", "CFGHI", "CFGHJ", "CFGIJ", "CFHIJ", "CGHIJ", "DEFGH", "DEFGI", "DEFGJ", "DEFHI", "DEFHJ", "DEFIJ", "DEGHI", "DEGHJ", "DEGIJ", "DEHIJ", "DFGHI", "DFGHJ", "DFGIJ", "DFHIJ", "DGHIJ", "EFGHI", "EFGHJ", "EFGIJ", "EFHIJ", "EGHIJ", "FGHIJ" }; char[] iterable = "ABCDEFGHIJ".ToCharArray(); var actual = Nitre.CombinationsQuinary(iterable).Select(item => new string(new char[] { item.Item1, item.Item2, item.Item3, item.Item4, item.Item5 })).ToList(); Assert.Equal(expected, actual); }
public void Default() { var values = "ABCD".ToCharArray(); var actual = new string(Nitre.Cycle(values).Take(10).ToArray()); Assert.Equal("ABCDABCDAB", actual); }
public void WithTwoTuples() { var iterable0 = new[] { Tuple.Create(1, "first"), Tuple.Create(3, "second") }; var actual = Nitre.Starmap((a, b) => $"{a}{b}", iterable0); Assert.Equal("1first-3second", string.Join("-", actual)); }
public void ForDecimalWithStep() { var actual = Nitre.Count(1.1m, -0.4m).Take(3).ToList(); Assert.Equal(new List <decimal> { 1.1m, 0.7m, 0.3m }, actual); }
public void ForNegativeDoubleWithoutStep() { var actual = Nitre.Count(-2d).Take(3).ToList(); Assert.Equal(new List <double> { -2d, -1d, 0d }, actual); }
public void ForFloatWithNegativeStep() { var actual = Nitre.Count(6f, -7f).Take(3).ToList(); Assert.Equal(new List <float> { 6f, -1f, -8 }, actual); }
public void ForIntegerWithStep() { var actual = Nitre.Count(0, 3).Take(10).ToList(); Assert.StrictEqual(10, actual.Count); Assert.Equal(0, actual[0]); Assert.Equal(9, actual[3]); }
public void ForIndexed() { var iterable0 = Enumerable.Range(0, 12); var actual = Nitre.TakeWhile(iterable0, (it, i) => i < 4 && (it < 3 || it % 3 == 0)).ToList(); Assert.Equal(4, actual.Count); Assert.Equal(1, actual[1]); }
public void OutOfBounds() { var iterable0 = Enumerable.Range(0, 3); var actual = Nitre.Islice(iterable0, 0, 5); Assert.Equal(new List <int> { 0, 1, 2 }, actual); }
public void DefaultStep() { var iterable0 = Enumerable.Range(0, 20); var actual = Nitre.Islice(iterable0, 15, 20); Assert.Equal(new List <int> { 15, 16, 17, 18, 19 }, actual); }
public void ForIndexed() { var iterable0 = Enumerable.Range(0, 12); var actual = Nitre.FilterFalse(iterable0, (it, i) => i % 2 == 0 && it % 3 == 0).ToList(); Assert.Equal(10, actual.Count); Assert.DoesNotContain(6, actual); Assert.DoesNotContain(12, actual); }
public void ForNonIndexed() { var iterable0 = Enumerable.Range(0, 12); var actual = Nitre.FilterFalse(iterable0, it => it < 4).ToList(); Assert.Equal(8, actual.Count); Assert.DoesNotContain(2, actual); Assert.Contains(4, actual); }
public void ForNegativeValues() { var iterable0 = Enumerable.Range(0, 2); var actual = Nitre.Islice(iterable0, 0, -1, 0); Assert.Throws <ArgumentException>(() => Nitre.Islice(iterable0, 0, -1, 0).ToList()); Assert.Throws <ArgumentException>(() => Nitre.Islice(iterable0, 1, 3, -2).ToList()); Assert.Throws <ArgumentException>(() => Nitre.Islice(iterable0, -23, 0, 0).ToList()); }
public void Repl_TernaryTuple_Empty() { var expected = Enumerable.Empty <Tuple <char, char, char> >(); char[] iterable = "AB".ToCharArray(); List <Tuple <char, char, char> > actual = Nitre.CombinationsTernary(iterable).ToList(); Assert.Equal(expected, actual); }
public void Default() { var values = Enumerable.Range(0, 3); var booleans = new[] { true, false, true }; var actual = Nitre.Compress(values, booleans); Assert.Equal(new List <int> { 0, 2 }, actual); }
public void VerifiedExample_WithReplacements() { var iterables = "ABCD".ToCharArray(); var actual = Nitre.CombinationsWithReplacementsBinary(iterables).Select(item => new string(new char[] { item.Item1, item.Item2 })).ToList(); var expected = new List <string> { "AA", "AB", "AC", "AD", "BB", "BC", "BD", "CC", "CD", "DD" }; Assert.Equal(expected, actual); }
public void WithSevenTuples() { var iterable0 = new[] { Tuple.Create("A", 101, 1.2m, 0, 0, 1, 3), Tuple.Create("B", 3, .3m, 1, 1, 1, 1) }; var actual = Nitre.Starmap(Reduce7Arguments, iterable0).ToList(); Assert.Equal("A", actual[0].name); Assert.Equal(4, actual[0].sum); Assert.Equal(101 * 1.2m, actual[0].area); Assert.Equal("B", actual[1].name); Assert.Equal(3 * .3m, actual[1].area); }
public void Repl_QuaternaryTuple() { List <Tuple <char, char, char, char> > expected = new List <Tuple <char, char, char, char> > { Tuple.Create('A', 'B', 'C', 'D') }; char[] iterable = "ABCD".ToCharArray(); var actual = Nitre.CombinationsQuaternary(iterable).ToList(); Assert.Equal(expected, actual); }
public void Repl_TernaryTuple_Long() { var expected = new string[] { "ABC", "ABD", "ABE", "ABF", "ACD", "ACE", "ACF", "ADE", "ADF", "AEF", "BCD", "BCE", "BCF", "BDE", "BDF", "BEF", "CDE", "CDF", "CEF", "DEF" }; char[] iterable = "ABCDEF".ToCharArray(); var actual = Nitre.CombinationsTernary(iterable).Select(item => new string(new char[] { item.Item1, item.Item2, item.Item3 })).ToList(); Assert.Equal(expected, actual); }
public void WithRepeat() { var expected1 = new Tuple <int, char>(1, 'C'); var expected29 = new Tuple <int, char>(5, 'C'); var iterable0 = Enumerable.Range(1, 5); var iterable1 = Utils.RangeOfChars(3); var actual = Nitre.Product(iterable0, iterable1, 2).ToList(); Assert.StrictEqual(30, actual.Count); Assert.Equal(expected1, actual[2]); Assert.Equal(expected29, actual[29]); Assert.Equal(actual[13], actual[28]); }
public void Repl_TernaryTuple_WithReplacements() { var iterables = "ABCD".ToCharArray(); var actual = Nitre.CombinationsWithReplacementsTernary(iterables).Select(item => new string(new char[] { item.Item1, item.Item2, item.Item3 })).ToList(); var expected = new string[] { "AAA", "AAB", "AAC", "AAD", "AAE", "AAF", "ABB", "ABC", "ABD", "ABE", "ABF", "ACC", "ACD", "ACE", "ACF", "ADD", "ADE", "ADF", "AEE", "AEF", "AFF", "BBB", "BBC", "BBD", "BBE", "BBF", "BCC", "BCD", "BCE", "BCF", "BDD", "BDE", "BDF", "BEE", "BEF", "BFF", "CCC", "CCD", "CCE", "CCF", "CDD", "CDE", "CDF", "CEE", "CEF", "CFF", "DDD", "DDE", "DDF", "DEE", "DEF", "DFF", "EEE", "EEF", "EFF", "FFF" }; Assert.Equal(expected, actual); }
public void WithTwoLists() { var expected0 = new Tuple <int, char>(1, 'A'); var expected2 = new Tuple <int, char>(1, 'C'); var expected11 = new Tuple <int, char>(3, 'D'); var iterable0 = Enumerable.Range(1, 3); var iterable1 = Utils.RangeOfChars(4); var actual = Nitre.Product(iterable0, iterable1).ToList(); Assert.StrictEqual(12, actual.Count); Assert.Equal(expected0, actual[0]); Assert.Equal(expected2, actual[2]); Assert.Equal(expected11, actual[11]); }
public void Repl_TernaryTuple_VeryLong() { var expected = new string[] { "IJK", "IJL", "IJM", "IJN", "IJO", "IJP", "IKL", "IKM", "IKN", "IKO", "IKP", "ILM", "ILN", "ILO", "ILP", "IMN", "IMO", "IMP", "INO", "INP", "IOP", "JKL", "JKM", "JKN", "JKO", "JKP", "JLM", "JLN", "JLO", "JLP", "JMN", "JMO", "JMP", "JNO", "JNP", "JOP", "KLM", "KLN", "KLO", "KLP", "KMN", "KMO", "KMP", "KNO", "KNP", "KOP", "LMN", "LMO", "LMP", "LNO", "LNP", "LOP", "MNO", "MNP", "MOP", "NOP" }; char[] iterable = "IJKLMNOP".ToCharArray(); var actual = Nitre.CombinationsTernary(iterable).Select(item => new string(new char[] { item.Item1, item.Item2, item.Item3 })).ToList(); Assert.Equal(expected, actual); }
public void Repl_BinaryTuple() { List <Tuple <char, char> > expected = new List <Tuple <char, char> > { Tuple.Create('A', 'B'), Tuple.Create('A', 'C'), Tuple.Create('A', 'D'), Tuple.Create('B', 'C'), Tuple.Create('B', 'D'), Tuple.Create('C', 'D') }; char[] iterable = "ABCD".ToCharArray(); List <Tuple <char, char> > actual = Nitre.CombinationsBinary(iterable).ToList(); // var actual_ = partialResult.Select(r => new string(new char[] { r.Item1, r.Item2 })); // Assert.False(true); Assert.Equal(expected, actual); }
public void ProductFilter() { var iterables = Create(); var actual = Nitre.Product(iterables.Item1, iterables.Item2, iterables.Item3) .Filter(item => item.Item1.MunicipalityId == item.Item2.MunicipalityId) .Filter(item => item.Item2.IsoCode == item.Item3.IsoCode || "GB" == item.Item3.IsoCode) .ToArray(); var countries = actual.Select(t => t.Item3.IsoCode).ToArray(); var municipalities = actual.Select(t => t.Item2.IsoCode).ToArray(); var libraries = actual.Select(t => t.Item1.MunicipalityId).ToArray(); Assert.Contains("GB", countries); Assert.Contains("CN", countries); Assert.DoesNotContain("IN", countries); Assert.Contains("CN", municipalities); Assert.Contains("XL", municipalities); Assert.DoesNotContain("IL", municipalities); Assert.Contains(3, libraries); }
public void Filter() { var iterable0 = Utils.RangeOfChars(3); var iterable1 = Utils.RangeOfChars(5); var iterable2 = Enumerable.Range(0, 10); var actual = Nitre.Product(iterable0, iterable1, iterable2) .Filter(item => item.Item1 == 'A' && item.Item2 == 'E') .Filter(item => item.Item3 == 5 || item.Item3 == 7) .ToList(); var actual0 = actual.Select(t => t.Item1).ToList(); var actual1 = actual.Select(t => t.Item2).ToList(); int numberMax = actual.Select(t => t.Item3).Max(); Assert.Equal(2, actual.Count); Assert.Contains('A', actual0); Assert.Contains('E', actual1); Assert.DoesNotContain('B', actual1); Assert.Equal(7, numberMax); }
public void FilterForIndexAndImmutableCollection_AssertOrder() { var iterable0 = Utils.RangeOfChars(3).ToArray(); var iterable1 = Utils.RangeOfChars(5, 70).ToList(); var iterable2 = Enumerable.Range(0, 4).ToImmutableArray(); var tuple0 = Nitre.Product(iterable0, iterable1, iterable2).ToArray(); var tuple1 = Nitre.Product(iterable2, iterable0, iterable1).ToArray(); var actual0 = tuple0 .Filter((item, index) => index == 50) .Single(); var actual1 = tuple1 .Filter((item, index) => index == 50) .Single(); Assert.Equal('C', actual0.Item1); Assert.Equal(2, actual0.Item3); Assert.Equal(3, actual1.Item1); Assert.True(actual0.Item1 > actual1.Item1); }