コード例 #1
0
        public void TestMethod0()
        {
            SqlGrep.PatternPicker pp        = new SqlGrep.PatternPicker();
            MethodInfo            cartesian = pp.GetType().GetMethod("Cartesian", BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance);

            IList <IList <string> > arg1;
            IList <string>          arg2;
            bool arg3;

            object[] args;
            IList <IList <string> > ret;

            // Pattern 1.
            // { A, B } * { 1, 2 }
            //   =
            //     { A, B, 1 }
            //     { A, B, 2 }
            arg1 = new List <IList <string> >();
            arg1.Add(new List <string>(new string[] { @"A", @"B" }));
            arg2 = new List <string>(new string[] { @"1", @"2" });
            arg3 = false;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(2, ret.Count);
            Assert.AreEqual(3, ret[0].Count);
            Assert.AreEqual(3, ret[1].Count);
            Assert.AreEqual(@"A", ret[0][0]);
            Assert.AreEqual(@"B", ret[0][1]);
            Assert.AreEqual(@"1", ret[0][2]);
            Assert.AreEqual(@"A", ret[1][0]);
            Assert.AreEqual(@"B", ret[1][1]);
            Assert.AreEqual(@"2", ret[1][2]);

            // Pattern 2.
            // { A, B }
            // { C, D } * { 1, 2 }
            //   =
            //     { A, B, 1 }
            //     { A, B, 2 }
            //     { C, D, 1 }
            //     { C, D, 2 }
            arg1 = new List <IList <string> >();
            arg1.Add(new List <string>(new string[] { @"A", @"B" }));
            arg1.Add(new List <string>(new string[] { @"C", @"D" }));
            arg2 = new List <string>(new string[] { @"1", @"2" });
            arg3 = false;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(4, ret.Count);
            Assert.AreEqual(3, ret[0].Count);
            Assert.AreEqual(3, ret[1].Count);
            Assert.AreEqual(3, ret[2].Count);
            Assert.AreEqual(3, ret[3].Count);
            Assert.AreEqual(@"A", ret[0][0]);
            Assert.AreEqual(@"B", ret[0][1]);
            Assert.AreEqual(@"1", ret[0][2]);
            Assert.AreEqual(@"A", ret[1][0]);
            Assert.AreEqual(@"B", ret[1][1]);
            Assert.AreEqual(@"2", ret[1][2]);
            Assert.AreEqual(@"C", ret[2][0]);
            Assert.AreEqual(@"D", ret[2][1]);
            Assert.AreEqual(@"1", ret[2][2]);
            Assert.AreEqual(@"C", ret[3][0]);
            Assert.AreEqual(@"D", ret[3][1]);
            Assert.AreEqual(@"2", ret[3][2]);

            // Pattern 3.
            // { } * { 1, 2 }
            //   =
            //     { 1 }
            //     { 2 }
            arg1 = new List <IList <string> >();
            arg1.Add(new List <string>());
            arg2 = new List <string>(new string[] { @"1", @"2" });
            arg3 = false;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(2, ret.Count);
            Assert.AreEqual(1, ret[0].Count);
            Assert.AreEqual(1, ret[1].Count);
            Assert.AreEqual(@"1", ret[0][0]);
            Assert.AreEqual(@"2", ret[1][0]);

            // Pattern 4.
            // { A, B } * { }
            //   =
            //     { A, B }
            arg1 = new List <IList <string> >();
            arg1.Add(new List <string>(new string[] { @"A", @"B" }));
            arg2 = new List <string>();
            arg3 = false;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(1, ret.Count);
            Assert.AreEqual(2, ret[0].Count);
            Assert.AreEqual(@"A", ret[0][0]);
            Assert.AreEqual(@"B", ret[0][1]);

            // Pattern 5-1. ( shift )
            // { } * { }
            //   =
            //     { "" }
            arg1 = new List <IList <string> >();
            arg1.Add(new List <string>());
            arg2 = new List <string>();
            arg3 = true;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(1, ret.Count);
            Assert.AreEqual(1, ret[0].Count);
            Assert.AreEqual(@"", ret[0][0]);

            // Pattern 5-2.
            // { "" } * { A, B }
            //   =
            //     { "", A }
            //     { "", B }
            arg1 = ret;
            arg2 = new List <string>(new string[] { @"A", @"B" });
            arg3 = false;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(2, ret.Count);
            Assert.AreEqual(2, ret[0].Count);
            Assert.AreEqual(2, ret[1].Count);
            Assert.AreEqual(@"", ret[0][0]);
            Assert.AreEqual(@"A", ret[0][1]);
            Assert.AreEqual(@"", ret[1][0]);
            Assert.AreEqual(@"B", ret[1][1]);

            // Pattern 5-3.
            // { "", A }
            // { "", B } * { 1, 2 }
            //   =
            //     { "", A, 1 }
            //     { "", A, 2 }
            //     { "", B, 1 }
            //     { "", B, 2 }
            arg1 = ret;
            arg2 = new List <string>(new string[] { @"1", @"2" });
            arg3 = false;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(4, ret.Count);
            Assert.AreEqual(3, ret[0].Count);
            Assert.AreEqual(3, ret[1].Count);
            Assert.AreEqual(3, ret[2].Count);
            Assert.AreEqual(3, ret[3].Count);
            Assert.AreEqual(@"", ret[0][0]);
            Assert.AreEqual(@"A", ret[0][1]);
            Assert.AreEqual(@"1", ret[0][2]);
            Assert.AreEqual(@"", ret[1][0]);
            Assert.AreEqual(@"A", ret[1][1]);
            Assert.AreEqual(@"2", ret[1][2]);
            Assert.AreEqual(@"", ret[2][0]);
            Assert.AreEqual(@"B", ret[2][1]);
            Assert.AreEqual(@"1", ret[2][2]);
            Assert.AreEqual(@"", ret[3][0]);
            Assert.AreEqual(@"B", ret[3][1]);
            Assert.AreEqual(@"2", ret[3][2]);

            // Pattern 5-4.
            // { "", A, 1 }
            // { "", A, 2 }
            // { "", B, 1 }
            // { "", B, 2 } * { "" }
            //   =
            //     { "", A, 1, "" }
            //     { "", A, 2, "" }
            //     { "", B, 1, "" }
            //     { "", B, 2, "" }
            arg1 = ret;
            arg2 = new List <string>(new string[] { @"" });
            arg3 = false;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(4, ret.Count);
            Assert.AreEqual(4, ret[0].Count);
            Assert.AreEqual(4, ret[1].Count);
            Assert.AreEqual(4, ret[2].Count);
            Assert.AreEqual(4, ret[3].Count);
            Assert.AreEqual(@"", ret[0][0]);
            Assert.AreEqual(@"A", ret[0][1]);
            Assert.AreEqual(@"1", ret[0][2]);
            Assert.AreEqual(@"", ret[0][3]);
            Assert.AreEqual(@"", ret[1][0]);
            Assert.AreEqual(@"A", ret[1][1]);
            Assert.AreEqual(@"2", ret[1][2]);
            Assert.AreEqual(@"", ret[1][3]);
            Assert.AreEqual(@"", ret[2][0]);
            Assert.AreEqual(@"B", ret[2][1]);
            Assert.AreEqual(@"1", ret[2][2]);
            Assert.AreEqual(@"", ret[2][3]);
            Assert.AreEqual(@"", ret[3][0]);
            Assert.AreEqual(@"B", ret[3][1]);
            Assert.AreEqual(@"2", ret[3][2]);
            Assert.AreEqual(@"", ret[3][3]);

            // Pattern 6-1. ( shift )
            // { } * { 1, 2 }
            //   =
            //     { "", 1 }
            //     { "", 2 }
            arg1 = new List <IList <string> >();
            arg1.Add(new List <string>());
            arg2 = new List <string>(new string[] { @"1", @"2" });
            arg3 = true;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(2, ret.Count);
            Assert.AreEqual(2, ret[0].Count);
            Assert.AreEqual(2, ret[1].Count);
            Assert.AreEqual(@"", ret[0][0]);
            Assert.AreEqual(@"1", ret[0][1]);
            Assert.AreEqual(@"", ret[1][0]);
            Assert.AreEqual(@"2", ret[1][1]);

            // Pattern 6-2.
            // { } * { 1, 2 }
            //   =
            //     { 1 }
            //     { 2 }
            arg1 = new List <IList <string> >();
            arg1.Add(new List <string>());
            arg2 = new List <string>(new string[] { @"1", @"2" });
            arg3 = false;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(2, ret.Count);
            Assert.AreEqual(1, ret[0].Count);
            Assert.AreEqual(1, ret[1].Count);
            Assert.AreEqual(@"1", ret[0][0]);
            Assert.AreEqual(@"2", ret[1][0]);

            // Pattern 7.
            // { } * { }
            //   =
            //     { }
            arg1 = new List <IList <string> >();
            arg1.Add(new List <string>());
            arg2 = new List <string>();
            arg3 = false;
            args = new object[3] {
                arg1, arg2, arg3
            };

            ret = (IList <IList <string> >)(cartesian.Invoke(pp, args));
            Assert.AreEqual(1, ret.Count);
            Assert.AreEqual(0, ret[0].Count);
        }