Exemple #1
0
        public void testFourSequences()
        {
            List <int> sequence0 = new List <int> {
                7, 12, 16
            };
            List <int> sequence1 = new List <int> {
                3, 4, 5
            };
            List <int> sequence2 = new List <int> {
                3, 3, 4, 5
            };
            List <int> sequence3 = new List <int> {
                3, 3, 4, 5
            };

            Func <object, int> identity = ig => (int)ig;
            Func <object, int> times3   = x => (int)x * 3;
            Func <object, int> times4   = x => (int)x * 4;
            Func <object, int> times5   = x => (int)x * 5;

            //@SuppressWarnings({ "unchecked", "rawtypes" })
            GroupBy2 <int> m = GroupBy2 <int> .Of(
                new Tuple <List <object>, Func <object, int> >(sequence0.Cast <object>().ToList(), identity),
                new Tuple <List <object>, Func <object, int> >(sequence1.Cast <object>().ToList(), times3),
                new Tuple <List <object>, Func <object, int> >(sequence2.Cast <object>().ToList(), times4),
                new Tuple <List <object>, Func <object, int> >(sequence3.Cast <object>().ToList(), times5));

            List <Tuple> expectedValues = new List <Tuple>
            {
                new Tuple(7, list(7), none, none, none),
                new Tuple(9, none, list(3), none, none),
                new Tuple(12, list(12), list(4), list(3, 3), none),
                new Tuple(15, none, list(5), none, list(3, 3)),
                new Tuple(16, list(16), none, list(4), none),
                new Tuple(20, none, none, list(5), list(4)),
                new Tuple(25, none, none, none, list(5))
            };

            int i = 0;

            foreach (Tuple t in m)
            {
                int j = 0;
                foreach (Object o in t.All())
                {
                    if (o is IList)
                    {
                        Assert.IsTrue(Arrays.AreEqualList((IList)o, (IList)expectedValues[i].Get(j)), "grouped list has a problem");
                    }
                    else
                    {
                        Assert.AreEqual(o, expectedValues[i].Get(j));
                    }
                    j++;
                }
                i++;
            }
        }
Exemple #2
0
        public void TestOneSequence()
        {
            List <int> sequence0 = new List <int> {
                7, 12, 12, 16
            };

            Func <int, int> identity = ig => (int)ig;

            //@SuppressWarnings({ "unchecked", "rawtypes" })
            GroupBy2 <int> m = GroupBy2 <int> .Of(
                new Tuple <List <object>, Func <object, int> >(sequence0.Cast <object>().ToList(), x => identity((int)x)));

            List <Tuple> expectedValues = new List <Tuple>
            {
                new Tuple(7, list(7)),
                new Tuple(12, list(12, 12)),
                new Tuple(16, list(16))
            };

            int i = 0;

            foreach (Tuple t in m)
            {
                int j = 0;
                foreach (object o in t.All())
                {
                    if (o is IList)
                    {
                        Assert.IsTrue(Arrays.AreEqualList((IList)o, (IList)expectedValues[i].Get(j)), "grouped list has a problem");
                    }
                    else
                    {
                        Assert.AreEqual(o, expectedValues[i].Get(j));
                    }
                    j++;
                }
                i++;
            }
        }