示例#1
0
        public void PBToDTODiTree()
        {
            DiTreeDTO dtoStart = Misc.CreateDiTreeDTO();
            PBDiTree  pb       = dtoStart.ToPBDiTree();
            DiTreeDTO dtoEnd   = pb.ToDiTree();

            Assert.True(dtoStart.CompareTo(dtoEnd) == 0);
        }
示例#2
0
        public static PBDiTree ToPBDiTree(this DiTreeDTO value)
        {
            PBDiTree retVal = new PBDiTree();

            retVal.Root = value.Root.ToPBVertex();
            retVal.VertexMap.AddRange(value.VertexMap.ToPBVertices());
            retVal.PredecesorMap.AddRange(value.PredecessorMap.ToPBIntToIntMap());
            retVal.SuccessorMap.AddRange(value.SuccessorMap.ToPBIntToMultipleIntMap());
            return(retVal);
        }
示例#3
0
        public void DiTreeDTOMarshalTest()
        {
            DiTreeDTO dtoStart = Misc.CreateDiTreeDTO();

            MemoryStream ms = new MemoryStream();

            using (TinkarOutput output = new TinkarOutput(ms))
            {
                dtoStart.Marshal(output);
            }

            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                DiTreeDTO dtoRead = DiTreeDTO.Make(input);
                Assert.True(dtoStart.CompareTo(dtoRead) == 0);
            }
        }
示例#4
0
        public void DiTreeDTOFieldsTest()
        {
            DiTreeDTO dto = Misc.CreateDiTreeDTO();

            Assert.True(dto.VertexMap.Count == 4);
            Assert.True(dto.VertexMap[0] == dto.Vertex(Misc.g1));
            Assert.True(dto.VertexMap[1] == dto.Vertex(Misc.g2));
            Assert.True(dto.VertexMap[2] == dto.Vertex(Misc.g3));
            Assert.True(dto.VertexMap[3] == dto.Vertex(Misc.g4));

            Assert.True(dto.VertexMap[0] == dto.Vertex(0));
            Assert.True(dto.VertexMap[1] == dto.Vertex(1));
            Assert.True(dto.VertexMap[2] == dto.Vertex(2));
            Assert.True(dto.VertexMap[3] == dto.Vertex(3));

            Assert.True(dto.Vertex(0) == dto.Predecessor(dto.Vertex(1)));
            Assert.True(dto.Vertex(0) == dto.Predecessor(dto.Vertex(2)));
            Assert.True(dto.Vertex(1) == dto.Predecessor(dto.Vertex(3)));
        }
