コード例 #1
0
        public void FillRecordsTest()
        {
            var seqtriplets = new PTypeSequence(
                                        new PTypeRecord(
                                            new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                                            new NamedType("predicate", new PType(PTypeEnumeration.sstring)),
                                            new NamedType("obj", new PType(PTypeEnumeration.sstring)))
                                );

            var testdb = new object[] {
                new object[] {"a", "b", "c"},
                new object[] {"a1", "b1", "c1"},
                new object[] {"da", "db", "dc"}
            };

            PhCell hCell = new PhCell(seqtriplets, string.Empty, "test");
            try
            {
                hCell.Fill(testdb);
                Assert.AreEqual(3, hCell.Root.Count());
                var e = (object[])hCell.Root.Element(2).Get().Value;
                Assert.AreEqual(e.Length, 3);
                Assert.AreEqual(e[0], "da");
                Assert.AreEqual(e[1], "db");
                Assert.AreEqual(e[2], "dc");

                Assert.AreEqual(hCell.Root.Element(2).Field(2).Get().Value, "dc");
            }
            finally
            {
                hCell.Close();
            }
        }
コード例 #2
0
        public void InsertAtomTest()
        {
            var seqtriplets = new PTypeSequence(new PType(PTypeEnumeration.integer));

            var testdb = new object[] { 1, 2, 3, 5, 15, 19, 21 };

            PhCell hCell = new PhCell(seqtriplets, string.Empty, "test");

            hCell.Fill(testdb);
            try
            {
                Assert.AreEqual(7, hCell.Root.Count());
                Assert.AreEqual(3, (int)hCell.Root.Element(2).Get().Value);
                Assert.AreEqual(5, (int)hCell.Root.Element(3).Get().Value);
                Assert.AreEqual(21, (int)hCell.Root.Element(6).Get().Value);

                hCell.InsertElement(0, 12);
                Assert.AreEqual(8, hCell.Root.Count());
                Assert.AreEqual(12, (int)hCell.Root.Element(0).Get().Value);
                Assert.AreEqual(3, (int)hCell.Root.Element(3).Get().Value);
                Assert.AreEqual(21, (int)hCell.Root.Element(7).Get().Value);

            }
            finally
            {
                hCell.Close();
            }
        }
コード例 #3
0
        public void UpdateAtomsTest()
        {
            var seqtriplets = new PTypeSequence(new PType(PTypeEnumeration.integer));

            var testdb = new object[] { 1, 4, 6, 8, 13, 88};

            PhCell hCell = new PhCell(seqtriplets, string.Empty, "test");
            try
            {
                hCell.Fill(testdb);
                Assert.AreEqual(6, hCell.Root.Count());
                var e = (int)hCell.Root.Element(2).Get().Value;
                Assert.AreEqual(e, 6);
                Assert.AreEqual((int)hCell.Root.Element(0).Get().Value, 1);
                Assert.AreEqual((int)hCell.Root.Element(2).Get().Value, 6);
                Assert.AreEqual((int)hCell.Root.Element(5).Get().Value, 88);

                var entry = (PhEntry)hCell.Root.Element(2);
                entry.Set(987);
                Assert.AreEqual((int)hCell.Root.Element(2).Get().Value, 987);
            }
            finally
            {
                hCell.Close();
            }
        }
