Exemple #1
0
        public void Test_DateItems()
        {
            var dtx1    = new GEDCOMDateValue(null, null, "DATE", "05 JAN 2013");
            var dtItem1 = new GEDCOMDateItem(dtx1);

            Assert.AreEqual("05.01.2013", dtItem1.ToString());

            var dtx2    = new GEDCOMDateValue(null, null, "DATE", "17 FEB 2013");
            var dtItem2 = new GEDCOMDateItem(dtx2);

            Assert.AreEqual("17.02.2013", dtItem2.ToString());

            Assert.AreEqual(0, dtItem1.CompareTo(dtItem1));
            Assert.AreEqual(-1, dtItem1.CompareTo(dtItem2));
            Assert.AreEqual(-1, dtItem1.CompareTo(null));
            Assert.AreEqual(+1, dtItem2.CompareTo(dtItem1));

            dtItem1 = new GEDCOMDateItem(dtx1);
            dtItem2 = new GEDCOMDateItem(null);
            Assert.AreEqual(-1, dtItem1.CompareTo(dtItem2));

            dtItem1 = new GEDCOMDateItem(null);
            dtItem2 = new GEDCOMDateItem(dtx2);
            Assert.AreEqual(+1, dtItem1.CompareTo(dtItem2));

            dtItem1 = new GEDCOMDateItem(null);
            dtItem2 = new GEDCOMDateItem(null);
            Assert.AreEqual(0, dtItem1.CompareTo(dtItem2));
        }
        public override float IsMatch(GEDCOMTag tag, MatchParams matchParams)
        {
            if (tag == null)
            {
                return(0.0f);
            }
            GEDCOMCustomEvent ev = (GEDCOMCustomEvent)tag;

            // match date
            float dateMatch = 0.0f;
            float locMatch  = 0.0f;
            int   matches   = 0;

            GEDCOMDateValue dtVal  = this.Date;
            GEDCOMDateValue dtVal2 = ev.Date;

            matches += 1;
            if (dtVal != null && dtVal2 != null)
            {
                dateMatch = dtVal.IsMatch(dtVal2, matchParams);
            }

            // match location - late code-on by option implementation
            if (matchParams.CheckEventPlaces)
            {
                matches += 1;

                if (this.Place == null && ev.Place == null)
                {
                    locMatch = 100.0f;
                }
                else if (this.Place != null && ev.Place != null && this.Place.StringValue == ev.Place.StringValue)
                {
                    locMatch = 100.0f;
                }
            }

            float match = (dateMatch + locMatch) / matches;

            return(match);
        }
Exemple #3
0
        public void Test_DateItems_IConvertible()
        {
            var dtx1    = new GEDCOMDateValue(null, null, "DATE", "05 JAN 2013");
            var dtItem1 = new GEDCOMDateItem(dtx1);

            Assert.AreEqual(TypeCode.Object, ((IConvertible)dtItem1).GetTypeCode());
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToBoolean(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToChar(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToSByte(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToByte(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToInt16(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToUInt16(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToInt32(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToUInt32(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToInt64(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToUInt64(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToSingle(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToDouble(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToDecimal(null); });
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToDateTime(null); });
            Assert.AreEqual("05.01.2013", ((IConvertible)dtItem1).ToString(null));
            Assert.Throws(typeof(NotImplementedException), () => { ((IConvertible)dtItem1).ToType(typeof(Int32), null); });
        }