Ejemplo n.º 1
0
            // The following verification function will be used when the PLINQ team runs these tests
            // This is a non-order preserving verification function
#if PLINQ
            public static int DataEqual(IEnumerable <JoinRec> ele1, IEnumerable <JoinRec> ele2)
            {
                if ((ele1 == null) && (ele2 == null))
                {
                    return(0);
                }
                if (ele1.Count() != ele2.Count())
                {
                    return(1);
                }

                List <JoinRec> elt = new List <JoinRec>(ele1);

                foreach (JoinRec e2 in ele2)
                {
                    bool contains = false;
                    for (int i = 0; i < elt.Count; i++)
                    {
                        JoinRec e1 = elt[i];
                        if (e1.name == e2.name && e1.orderID.Count() == e2.orderID.Count() && e1.total.Count() == e2.total.Count())
                        {
                            bool eq = true;
                            for (int j = 0; j < e1.orderID.Count(); j++)
                            {
                                if (e1.orderID[j] != e2.orderID[j])
                                {
                                    eq = false;
                                    break;
                                }
                            }

                            for (int j = 0; j < e1.total.Count(); j++)
                            {
                                if (e1.total[j] != e2.total[j])
                                {
                                    eq = false;
                                    break;
                                }
                            }

                            if (!eq)
                            {
                                continue;
                            }
                            elt.RemoveAt(i);
                            contains = true;
                            break;
                        }
                    }
                    if (!contains)
                    {
                        return(1);
                    }
                }
                return(0);
            }
Ejemplo n.º 2
0
            public static JoinRec createJoinRec(CustomerRec cr, AnagramRec or)
            {
                JoinRec jr = new JoinRec();

                jr.name    = cr.name;
                jr.orderID = or.orderID;
                jr.total   = or.total;

                return(jr);
            }
Ejemplo n.º 3
0
            // The following is an order preserving verification function
            public static int DataEqual(IEnumerable <JoinRec> ele1, IEnumerable <JoinRec> ele2)
            {
                if ((ele1 == null) && (ele2 == null))
                {
                    return(0);
                }
                if (ele1.Count() != ele2.Count())
                {
                    return(1);
                }

                using (IEnumerator <JoinRec> e1 = ele1.GetEnumerator())
                    using (IEnumerator <JoinRec> e2 = ele2.GetEnumerator())
                    {
                        while (e1.MoveNext())
                        {
                            e2.MoveNext();
                            JoinRec rec1 = (JoinRec)e1.Current;
                            JoinRec rec2 = (JoinRec)e2.Current;

                            if (rec1.name != rec2.name)
                            {
                                return(1);
                            }
                            if (rec1.orderID.Count() != rec2.orderID.Count())
                            {
                                return(1);
                            }
                            if (rec1.total.Count() != rec2.total.Count())
                            {
                                return(1);
                            }

                            int num = rec1.orderID.Count();

                            for (int i = 0; i < num; i++)
                            {
                                if (rec1.orderID[i] != rec2.orderID[i])
                                {
                                    return(1);
                                }
                            }

                            num = rec1.total.Count();
                            for (int i = 0; i < num; i++)
                            {
                                if (rec1.total[i] != rec2.total[i])
                                {
                                    return(1);
                                }
                            }
                        }
                    }
                return(0);
            }
        public void SingleElementEachAndDoesntMatch()
        {
            CustomerRec[] outer = new [] { new CustomerRec {
                                               name = "Tim", custID = 43434
                                           } };
            OrderRec[] inner = new [] { new OrderRec {
                                            orderID = 97865, custID = 49434, total = 25
                                        } };
            JoinRec[] expected = new JoinRec[] { new JoinRec {
                                                     name = "Tim", orderID = new int?[] { }, total = new int?[] { }
                                                 } };

            Assert.Equal(expected, outer.GroupJoin(inner, e => e.custID, e => e.custID, createJoinRec));
        }