コード例 #4
0
ファイル: PhSortTest.cs プロジェクト: jurik/PolarDBTest
        public void SimpleSortRecordTest()
        {
            PType tp_seq = new PTypeSequence(new PTypeRecord(
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("id", new PType(PTypeEnumeration.sstring))));

            object[] testdb = new object[] {
                new object[] { "Petr", "0120"},
                new object[] { "Dan", "12"},
                new object[] { "Ivan", "54"},
                new object[] { "Jim", "13"},
                new object[] { "Wai", "1"},
                new object[] { "Ken", "15"},
                new object[] { "Aby", "916"},
            };

            PhCell hCell = new PhCell(tp_seq, string.Empty, "test");
            try
            {
                hCell.Fill(testdb);

                Assert.AreEqual(7, hCell.Root.Count());
                Assert.AreEqual("Ivan", hCell.Root.Element(2).Field(0).Get().Value.ToString());
                Assert.AreEqual("Jim", hCell.Root.Element(3).Field(0).Get().Value.ToString());
                Assert.AreEqual("Ken", hCell.Root.Element(5).Field(0).Get().Value.ToString());
                Assert.AreEqual("Aby", hCell.Root.Element(6).Field(0).Get().Value.ToString());

                hCell.Sort(e =>
                {
                    return (string)e.Field(0).Get().Value;
                });

                Assert.AreEqual(7, hCell.Root.Count());
                Assert.AreEqual("Ivan", hCell.Root.Element(2).Field(0).Get().Value.ToString());
                Assert.AreEqual("Jim", hCell.Root.Element(3).Field(0).Get().Value.ToString());
                Assert.AreEqual("Petr", hCell.Root.Element(5).Field(0).Get().Value.ToString());
                Assert.AreEqual("Wai", hCell.Root.Element(6).Field(0).Get().Value.ToString());
            }
            finally
            {
                hCell.Close();
            }
        }
コード例 #5
0
        public void FillAtomsTest()
        {
            var seqtriplets = new PTypeSequence(new PType(PTypeEnumeration.sstring));

            var testdb = new object[] { "test1", "obj24", "ggg", "ntest45", "nq1"
            };

            PhCell hCell = new PhCell(seqtriplets, string.Empty, "test");
            try
            {
                hCell.Fill(testdb);
                Assert.AreEqual(5, hCell.Root.Count());
                var e = (string)hCell.Root.Element(2).Get().Value;
                Assert.AreEqual(e.Length, 3);
                Assert.AreEqual(e, "ggg");
                Assert.AreEqual((string)hCell.Root.Element(0).Get().Value, "test1");
                Assert.AreEqual((string)hCell.Root.Element(4).Get().Value, "nq1");
            }
            finally
            {
                hCell.Close();
            }
        }
コード例 #6
0
        public void InsertElementInnerTest()
        {
            var seqtriplets = new PTypeSequence(
                new PTypeUnion(
                    new NamedType("test1",
                        new PTypeRecord(
                            new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                            new NamedType("obj", new PType(PTypeEnumeration.sstring)))),
                    new NamedType("test2",
                        new PTypeRecord(
                            new NamedType("name", new PType(PTypeEnumeration.sstring)),
                            new NamedType("value", new PType(PTypeEnumeration.integer))))
                 ));

            var testdb = new object[] {
                new object[] { 0, new object[] {"a11", "b11"}},
                new object[] { 0, new object[] {"a12", "b12"}},
                new object[] { 1, new object[] {"a21", 22}},
                new object[] { 0, new object[] {"a13", "b13"}},
                new object[] { 0, new object[] {"a14", "b14"}},
                new object[] { 0, new object[] {"a15", "b15"}},
                new object[] { 0, new object[] {"a16", "b16"}},
            };

            PhCell hCell = new PhCell(seqtriplets, string.Empty, "test");
            hCell.Fill(testdb);
            try
            {
                Assert.AreEqual(hCell.Root.Count(), 7);
                var e = (object[])hCell.Root.Element(2).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 1);
                var o = (object[])e[1];
                Assert.AreEqual(o[0], "a21");
                Assert.AreEqual(o[1], 22);

                e = (object[])hCell.Root.Element(3).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a13");
                Assert.AreEqual(o[1], "b13");

                e = (object[])hCell.Root.Element(4).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a14");
                Assert.AreEqual(o[1], "b14");

                hCell.InsertElement(4, new object[] { 0, new object[] { "a44", "b44" } });

                Assert.AreEqual(hCell.Root.Count(), 8);

                e = (object[])hCell.Root.Element(4).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a44");
                Assert.AreEqual(o[1], "b44");

                e = (object[])hCell.Root.Element(5).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a14");
                Assert.AreEqual(o[1], "b14");

                e = (object[])hCell.Root.Element(7).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a16");
                Assert.AreEqual(o[1], "b16");

                hCell.InsertElement(0, new object[] { 0, new object[] { "a55", "b55" } });

                Assert.AreEqual(hCell.Root.Count(), 9);

                e = (object[])hCell.Root.Element(0).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a55");
                Assert.AreEqual(o[1], "b55");

                e = (object[])hCell.Root.Element(5).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a44");
                Assert.AreEqual(o[1], "b44");

                e = (object[])hCell.Root.Element(8).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a16");
                Assert.AreEqual(o[1], "b16");
            }
            finally
            {
                hCell.Close();
            }
        }
