コード例 #1
0
        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]);
        }
コード例 #2
0
        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]);
        }
コード例 #3
0
        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]);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public void WithInvalidRepeatThrows()
        {
            Action action = () => Nitre.Product(new int[] {}, new int[] {}, -1).ToList();

            Assert.Throws <ArgumentException>(action);
        }