Ejemplo n.º 5
0
            // outer and inner has only one element and the key do not match
            public static int Test4()
            {
                CustomerRec[] outer = new CustomerRec[] { new CustomerRec {
                                                              name = "Prakash", custID = 98922
                                                          } };
                OrderRec[] inner = new OrderRec[] { new OrderRec {
                                                        orderID = 45321, custID = 98022, total = 50
                                                    } };
                JoinRec[] expected = new JoinRec[] { };
                Func <CustomerRec, OrderRec, JoinRec> resultSelector = Helper.createJoinRec;

                var actual = outer.Join(inner, (e) => e.custID, (o) => o.custID, resultSelector);

                return(Verification.Allequal(expected, actual));
            }
Ejemplo n.º 6
0
            // outer is empty and inner is non-empty
            public static int Test1()
            {
                CustomerRec[] outer = new CustomerRec[] { };
                OrderRec[]    inner = new OrderRec[] { new OrderRec {
                                                           orderID = 45321, custID = 98022, total = 50
                                                       },
                                                       new OrderRec {
                                                           orderID = 97865, custID = 32103, total = 25
                                                       } };
                JoinRec[] expected = new JoinRec[] { };
                Func <CustomerRec, IEnumerable <OrderRec>, JoinRec> resultSelector = Helper.createJoinRec;

                var actual = outer.GroupJoin(inner, (e) => e.custID, (o) => o.custID, resultSelector);

                return(Helper.DataEqual(expected, actual));
            }
Ejemplo n.º 7
0
            // outer is non-empty and inner is non-empty
            public static int Test2()
            {
                CustomerRec[] outer = new CustomerRec[] { new CustomerRec {
                                                              name = "Tim", custID = 43434
                                                          },
                                                          new CustomerRec {
                                                              name = "Bob", custID = 34093
                                                          } };
                OrderRec[] inner    = new OrderRec[] { };
                JoinRec[]  expected = new JoinRec[] { };
                Func <CustomerRec, OrderRec, JoinRec> resultSelector = Helper.createJoinRec;

                var actual = outer.Join(inner, (e) => e.custID, (o) => o.custID, resultSelector);

                return(Verification.Allequal(expected, actual));
            }
Ejemplo n.º 8
0
            // outer and inner has only one element and the keys do not match
            public static int Test4()
            {
                CustomerRec[] outer = new CustomerRec[] { new CustomerRec {
                                                              name = "Tim", custID = 43434
                                                          } };
                OrderRec[] inner = new OrderRec[] { new OrderRec {
                                                        orderID = 97865, custID = 49434, total = 25
                                                    } };
                JoinRec[] expected = new JoinRec[] { new JoinRec {
                                                         name = "Tim", orderID = new int?[] {}, total = new int?[] {}
                                                     } };
                Func <CustomerRec, IEnumerable <OrderRec>, JoinRec> resultSelector = Helper.createJoinRec;

                var actual = outer.GroupJoin(inner, (e) => e.custID, (o) => o.custID, resultSelector);

                return(Helper.DataEqual(expected, actual));
            }
Ejemplo n.º 9
0
            public static JoinRec createJoinRec(CustomerRec cr, IEnumerable <AnagramRec> arIE)
            {
                int count = 0;

                JoinRec jr = new JoinRec();

                jr.name    = cr.name;
                jr.orderID = new int?[arIE.Count()];
                jr.total   = new int?[arIE.Count()];

                foreach (AnagramRec ar in arIE)
                {
                    jr.orderID[count] = ar.orderID;
                    jr.total[count]   = ar.total;
                    count++;
                }

                return(jr);
            }
Ejemplo n.º 10
0
            public static JoinRec createJoinRec(CustomerRec cr, IEnumerable <OrderRec> orIE)
            {
                int count = 0;

                JoinRec jr = new JoinRec();

                jr.name = cr.name;

                jr.orderID = new int?[orIE.Count()];
                jr.total   = new int?[orIE.Count()];

                foreach (OrderRec or in orIE)
                {
                    jr.orderID[count] = or.orderID;
                    jr.total[count]   = or.total;
                    count++;
                }

                return(jr);
            }