コード例 #7
0
        public void InsertElementOutterTest()
        {
            var seqtriplets = new PTypeSequence(
                            new PTypeUnion(
                                new NamedType("test1",
                                    new PTypeRecord(
                                        new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                                        new NamedType("obj", new PType(PTypeEnumeration.sstring)))),
                                new NamedType("test2",
                                    new PTypeRecord(
                                        new NamedType("name", new PType(PTypeEnumeration.sstring)),
                                        new NamedType("value", new PType(PTypeEnumeration.integer))))
                             ));

            var testdb = new object[] {
                new object[] { 0, new object[] {"a11", "b11"}},
            };

            PhCell hCell = new PhCell(seqtriplets, string.Empty, "test");
            hCell.Fill(testdb);
            try
            {
                hCell.InsertElement(1000, new object[] { 0, new object[] { "a12", "b12" } });
                Assert.AreEqual(hCell.Root.Count(), 2);

                object[] e = (object[])hCell.Root.Element(1).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                object[] o = (object[])e[1];
                Assert.AreEqual(o[0], "a12");
                Assert.AreEqual(o[1], "b12");

                int step = 23725;

                for (int i = 1; i < step - 1; i++)
                {
                    hCell.InsertElement(i, new object[] { 0, new object[] { "a" + i, "b" + i } });
                    Assert.AreEqual(hCell.Root.Count(), i + 2);

                    e = (object[])hCell.Root.Element(i).Get().Value;
                    Assert.AreEqual(e.Length, 2);
                    Assert.AreEqual(e[0], 0);
                    o = (object[])e[1];
                    Assert.AreEqual(o[0], "a" + i);
                    Assert.AreEqual(o[1], "b" + i);
                }

                var str = string.Empty;
                hCell.InsertElement(step - 2, new object[] { 0, new object[] { "a003", "b003" } });
                Assert.AreEqual(hCell.Root.Count(), step + 1);

                e = (object[])hCell.Root.Element(step - 3).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a" + (step - 3));
                Assert.AreEqual(o[1], "b" + (step - 3));

                e = (object[])hCell.Root.Element(step - 2).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a003");
                Assert.AreEqual(o[1], "b003");

                var s = (object[])hCell.Root.Elements().Last().Get().Value;
                Assert.AreEqual(s.Length, 2);
                Assert.AreEqual(s[0], 0);
                o = (object[])s[1];
                Assert.AreEqual(o[0], "a12");
                Assert.AreEqual(o[1], "b12");

                hCell.InsertElement(step, new object[] { 0, new object[] { "a005", "b005" } });
                Assert.AreEqual(hCell.Root.Count(), step + 2);

                e = (object[])hCell.Root.Element(step - 3).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a" + (step - 3));
                Assert.AreEqual(o[1], "b" + (step - 3));

                e = (object[])hCell.Root.Element(step - 2).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a003");
                Assert.AreEqual(o[1], "b003");

                s = (object[])hCell.Root.Elements().Last().Get().Value;
                Assert.AreEqual(s.Length, 2);
                Assert.AreEqual(s[0], 0);
                o = (object[])s[1];
                Assert.AreEqual(o[0], "a12");
                Assert.AreEqual(o[1], "b12");

                hCell.InsertElement(step + 1, new object[] { 0, new object[] { "a006", "b006" } });
                Assert.AreEqual(hCell.Root.Count(), step + 3);

                e = (object[])hCell.Root.Element(step - 3).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a" + (step - 3));
                Assert.AreEqual(o[1], "b" + (step - 3));

                e = (object[])hCell.Root.Element(step - 2).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a003");
                Assert.AreEqual(o[1], "b003");

                s = (object[])hCell.Root.Elements().Last().Get().Value;
                Assert.AreEqual(s.Length, 2);
                Assert.AreEqual(s[0], 0);
                o = (object[])s[1];
                Assert.AreEqual(o[0], "a12");
                Assert.AreEqual(o[1], "b12");
            }
            finally
            {
                hCell.Close();
            }
        }
