public void ConceptChronologyDTOIsEquivalentTest()
        {
            {
                ConceptChronologyDTO a = Misc.CreateConceptChronologyDTO;
                ConceptChronologyDTO b = Misc.CreateConceptChronologyDTO;
                Assert.True(a.IsEquivalent(b));
            }

            {
                ConceptChronologyDTO a = Misc.CreateConceptChronologyDTO;
                ConceptChronologyDTO b = Misc.CreateConceptChronologyDTO
                                         with
                {
                    PublicId = new PublicId(Misc.other)
                };
                Assert.False(a.IsEquivalent(b));
            }

            {
                ConceptChronologyDTO a = new ConceptChronologyDTO(
                    Misc.PublicIdG,
                    Misc.ConceptVersionsBase(Misc.PublicIdG).ToImmutableArray()
                    );
                ConceptChronologyDTO b = new ConceptChronologyDTO(
                    Misc.PublicIdG,
                    new ConceptVersionDTO[]
                {
                    Misc.cv1(Misc.PublicIdG)
                }.ToImmutableArray()
                    );
                Assert.False(a.IsEquivalent(b));
            }
        }
        public void ConceptChronologyDTOCompareToTest()
        {
            {
                ConceptChronologyDTO a = Misc.CreateConceptChronologyDTO;
                ConceptChronologyDTO b = Misc.CreateConceptChronologyDTO;
                Assert.True(a.CompareTo(b) == 0);
            }

            {
                ConceptChronologyDTO a = Misc.CreateConceptChronologyDTO;
                ConceptChronologyDTO b = Misc.CreateConceptChronologyDTO
                                         with
                {
                    PublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4)
                };
                Assert.False(a.CompareTo(b) == 0);
            }

            {
                ConceptChronologyDTO a = new ConceptChronologyDTO(
                    Misc.PublicIdG,
                    Misc.ConceptVersionsBase(Misc.PublicIdG).ToImmutableArray()
                    );
                ConceptChronologyDTO b = new ConceptChronologyDTO(
                    Misc.PublicIdG,
                    new ConceptVersionDTO[]
                {
                    Misc.cv1(Misc.PublicIdG)
                }.ToImmutableArray()
                    );
                Assert.False(a.CompareTo(b) == 0);
            }
        }
Exemple #3
0
        public void PBToDTOConceptChronology()
        {
            ConceptChronologyDTO dtoStart = Misc.CreateConceptChronologyDTO;
            PBConceptChronology  pb       = dtoStart.ToPBConceptChronology();
            ConceptChronologyDTO dtoEnd   = pb.ToConceptChronology();

            Assert.True(dtoStart.CompareTo(dtoEnd) == 0);
        }
        public void ConceptChronologyDTOFieldsTest()
        {
            ConceptChronologyDTO dtoStart = Misc.CreateConceptChronologyDTO;

            Misc.Compare(dtoStart.PublicId, Misc.g1, Misc.g2, Misc.g3, Misc.g4);
            Misc.Compare(dtoStart.Versions,
                         Misc.ConceptVersionsBase(Misc.PublicIdG));
        }
Exemple #5
0
        public static PBConceptChronology ToPBConceptChronology(this ConceptChronologyDTO c)
        {
            //# Tested
            PBConceptChronology retVal = new PBConceptChronology
            {
                PublicId = c.PublicId.ToPBPublicId()
            };

            PBConceptVersion[] versions = new PBConceptVersion[c.Versions.Length];
            for (Int32 i = 0; i < c.Versions.Length; i++)
            {
                versions[i] = c.Versions[i].ToPBConceptVersion();
            }
            retVal.ConceptVersions.AddRange(versions);
            return(retVal);
        }
Exemple #6
0
        /// <summary>
        /// Read Tinkar items from file.
        /// </summary>
        /// <returns>Object[].</returns>
        public IEnumerable <ComponentDTO> GetComponents()
        {
            JObject jObject = this.ReadJsonObject();
            JArray  items   = (JArray)jObject["root"];

            foreach (JObject item in items)
            {
                String className = (String)item["class"];
                switch (className)
                {
                case ConceptChronologyDTO.JSONCLASSNAME:
                    yield return(ConceptChronologyDTO.Make(item));

                    break;

                case PatternChronologyDTO.JSONCLASSNAME:
                    yield return(PatternChronologyDTO.Make(item));

                    break;

                case SemanticChronologyDTO.JSONCLASSNAME:
                    yield return(SemanticChronologyDTO.Make(item));

                    break;

                case ConceptDTO.JSONCLASSNAME:
                    yield return(ConceptDTO.Make(item));

                    break;

                case PatternDTO.JSONCLASSNAME:
                    yield return(PatternDTO.Make(item));

                    break;

                case SemanticDTO.JSONCLASSNAME:
                    yield return(SemanticDTO.Make(item));

                    break;

                default:
                    throw new NotImplementedException($"Tinkar class {className} not known");
                }
            }
        }
        public void ConceptChronologyDTOJsonMarshal()
        {
            ConceptChronologyDTO dtoStart = Misc.CreateConceptChronologyDTO;
            MemoryStream         ms       = new MemoryStream();

            using (TinkarJsonOutput output = new TinkarJsonOutput(ms, true))
            {
                dtoStart.Marshal(output);
            }

            ms.Dump();
            ms.Position = 0;
            using (TinkarJsonInput input = new TinkarJsonInput(ms))
            {
                ConceptChronologyDTO dtoEnd = ConceptChronologyDTO.Make(input.ReadJsonObject());
                Assert.True(dtoStart.CompareTo(dtoEnd) == 0);
            }
        }
        public void ConceptChronologyDTOMarshalTest()
        {
            ConceptChronologyDTO dtoStart = new ConceptChronologyDTO(
                Misc.PublicIdG,
                Misc.ConceptVersionsBase(Misc.PublicIdG).ToImmutableArray()
                );

            MemoryStream ms = new MemoryStream();

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


            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                ConceptChronologyDTO dtoRead = (ConceptChronologyDTO)input.GetField();
                Assert.True(dtoStart.CompareTo(dtoRead) == 0);
            }
        }