示例#5
0
        public void DiTreeDTOIsEquivalentTest()
        {
            {
                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO();
                Assert.True(a.IsEquivalent(b));
            }

            {
                ImmutableDictionary <IConcept, Object> .Builder pb1 = ImmutableDictionary <IConcept, Object> .Empty.ToBuilder();

                pb1.Add(new ConceptDTO(Misc.GID(0x1)), (Int32)1);
                pb1.Add(new ConceptDTO(Misc.GID(0x2)), (Int64)2);
                pb1.Add(new ConceptDTO(Misc.GID(0x3)), (Single)3);
                pb1.Add(new ConceptDTO(Misc.GID(0x4)), (Double)4);
                pb1.Add(new ConceptDTO(Misc.GID(0x5)), "abcdef");
                pb1.Add(new ConceptDTO(Misc.GID(0x7)), new DateTime(2000, 1, 1));

                VertexDTO newRoot = new VertexDTO(
                    Misc.g1,
                    123,
                    new ConceptDTO(Misc.PublicIdH),
                    pb1.ToImmutable()
                    );

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    Root = newRoot
                };
                Assert.True(a.IsEquivalent(b) == false);
            }

            {
                ImmutableDictionary <Int32, Int32> .Builder predecessors = ImmutableDictionary <Int32, Int32> .Empty.ToBuilder();

                predecessors.Add(0, 1);
                predecessors.Add(1, 2);

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    PredecessorMap = predecessors.ToImmutable()
                };
                Assert.True(a.IsEquivalent(b) == false);
            }

            {
                ImmutableDictionary <IConcept, Object> .Builder pBuilder1 = ImmutableDictionary <IConcept, Object> .Empty.ToBuilder();

                pBuilder1.Add(new ConceptDTO(Misc.GID(0x1)), (Int32)1);

                ImmutableDictionary <IConcept, Object> .Builder pBuilder2 = ImmutableDictionary <IConcept, Object> .Empty.ToBuilder();

                pBuilder2.Add(new ConceptDTO(Misc.GID(0x1)), (Int32)2);

                ImmutableDictionary <IConcept, Object> .Builder pBuilder3 = ImmutableDictionary <IConcept, Object> .Empty.ToBuilder();

                pBuilder3.Add(new ConceptDTO(Misc.GID(0x1)), (Int32)3);

                ImmutableDictionary <IConcept, Object> .Builder pBuilder4 = ImmutableDictionary <IConcept, Object> .Empty.ToBuilder();

                pBuilder4.Add(new ConceptDTO(Misc.GID(0x1)), (Int32)4);

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    VertexMap = new VertexDTO[]
                    {
                        new VertexDTO(
                            Misc.g1,
                            0,
                            new ConceptDTO(Misc.PublicIdG),
                            pBuilder1.ToImmutable()
                            ),
                        new VertexDTO(
                            Misc.g2,
                            1,
                            new ConceptDTO(Misc.PublicIdH),
                            pBuilder2.ToImmutable()
                            ),
                        new VertexDTO(
                            Misc.g3,
                            2,
                            new ConceptDTO(Misc.PublicIdI),
                            pBuilder3.ToImmutable()
                            ),
                        new VertexDTO(
                            Misc.g4,
                            3,
                            new ConceptDTO(Misc.j1),
                            pBuilder4.ToImmutable()
                            )
                    }.ToImmutableList()
                };
                Assert.True(a.IsEquivalent(b));
            }

            {
                ImmutableDictionary <IConcept, Object> .Builder pBuilder1 = ImmutableDictionary <IConcept, Object> .Empty.ToBuilder();

                pBuilder1.Add(new ConceptDTO(Misc.GID(0x1)), (Int32)1);

                ImmutableDictionary <IConcept, Object> .Builder pBuilder2 = ImmutableDictionary <IConcept, Object> .Empty.ToBuilder();

                pBuilder2.Add(new ConceptDTO(Misc.GID(0x1)), (Int32)2);

                ImmutableDictionary <IConcept, Object> .Builder pBuilder3 = ImmutableDictionary <IConcept, Object> .Empty.ToBuilder();

                pBuilder3.Add(new ConceptDTO(Misc.GID(0x1)), (Int32)3);

                ImmutableDictionary <IConcept, Object> .Builder pBuilder4 = ImmutableDictionary <IConcept, Object> .Empty.ToBuilder();

                pBuilder4.Add(new ConceptDTO(Misc.GID(0x1)), (Int32)4);

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    VertexMap = new VertexDTO[]
                    {
                        new VertexDTO(
                            Misc.g1,
                            0,
                            new ConceptDTO(Misc.PublicIdG),
                            pBuilder1.ToImmutable()
                            ),
                        new VertexDTO(
                            Misc.g2,
                            1,
                            new ConceptDTO(Misc.PublicIdH),
                            pBuilder2.ToImmutable()
                            ),
                        new VertexDTO(
                            Misc.g3,
                            2,
                            new ConceptDTO(Misc.PublicIdI),
                            pBuilder3.ToImmutable()
                            ),
                        new VertexDTO(
                            Misc.g4,
                            3,
                            new ConceptDTO(Misc.k1),
                            pBuilder4.ToImmutable()
                            )
                    }.ToImmutableList()
                };
                Assert.False(a.IsEquivalent(b));
            }



            {
                ImmutableDictionary <Int32, Int32> .Builder predecessors = ImmutableDictionary <Int32, Int32> .Empty.ToBuilder();

                predecessors.Add(1, 0);
                predecessors.Add(2, 0);
                predecessors.Add(3, 1);

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    PredecessorMap = predecessors.ToImmutable()
                };
                Assert.True(a.IsEquivalent(b));
            }

            {
                ImmutableDictionary <Int32, Int32> .Builder predecessors = ImmutableDictionary <Int32, Int32> .Empty.ToBuilder();

                predecessors.Add(1, 0);
                predecessors.Add(2, 0);

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    PredecessorMap = predecessors.ToImmutable()
                };
                Assert.False(a.IsEquivalent(b));
            }

            {
                ImmutableDictionary <Int32, Int32> .Builder predecessors = ImmutableDictionary <Int32, Int32> .Empty.ToBuilder();

                predecessors.Add(1, 0);
                predecessors.Add(2, 0);
                predecessors.Add(3, 2);

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    PredecessorMap = predecessors.ToImmutable()
                };
                Assert.False(a.IsEquivalent(b));
            }

            {
                ImmutableDictionary <Int32, ImmutableList <Int32> > .Builder successors = ImmutableDictionary <Int32, ImmutableList <Int32> > .Empty.ToBuilder();

                successors.Add(0, new Int32[] { 1, 2 }.ToImmutableList());
                successors.Add(1, new Int32[] { 3 }.ToImmutableList());

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    SuccessorMap = successors.ToImmutable()
                };
                Assert.True(a.IsEquivalent(b));
            }

            {
                ImmutableDictionary <Int32, ImmutableList <Int32> > .Builder successors = ImmutableDictionary <Int32, ImmutableList <Int32> > .Empty.ToBuilder();

                successors.Add(0, new Int32[] { 1, 3 }.ToImmutableList());
                successors.Add(1, new Int32[] { 3 }.ToImmutableList());

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    SuccessorMap = successors.ToImmutable()
                };
                Assert.False(a.IsEquivalent(b));
            }

            {
                ImmutableDictionary <Int32, ImmutableList <Int32> > .Builder successors = ImmutableDictionary <Int32, ImmutableList <Int32> > .Empty.ToBuilder();

                successors.Add(0, new Int32[] { 1, 2 }.ToImmutableList());

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    SuccessorMap = successors.ToImmutable()
                };
                Assert.False(a.IsEquivalent(b));
            }

            {
                ImmutableDictionary <Int32, ImmutableList <Int32> > .Builder successors = ImmutableDictionary <Int32, ImmutableList <Int32> > .Empty.ToBuilder();

                successors.Add(0, new Int32[] { 1, 2 }.ToImmutableList());
                successors.Add(2, new Int32[] { 3 }.ToImmutableList());

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    SuccessorMap = successors.ToImmutable()
                };
                Assert.False(a.IsEquivalent(b));
            }

            {
                ImmutableDictionary <Int32, ImmutableList <Int32> > .Builder successors = ImmutableDictionary <Int32, ImmutableList <Int32> > .Empty.ToBuilder();

                successors.Add(0, new Int32[] { 1, 2 }.ToImmutableList());
                successors.Add(2, new Int32[] { 3 }.ToImmutableList());

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    SuccessorMap = successors.ToImmutable()
                };
                Assert.False(a.IsEquivalent(b));
            }
        }