コード例 #8
0
        public void UpdateUnionTest()
        {
            var seqtriplets = new PTypeSequence(
                                new PTypeUnion(
                                    new NamedType("empty", new PType(PTypeEnumeration.none)),
                                    new NamedType("op",
                                        new PTypeRecord(
                                            new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                                            new NamedType("predicate", new PType(PTypeEnumeration.sstring)),
                                            new NamedType("obj", new PType(PTypeEnumeration.sstring)))),
                                    new NamedType("dp",
                                        new PTypeRecord(
                                            new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                                            new NamedType("predicate", new PType(PTypeEnumeration.sstring)),
                                            new NamedType("data", new PType(PTypeEnumeration.sstring)),
                                            new NamedType("lang", new PType(PTypeEnumeration.sstring)))))
                                );

            var testdb = new object[] {
                new object[] { 1, new object[] {"a", "b", "c"}},
                new object[] { 1, new object[] {"a1", "b1", "c1"}},
                new object[] { 2, new object[] {"da", "db", "dc", "lang"}}
            };

            PhCell hCell = new PhCell(seqtriplets, string.Empty, "test");
            try
            {
                hCell.Fill(testdb);
                Assert.AreEqual(3, hCell.Root.Count());
                var e = (object[])hCell.Root.Element(1).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 1);
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                var o = (object[])e[1];
                Assert.AreEqual(o.Length, 3);
                Assert.AreEqual(o[0], "a1");
                Assert.AreEqual(o[1], "b1");
                Assert.AreEqual(o[2], "c1");

                PhEntry entry = hCell.Root.Element(1);
                entry.Set(new object[] { 1, new object[] { "a2", "b2", "c134" } });

                e = (object[])hCell.Root.Element(1).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 1);
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                o = (object[])e[1];
                Assert.AreEqual(o.Length, 3);
                Assert.AreEqual(o[0], "a2");
                Assert.AreEqual(o[1], "b2");
                Assert.AreEqual(o[2], "c134");

            }
            finally
            {
                hCell.Close();
            }
        }
