示例#1
0
        private void Solve()
        {
            fResult = "???";

            if (fRec1 != null && fRec2 != null)
            {
                using (KinshipsGraph kinsGraph = KinshipsGraph.SearchGraph(fBase.Context, fRec1)) {
                    if (kinsGraph.IsEmpty())
                    {
                        fResult = "Empty graph.";
                        return;
                    }

                    if (kinsGraph.FindVertex(fRec2.XRef) == null)
                    {
                        fResult = "These individuals have no common relatives.";
                        return;
                    }

                    kinsGraph.SetTreeRoot(fRec1);
                    fResult = kinsGraph.GetRelationship(fRec2, true);

                    #if DEBUG_SOLVE
                    fResult += "\r\n" + kinsGraph.IndividualsPath;
                    #endif
                }
            }

            UpdateView();
        }
示例#2
0
        public void Test_KinshipsGraph()
        {
            GDMIndividualRecord indRec   = fContext.Tree.XRefIndex_Find("I1") as GDMIndividualRecord;
            GDMIndividualRecord chldRec  = fContext.Tree.XRefIndex_Find("I3") as GDMIndividualRecord;
            GDMIndividualRecord otherRec = fContext.Tree.XRefIndex_Find("I4") as GDMIndividualRecord;
            GDMIndividualRecord wifeRec  = fContext.Tree.XRefIndex_Find("I2") as GDMIndividualRecord;
            GDMIndividualRecord rec5     = fContext.Tree.XRefIndex_Find("I5") as GDMIndividualRecord;

            Assert.Throws(typeof(ArgumentNullException), () => { KinshipsGraph.SearchGraph(fContext, null); });

            using (KinshipsGraph kinsGraph = KinshipsGraph.SearchGraph(fContext, indRec)) {
                Assert.IsNull(kinsGraph.AddIndividual(null));

                Assert.IsNotNull(kinsGraph.FindVertex(chldRec.XRef));

                // check invalid args
                kinsGraph.SetTreeRoot(null);
                kinsGraph.SetTreeRoot(otherRec);

                // valid individual
                kinsGraph.SetTreeRoot(indRec);

                Assert.AreEqual("???", kinsGraph.GetRelationship(null));
                Assert.AreEqual("???", kinsGraph.GetRelationship(otherRec));

                string result = kinsGraph.GetRelationship(chldRec);
                Assert.AreEqual("daughter", result);

                result = kinsGraph.GetRelationship(wifeRec);
                Assert.AreEqual("wife", result);

                result = kinsGraph.GetRelationship(rec5);
                Assert.AreEqual("granddaughter", result);

                Assert.IsFalse(kinsGraph.IsEmpty());
                kinsGraph.Clear();
                Assert.IsTrue(kinsGraph.IsEmpty());
            }
        }