Example #1
0
        public void DiGraphDTOFieldsTest()
        {
            DiGraphDTO dto = Misc.CreateDiGraphDTO();

            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.Predecessors(dto.Vertex(1)).Count() == 1);
            Assert.True(dto.Predecessors(dto.Vertex(1)).ElementAt(0) == dto.Vertex(0));

            Assert.True(dto.Predecessors(dto.Vertex(2)).Count() == 1);
            Assert.True(dto.Predecessors(dto.Vertex(2)).ElementAt(0) == dto.Vertex(0));

            Assert.True(dto.Predecessors(dto.Vertex(3)).Count() == 2);
            Assert.Contains(dto.Vertex(1), dto.Predecessors(dto.Vertex(3)));
            Assert.Contains(dto.Vertex(2), dto.Predecessors(dto.Vertex(3)));
        }
Example #2
0
        public void PBToDTODiGraph()
        {
            DiGraphDTO dtoStart = Misc.CreateDiGraphDTO();
            PBDiGraph  pb       = dtoStart.ToPBDiGraph();
            DiGraphDTO dtoEnd   = pb.ToDiGraph();

            Assert.True(dtoStart.CompareTo(dtoEnd) == 0);
        }
Example #3
0
        public static PBDiGraph ToPBDiGraph(this DiGraphDTO value)
        {
            PBDiGraph retVal = new PBDiGraph();

            retVal.RootSequence.Add(value.RootSequence.ToArray());
            retVal.VertexMap.AddRange(value.VertexMap.ToPBVertices());
            retVal.PredecesorMap.AddRange(value.PredecessorMap.ToPBIntToMultipleIntMap());
            retVal.SuccessorMap.AddRange(value.SuccessorMap.ToPBIntToMultipleIntMap());
            return(retVal);
        }
Example #4
0
        public void DiGraphDTOMarshalTest()
        {
            DiGraphDTO dtoStart = Misc.CreateDiGraphDTO();

            MemoryStream ms = new MemoryStream();

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

            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                DiGraphDTO dtoRead = DiGraphDTO.Make(input);
                Assert.True(dtoStart.CompareTo(dtoRead) == 0);
            }
        }
Example #5
0
        public void DiGraphDTOIsEquivalentTest()
        {
            {
                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO();
                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));

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               with
                {
                    RootSequence = new Int32[] { 1 }.ToImmutableList()
                };
                Assert.True(a.IsEquivalent(b) == false);
            }

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

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

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               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);

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               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);

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               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, ImmutableList <Int32> > .Builder predecessors = ImmutableDictionary <Int32, ImmutableList <Int32> > .Empty.ToBuilder();

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

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

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

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

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

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

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

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               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());
                successors.Add(2, new Int32[] { 3 }.ToImmutableList());

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               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());

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               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());

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               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());

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               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());

                DiGraphDTO a = Misc.CreateDiGraphDTO();
                DiGraphDTO b = Misc.CreateDiGraphDTO()
                               with
                {
                    SuccessorMap = successors.ToImmutable()
                };
                Assert.False(a.IsEquivalent(b));
            }
        }
Example #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");
            }
        }