Пример #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 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);
            }
        }
Пример #3
0
        public void DiTreeDTOCompareToTest()
        {
            {
                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO();
                Assert.True(a.CompareTo(b) == 0);
            }

            {
                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.False(a.CompareTo(b) == 0);
            }

            {
                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.False(a.CompareTo(b) == 0);
            }

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

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

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

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

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

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

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

                pb4.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), pb1.ToImmutable()),
                        new VertexDTO(Misc.g2, 1, new ConceptDTO(Misc.PublicIdH), pb2.ToImmutable()),
                        new VertexDTO(Misc.g3, 2, new ConceptDTO(Misc.PublicIdI), pb3.ToImmutable()),
                        new VertexDTO(Misc.g4, 3, new ConceptDTO(Misc.j1), pb4.ToImmutable())
                    }.ToImmutableList()
                };
                Assert.True(a.CompareTo(b) != 0);
            }

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

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

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

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

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

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

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

                pb4.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),
                            pb1.ToImmutable()
                            ),
                        new VertexDTO(
                            Misc.g2,
                            102,
                            new ConceptDTO(Misc.PublicIdH),
                            pb2.ToImmutable()
                            ),
                        new VertexDTO(
                            Misc.g3,
                            2,
                            new ConceptDTO(Misc.PublicIdI),
                            pb3.ToImmutable()
                            ),
                        new VertexDTO(
                            Misc.g4,
                            3,
                            new ConceptDTO(Misc.k1),
                            pb4.ToImmutable()
                            )
                    }.ToImmutableList()
                };
                Assert.True(a.CompareTo(b) != 0);
            }

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

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

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    SuccessorMap = items.ToImmutable()
                };
                Assert.True(a.CompareTo(b) == 0);
            }

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

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

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    SuccessorMap = items.ToImmutable()
                };
                Assert.True(a.CompareTo(b) != 0);
            }

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

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

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    SuccessorMap = items.ToImmutable()
                };
                Assert.True(a.CompareTo(b) != 0);
            }

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

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

                DiTreeDTO a = Misc.CreateDiTreeDTO();
                DiTreeDTO b = Misc.CreateDiTreeDTO()
                              with
                {
                    SuccessorMap = items.ToImmutable()
                };
                Assert.True(a.CompareTo(b) != 0);
            }
        }