Exemple #9
0
        /// <summary>
        /// Read IJsonMarshalable values from the named child property.
        /// </summary>
        /// <param name="jObj">JSON parent container.</param>
        /// <returns>IJsonMarshalable values.</returns>
        private static IJsonMarshalable ReadJsonMarshable(this JObject jObj)
        {
            String actualClassName = jObj[ComponentFieldForJson.CLASS]?.Value <String>();

            switch (actualClassName)
            {
            case null:
                throw new Exception($"{TErr} Missing CLASS Declaration");

            case ConceptChronologyDTO.JSONCLASSNAME:
                return(ConceptChronologyDTO.Make(jObj));

            case ConceptDTO.JSONCLASSNAME:
                return(ConceptDTO.Make(jObj));

            case PatternChronologyDTO.JSONCLASSNAME:
                return(PatternChronologyDTO.Make(jObj));

            case PatternDTO.JSONCLASSNAME:
                return(PatternDTO.Make(jObj));

            case SemanticChronologyDTO.JSONCLASSNAME:
                return(SemanticChronologyDTO.Make(jObj));

            case SemanticDTO.JSONCLASSNAME:
                return(SemanticDTO.Make(jObj));

            case SpatialPointDTO.JSONCLASSNAME:
                return(SpatialPointDTO.Make(jObj));

            case PlanarPointDTO.JSONCLASSNAME:
                return(PlanarPointDTO.Make(jObj));

            default:
                throw new NotImplementedException($"Class {actualClassName} not known");
            }
        }
Exemple #10
0
        /// <summary>
        /// Create serialized output test cases.
        /// These can be read into java side to compare java and c# implementations.
        /// </summary>
        public List <ComponentDTO> CreateComponents()
        {
            List <ComponentDTO> retVal = new List <ComponentDTO>();

            {
                IPublicId pid = NextPublicId(1);
                // Write ConceptChronologyDTO.
                ConceptChronologyDTO dto = new ConceptChronologyDTO(
                    pid,
                    new ConceptVersionDTO[]
                {
                    new ConceptVersionDTO(pid, NextStamp()),
                    new ConceptVersionDTO(pid, NextStamp())
                }.ToImmutableArray()
                    );
                retVal.Add(dto);
            }
            {
                ConceptDTO dto = new ConceptDTO(NextPublicId(4));
                retVal.Add(dto);
            }
            {
                IPublicId            pid = NextPublicId(1);
                PatternChronologyDTO dto = new PatternChronologyDTO(
                    pid,
                    new PatternVersionDTO[]
                {
                    new PatternVersionDTO(
                        pid,
                        NextStamp(),
                        NextPublicId(4),
                        NextPublicId(5),
                        new FieldDefinitionDTO[] {
                        new FieldDefinitionDTO(
                            NextPublicId(4),
                            NextPublicId(3),
                            NextPublicId(2)
                            ),
                        new FieldDefinitionDTO(
                            NextPublicId(1),
                            NextPublicId(2),
                            NextPublicId(3)
                            )
                    }.ToImmutableArray()
                        )
                }.ToImmutableArray()
                    );

                retVal.Add(dto);
            }
            {
                PatternDTO dto = new PatternDTO(NextPublicId(2));
                retVal.Add(dto);
            }
            {
                IPublicId componentPublicId           = NextPublicId(4);
                IPublicId patternForSemanticPublicId  = NextPublicId(3);
                IPublicId referencedComponentPublicId = NextPublicId(2);

                SemanticChronologyDTO dto = new SemanticChronologyDTO(
                    componentPublicId,
                    patternForSemanticPublicId,
                    referencedComponentPublicId,
                    new SemanticVersionDTO[]
                {
                    new SemanticVersionDTO(
                        componentPublicId,
                        NextStamp(),
                        new Object[]
                    {
                        true, false,
                        new byte[] { }, new byte[] { 1, 2, 3 },
                        0.3F,
                        -1, 0, 1,
                        "abcdef",
                        new DateTime(2020, 1, 2),
                        new SpatialPointDTO(1, 2, 3),
                        new PlanarPointDTO(-1, -2)
                    }.ToImmutableArray()
                        )
                }.ToImmutableArray()
                    );

                retVal.Add(dto);
            }
            {
                SemanticDTO dto = new SemanticDTO(NextPublicId(4));
                retVal.Add(dto);
            }
            {
                SemanticVersionDTO dto =
                    new SemanticVersionDTO(
                        NextPublicId(3),
                        NextStamp(),
                        new Object[]
                {
                    true, false,
                    new byte[] { }, new byte[] { 1, 2, 3 },
                    0.3F,
                    -1, 0, 1,
                    "abcdef",
                    new DateTime(2020, 1, 2),
                    new SpatialPointDTO(1, 2, 3),
                    new PlanarPointDTO(-1, -2)
                }.ToImmutableArray()
                        );
            }
            return(retVal);
        }
Exemple #11
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");
            }
        }