コード例 #9
0
        public void DeleteOutterElementTest()
        {
            var seqtriplets = new PTypeSequence(
                new PTypeUnion(
                    new NamedType("test1",
                        new PTypeRecord(
                            new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                            new NamedType("obj", new PType(PTypeEnumeration.sstring)))),
                    new NamedType("test2",
                        new PTypeRecord(
                            new NamedType("name", new PType(PTypeEnumeration.sstring)),
                            new NamedType("value", new PType(PTypeEnumeration.integer))))
                 ));

            var testdb = new object[] {
                new object[] { 0, new object[] {"a11", "b11"}},
                new object[] { 1, new object[] {"a21", 22}},
               };

            PhCell hCell = new PhCell(seqtriplets, string.Empty, "test");
            hCell.Fill(testdb);
            try
            {
                Assert.AreEqual(hCell.Root.Count(), 2);
                var e = (object[])hCell.Root.Element(1).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 1);
                var o = (object[])e[1];
                Assert.AreEqual(o[0], "a21");
                Assert.AreEqual(o[1], 22);

                int step = 17359;
                for (int i = 2; i < step; i++)
                {
                    hCell.AppendElement(new object[] { 0, new object[] { "a" + i, "b" + i } });
                    Assert.AreEqual(hCell.Root.Count(), i + 1);
                    e = (object[])hCell.Root.Element(i).Get().Value;
                    Assert.AreEqual(e.Length, 2);
                    Assert.AreEqual(e[0], 0);
                    o = (object[])e[1];
                    Assert.AreEqual(o[0], "a" + i);
                    Assert.AreEqual(o[1], "b" + i);
                }

                hCell.AppendElement(new object[] { 0, new object[] { "a" + step, "b" + step } });
                Assert.AreEqual(hCell.Root.Count(), step + 1);

                hCell.AppendElement(new object[] { 0, new object[] { "a" + (step + 1), "b" + (step + 1) } });
                Assert.AreEqual(hCell.Root.Count(), step + 2);

                hCell.AppendElement(new object[] { 0, new object[] { "a" + (step + 2), "b" + (step + 2) } });
                Assert.AreEqual(hCell.Root.Count(), step + 3);

                hCell.DeleteElement(step + 1);
                Assert.AreEqual(hCell.Root.Count(), step + 2);
                e = (object[])hCell.Root.Element(step - 1).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a" + (step - 1));
                Assert.AreEqual(o[1], "b" + (step - 1));

                var e1 = (object[])hCell.Root.Element(step).Get().Value;
                Assert.AreEqual(e1.Length, 2);
                Assert.AreEqual(e1[0], 0);
                o = (object[])e1[1];
                Assert.AreEqual(o[0], "a" + step);
                Assert.AreEqual(o[1], "b" + step);

                hCell.DeleteElement(step);
                Assert.AreEqual(hCell.Root.Count(), step + 1);
                e = (object[])hCell.Root.Element(step - 2).Get().Value;
                e1 = (object[])hCell.Root.Element(step).Get().Value;

                //проверяем работу списка после добавления элемента
                var s = (object[])hCell.Root.Elements().Last().Get().Value;
                Assert.AreEqual(s.Length, 2);
                Assert.AreEqual(s[0], 0);
                o = (object[])s[1];
                Assert.AreEqual(o[0], "a" + (step + 2));
                Assert.AreEqual(o[1], "b" + (step + 2));

            }
            finally
            {
                hCell.Close();
            }
        }
コード例 #10
0
ファイル: PhSortTest.cs プロジェクト: jurik/PolarDBTest
        public void SortAtomTest()
        {
            var seqtriplets = new PTypeSequence(new PType(PTypeEnumeration.integer));

            var testdb = new object[] { 15, 2, 31, 35, 11, 190, 21 };

            PhCell hCell = new PhCell(seqtriplets, string.Empty, "test");

            hCell.Fill(testdb);
            try
            {
                Assert.AreEqual(7, hCell.Root.Count());
                Assert.AreEqual(31, (int)hCell.Root.Element(2).Get().Value);
                Assert.AreEqual(35, (int)hCell.Root.Element(3).Get().Value);
                Assert.AreEqual(21, (int)hCell.Root.Element(6).Get().Value);

                hCell.Sort(e =>
                {
                    return (int)e.Get().Value;
                });
                Assert.AreEqual(7, hCell.Root.Count());
                Assert.AreEqual(2, (int)hCell.Root.Element(0).Get().Value);
                Assert.AreEqual(21, (int)hCell.Root.Element(3).Get().Value);
                Assert.AreEqual(190, (int)hCell.Root.Element(6).Get().Value);

            }
            finally
            {
                hCell.Close();
            }
        }