示例#6
0
        /// <summary>
        /// Read an array or Object fields.
        /// </summary>
        /// <returns>Object[].</returns>
        public Object GetField()
        {
            FieldDataType token;

            try
            {
                token = (FieldDataType)this.reader.ReadByte();
            }
            catch
            {
                return(null);
            }

            switch (token)
            {
            case FieldDataType.ConceptChronologyType:
                return(ConceptChronologyDTO.Make(this));

            case FieldDataType.PatternChronologyType:
                return(PatternChronologyDTO.Make(this));

            case FieldDataType.SemanticChronologyType:
                return(SemanticChronologyDTO.Make(this));

            case FieldDataType.ConceptVersionType:
                throw new NotImplementedException();

            case FieldDataType.PatternVersionType:
                throw new NotImplementedException();

            case FieldDataType.SemanticVersionType:
                throw new NotImplementedException();

            case FieldDataType.StampType:
                throw new NotImplementedException();

            case FieldDataType.ConceptType:
                return(ConceptDTO.Make(this));

            case FieldDataType.PatternType:
                return(PatternDTO.Make(this));

            case FieldDataType.SemanticType:
                return(SemanticDTO.Make(this));

            case FieldDataType.DiTreeType:
                return(DiTreeDTO.Make(this));

            case FieldDataType.DiGraphType:
                return(DiGraphDTO.Make(this));

            case FieldDataType.VertexType:
                throw new NotImplementedException();

            case FieldDataType.ComponentIdList:
                return(this.GetPublicIdList());

            case FieldDataType.ComponentIdSet:
                return(this.GetPublicIdSet());

            case FieldDataType.PlanarPoint:
                return(new PlanarPointDTO(this.GetInt32(), this.GetInt32()));

            case FieldDataType.SpatialPoint:
                return(new SpatialPointDTO(this.GetInt32(), this.GetInt32(), this.GetInt32()));

            case FieldDataType.StringType:
                return(this.GetUTF());

            case FieldDataType.IntegerType:
                return(this.GetInt32());

            case FieldDataType.FloatType:
                return(this.GetSingle());

            case FieldDataType.BooleanType:
                return(this.GetBoolean());

            case FieldDataType.ByteArrayType:
                return(this.GetByteArray());

            case FieldDataType.ObjectArrayType:
                return(this.GetObjects().ToArray());

            case FieldDataType.InstantType:
                return(this.GetInstant());

            default:
                throw new NotImplementedException($"FieldDataType {token} not known");
            }
        }