From ad826365bc1b12127281504081f8ba0180b20a4b Mon Sep 17 00:00:00 2001 From: Alex Zaytsev Date: Fri, 28 Jun 2024 10:35:20 +1000 Subject: [PATCH] Improve calculation of location names --- projects/GKCore/GDModel/GDMCustomDate.cs | 24 +++ projects/GKCore/GDModel/GDMLocationRecord.cs | 36 +++- .../GKTests/GDModel/GDMLocationRecordTests.cs | 188 ++++++++++++++++-- 3 files changed, 219 insertions(+), 29 deletions(-) diff --git a/projects/GKCore/GDModel/GDMCustomDate.cs b/projects/GKCore/GDModel/GDMCustomDate.cs index af7cb70b2..2eeddd57a 100644 --- a/projects/GKCore/GDModel/GDMCustomDate.cs +++ b/projects/GKCore/GDModel/GDMCustomDate.cs @@ -202,5 +202,29 @@ public static GDMDatePeriod GetIntersection(GDMCustomDate range1, GDMCustomDate return CreatePeriod(greatestStart, smallestEnd); } + + public static GDMList GetDifference(GDMCustomDate range1, GDMCustomDate range2) + { + GDMDate r1start, r1end, r2start, r2end, i2start, i2end; + range1.GetDateRange(out r1start, out r1end); + range2.GetDateRange(out r2start, out r2end); + range2.GetDateRange(out i2start, out i2end); + + var smallestStart = r1start.IsEmpty() || !r2start.IsEmpty() && r1start.CompareTo(r2start) < 0 ? r1start : r2start; + var greatestStart = r1start.IsEmpty() || !r2start.IsEmpty() && r2start.CompareTo(r1start) > 0 ? r2start : r1start; + var smallestEnd = r1end.IsEmpty() || !r2end.IsEmpty() && r1end.CompareTo(r2end) > 0 ? r2end : r1end; + var greatestEnd = r1end.IsEmpty() || !r2end.IsEmpty() && r1end.CompareTo(r2end) > 0 ? r1end : r2end; + + var result = new GDMList(); + result.Add(smallestStart.CompareTo(GDMDate.Decrement(greatestStart)) <= 0 || smallestStart.IsEmpty() + ? CreatePeriod(smallestStart, GDMDate.Decrement(greatestStart)) + : GDMDatePeriod.Empty); + + result.Add(GDMDate.Increment(smallestEnd).CompareTo(greatestEnd) <= 0 || greatestEnd.IsEmpty() + ? CreatePeriod(GDMDate.Increment(smallestEnd), greatestEnd) + : GDMDatePeriod.Empty); + + return result; + } } } diff --git a/projects/GKCore/GDModel/GDMLocationRecord.cs b/projects/GKCore/GDModel/GDMLocationRecord.cs index b48630a29..198fb7bed 100644 --- a/projects/GKCore/GDModel/GDMLocationRecord.cs +++ b/projects/GKCore/GDModel/GDMLocationRecord.cs @@ -189,7 +189,6 @@ public GDMList GetFullNames(GDMTree tree, ATDEnumeration atdEnu var topLoc = tree.GetPtrValue(topLevel); if (topLoc == null) continue; - bool wasJoin = false; var topNames = topLoc.GetFullNames(tree, atdEnum, abbreviations); for (int i = 0; i < topNames.Count; i++) { var topName = topNames[i]; @@ -198,36 +197,51 @@ public GDMList GetFullNames(GDMTree tree, ATDEnumeration atdEnu if (!interDate.IsEmpty()) { string tnVal = (abbreviations && !string.IsNullOrEmpty(topName.Abbreviation)) ? topName.Abbreviation : topName.StringValue; topBuffer.Add(new GDMLocationName(tnVal, interDate)); - wasJoin = true; } } - - if (!wasJoin && topNames.Count > 0) { - topBuffer.Add(new GDMLocationName(topNames[topNames.Count - 1].StringValue, topLevel.Date.Value)); - } } // search of intersections of location names and intersections of top levels/names for (int i = 0; i < fNames.Count; i++) { var locName = fNames[i]; + var locDate = locName.Date.Value; string nVal = (abbreviations && !string.IsNullOrEmpty(locName.Abbreviation)) ? locName.Abbreviation : locName.StringValue; - bool wasJoin = false; for (int j = 0; j < topBuffer.Count; j++) { var topLocName = topBuffer[j]; var topName = topLocName.StringValue; var topDate = topLocName.Date.Value; - var interDate = GDMCustomDate.GetIntersection(topDate, locName.Date.Value); + var interDate = GDMCustomDate.GetIntersection(topDate, locDate); if (!interDate.IsEmpty()) { string newName = (atdEnum == ATDEnumeration.fLtS) ? topName + ", " + nVal : nVal + ", " + topName; + // Find relative complement of topDate in locDate (locDate \ topDate) + // E.g. the periods that are in locDate, but not in topDate + // + // GetDifference returns two periods, one is that before topDate and one that is after + // + // Since both fNames and topBuffer lists are ordered we can assume that + // if before is not empty, it would mean that this location did not have a top level element within this period + // if after is not empty then we can try locating the next top level element within this period + // if after is empty then we finished processing this locName + + var differences = GDMCustomDate.GetDifference(interDate, locDate); + var before = differences[0]; + var after = differences[1]; + if (!before.IsEmpty()) { + result.Add(new GDMLocationName(nVal, before)); + } + result.Add(new GDMLocationName(newName, interDate)); - wasJoin = true; + locDate = after; + if (after.IsEmpty()) { + break; + } } } - if (!wasJoin) { - result.Add(new GDMLocationName(nVal, locName.Date.Value)); + if (!locDate.IsEmpty()) { + result.Add(new GDMLocationName(nVal, locDate)); } } } diff --git a/projects/GKTests/GDModel/GDMLocationRecordTests.cs b/projects/GKTests/GDModel/GDMLocationRecordTests.cs index b6e637352..ffb490d4e 100644 --- a/projects/GKTests/GDModel/GDMLocationRecordTests.cs +++ b/projects/GKTests/GDModel/GDMLocationRecordTests.cs @@ -19,12 +19,9 @@ */ using System; -using System.Collections.Generic; -using System.IO; using System.Linq; using GDModel.Providers.GEDCOM; using GKCore; -using GKCore.Options; using GKCore.Types; using GKTests; using NUnit.Framework; @@ -193,16 +190,7 @@ public void Test_Hierarchy() { var tree = new GDMTree(); - // J2G Rus transfer: 26 JAN 1918 (Julian), 1 FEB -> 14 FEB 1918 - - var locRus = tree.CreateLocation(); - locRus.AddLocName("Россия", "FROM 862 TO 1546"); - locRus.AddLocName("Российское царство", "FROM 1547 TO 21 OCT 1721");//++ - locRus.AddLocName("Российская империя", "FROM 22 OCT 1721 TO 31 AUG 1917");//++ - locRus.AddLocName("Российская республика", "FROM 01 SEP 1917 TO 18 JUL 1918");//++ - locRus.AddLocName("РСФСР", "FROM 19 JUL 1918 TO 29 DEC 1922");//++ - locRus.AddLocName("СССР", "FROM 30 DEC 1922 TO 26 DEC 1991");//++ - locRus.AddLocName("РФ", "FROM 27 DEC 1991");//++ + var locRus = CreateRussia(tree); var fullNames = locRus.GetFullNames(tree, ATDEnumeration.fStL); string result = string.Join("\n", fullNames.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); @@ -218,6 +206,8 @@ public void Test_Hierarchy() var locSibGub = tree.CreateLocation(); locSibGub.AddLocName("Сибирская губерния", "FROM 18 DEC 1708 TO 19 JAN 1782"); locSibGub.AddLocLink(locRus, "FROM 18 DEC 1708 TO 19 JAN 1782"); + Assert.True(locSibGub.ValidateLinks()); + Assert.True(locSibGub.ValidateNames()); fullNames = locSibGub.GetFullNames(tree, ATDEnumeration.fStL); result = string.Join("\n", fullNames.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); @@ -230,6 +220,8 @@ public void Test_Hierarchy() locKazGub.AddLocName("Казанское наместничество", "FROM 28 SEP 1781 TO 11 DEC 1796"); locKazGub.AddLocName("Казанская губерния", "FROM 12 DEC 1796 TO 27 MAY 1920"); locKazGub.AddLocLink(locRus, "FROM 18 DEC 1708 TO 27 MAY 1920"); + Assert.True(locKazGub.ValidateLinks()); + Assert.True(locKazGub.ValidateNames()); fullNames = locKazGub.GetFullNames(tree, ATDEnumeration.fStL); result = string.Join("\n", fullNames.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); @@ -252,6 +244,8 @@ public void Test_Hierarchy() locNizhNovgGub.AddLocName("Горьковская область", "FROM 05 DEC 1936 TO 21 OCT 1990"); locNizhNovgGub.AddLocName("Нижегородская область", "FROM 22 OCT 1990 TO 9999"); locNizhNovgGub.AddLocLink(locRus, "FROM JAN 1714 TO 9999"); + Assert.True(locNizhNovgGub.ValidateLinks()); + Assert.True(locNizhNovgGub.ValidateNames()); var locVyatGub = tree.CreateLocation(); locVyatGub.AddLocName("Вятская провинция", "FROM 29 MAY 1719 TO 10 SEP 1780"); @@ -265,6 +259,8 @@ public void Test_Hierarchy() locVyatGub.AddLocLink(locRus, "FROM 11 SEP 1780 TO 14 JUL 1929"); locVyatGub.AddLocLink(locNizhNovgGub, "FROM 15 JUL 1929 TO 29 JUL 1930"); locVyatGub.AddLocLink(locRus, "FROM 30 JUL 1930 TO 9999"); + Assert.True(locVyatGub.ValidateLinks()); + Assert.True(locVyatGub.ValidateNames()); fullNames = locVyatGub.GetFullNames(tree, ATDEnumeration.fStL); result = string.Join("\n", fullNames.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); @@ -279,11 +275,12 @@ public void Test_Hierarchy() "'15.07.1929 [G] - 29.07.1930 [G]': 'Вятский округ, Нижегородский край, СССР'\n" + "'07.12.1934 [G] - 04.12.1936 [G]': 'Кировский край, СССР'\n" + "'05.12.1936 [G] - 26.12.1991 [G]': 'Кировская область, СССР'\n" + - "'27.12.1991 [G] - __.__.9999 [G]': 'Кировская область, РФ'", + "'27.12.1991 [G] - __.__.9999 [G]': 'Кировская область, РФ'\n" + + "'__.__.10000 [G] >': 'Кировская область'", result); var locSlobUezd = tree.CreateLocation(); - locSlobUezd.AddLocName("Слободской уезд", "FROM 1646 TO 1719"); + locSlobUezd.AddLocName("Слободской уезд", "FROM 1646 TO 1718"); locSlobUezd.AddLocName("Слободской дистр.", "FROM 1719 TO 1726"); locSlobUezd.AddLocName("Слободской уезд", "FROM 1727 TO 09 JUN 1929"); locSlobUezd.AddLocName("Слободской район", "FROM 10 JUN 1929"); @@ -291,19 +288,26 @@ public void Test_Hierarchy() locSlobUezd.AddLocLink(locVyatGub, "FROM 1719 TO 1726"); locSlobUezd.AddLocLink(locVyatGub, "FROM 1727 TO 10 SEP 1780"); locSlobUezd.AddLocLink(locVyatGub, "FROM 11 SEP 1780 TO 10 JUN 1929"); + Assert.True(locSlobUezd.ValidateLinks()); + Assert.True(locSlobUezd.ValidateNames()); var locOmutUezd = tree.CreateLocation(); locOmutUezd.AddLocName("Омутнинский уезд", "FROM 05 JAN 1921 TO 09 JUN 1929"); locOmutUezd.AddLocName("Омутнинский район", "FROM 10 JUN 1929"); locOmutUezd.AddLocLink(locVyatGub, "FROM 05 JAN 1921 TO 9999"); + Assert.True(locOmutUezd.ValidateLinks()); + Assert.True(locOmutUezd.ValidateNames()); var locVerhkamRn = tree.CreateLocation(); locVerhkamRn.AddLocName("Верхнекамский район", "FROM 12 JAN 1965"); locVerhkamRn.AddLocLink(locVyatGub, "FROM 12 JAN 1965 TO 9999"); + Assert.True(locVerhkamRn.ValidateLinks()); + Assert.True(locVerhkamRn.ValidateNames()); fullNames = locSlobUezd.GetFullNames(tree, ATDEnumeration.fStL); result = string.Join("\n", fullNames.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); Assert.AreEqual("'__.__.1646 [G] - __.__.1718 [G]': 'Слободской уезд, Российское царство'\n" + + "'__.__.1719 [G] - 28.05.1719 [G]': 'Слободской дистр.'\n" + "'29.05.1719 [G] - 21.10.1721 [G]': 'Слободской дистр., Вятская провинция, Сибирская губерния, Российское царство'\n" + "'22.10.1721 [G] - __.__.1726 [G]': 'Слободской дистр., Вятская провинция, Сибирская губерния, Российская империя'\n" + "'__.__.1727 [G] - 28.04.1727 [G]': 'Слободской уезд, Вятская провинция, Сибирская губерния, Российская империя'\n" + @@ -313,21 +317,28 @@ public void Test_Hierarchy() "'01.09.1917 [G] - 18.07.1918 [G]': 'Слободской уезд, Вятская губерния, Российская республика'\n" + "'19.07.1918 [G] - 29.12.1922 [G]': 'Слободской уезд, Вятская губерния, РСФСР'\n" + "'30.12.1922 [G] - 09.06.1929 [G]': 'Слободской уезд, Вятская губерния, СССР'\n" + - "'10.06.1929 [G] - 10.06.1929 [G]': 'Слободской район, Вятская губерния, СССР'", + "'10.06.1929 [G] - 10.06.1929 [G]': 'Слободской район, Вятская губерния, СССР'\n" + + "'11.06.1929 [G] >': 'Слободской район'", result); var locVerhVol = tree.CreateLocation(); locVerhVol.AddLocName("Верховская вол.", "FROM 1720 TO 1764"); locVerhVol.AddLocLink(locSlobUezd, "FROM 1720 TO 1764"); + Assert.True(locVerhVol.ValidateLinks()); + Assert.True(locVerhVol.ValidateNames()); var locLoinVol = tree.CreateLocation(); locLoinVol.AddLocName("Лоинская вол.", "FROM 1802 TO 1884"); locLoinVol.AddLocLink(locSlobUezd, "FROM 1802 TO 1884"); + Assert.True(locLoinVol.ValidateLinks()); + Assert.True(locLoinVol.ValidateNames()); var locKirsVol = tree.CreateLocation(); locKirsVol.AddLocName("Кирсинская вол.", "FROM 1884 TO 1926"); - locKirsVol.AddLocLink(locSlobUezd, "FROM 1884 TO 1926"); + locKirsVol.AddLocLink(locSlobUezd, "FROM 1884 TO 1925"); locKirsVol.AddLocLink(locOmutUezd, "FROM 1926 TO 1926"); + Assert.True(locKirsVol.ValidateLinks()); + Assert.True(locKirsVol.ValidateNames()); var locPrislon = tree.CreateLocation(); locPrislon.AddLocName("поч. Старое раменье", "FROM 1678 TO 1719"); @@ -340,25 +351,31 @@ public void Test_Hierarchy() locPrislon.AddLocLink(locKirsVol, "FROM 1884 TO 1926"); locPrislon.AddLocLink(locOmutUezd, "FROM 1927 TO 1964"); locPrislon.AddLocLink(locVerhkamRn, "FROM 1965 TO 9999"); + Assert.True(locPrislon.ValidateLinks()); + Assert.True(locPrislon.ValidateNames()); fullNames = locPrislon.GetFullNames(tree, ATDEnumeration.fStL); result = string.Join("\n", fullNames.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); Assert.AreEqual("'__.__.1678 [G] - __.__.1718 [G]': 'поч. Старое раменье, Слободской уезд, Российское царство'\n" + + "'__.__.1719 [G] - __.__.1719 [G]': 'поч. Старое раменье, Слободской дистр.'\n" + "'__.__.1720 [G] - 21.10.1721 [G]': 'д. Прислонская, Верховская вол., Слободской дистр., Вятская провинция, Сибирская губерния, Российское царство'\n" + "'22.10.1721 [G] - __.__.1726 [G]': 'д. Прислонская, Верховская вол., Слободской дистр., Вятская провинция, Сибирская губерния, Российская империя'\n" + "'__.__.1727 [G] - 28.04.1727 [G]': 'д. Мокрая Слободка, Верховская вол., Слободской уезд, Вятская провинция, Сибирская губерния, Российская империя'\n" + "'29.04.1727 [G] - __.__.1764 [G]': 'д. Мокрая Слободка, Верховская вол., Слободской уезд, Вятская провинция, Казанская губерния, Российская империя'\n" + + "'__.__.1765 [G] - __.__.1801 [G]': 'д. Мокрая Слободка'\n" + "'__.__.1802 [G] - __.__.1883 [G]': 'д. Мокрая Слободка, Лоинская вол., Слободской уезд, Вятская губерния, Российская империя'\n" + "'__.__.1884 [G] - 31.08.1917 [G]': 'д. Мокрая Слободка, Кирсинская вол., Слободской уезд, Вятская губерния, Российская империя'\n" + "'01.09.1917 [G] - 18.07.1918 [G]': 'д. Мокрая Слободка, Кирсинская вол., Слободской уезд, Вятская губерния, Российская республика'\n" + "'19.07.1918 [G] - 29.12.1922 [G]': 'д. Мокрая Слободка, Кирсинская вол., Слободской уезд, Вятская губерния, РСФСР'\n" + - "'30.12.1922 [G] - __.__.1926 [G]': 'д. Мокрая Слободка, Кирсинская вол., Слободской уезд, Вятская губерния, СССР'\n" + + "'30.12.1922 [G] - __.__.1925 [G]': 'д. Мокрая Слободка, Кирсинская вол., Слободской уезд, Вятская губерния, СССР'\n" + "'__.__.1926 [G] - __.__.1926 [G]': 'д. Мокрая Слободка, Кирсинская вол., Омутнинский уезд, Вятская губерния, СССР'\n" + "'__.__.1927 [G] - 09.06.1929 [G]': 'д. Колегово, Омутнинский уезд, Вятская губерния, СССР'\n" + "'10.06.1929 [G] - 14.07.1929 [G]': 'д. Колегово, Омутнинский район, Вятская губерния, СССР'\n" + "'15.07.1929 [G] - 29.07.1930 [G]': 'д. Колегово, Омутнинский район, Вятский округ, Нижегородский край, СССР'\n" + + "'30.07.1930 [G] - 06.12.1934 [G]': 'д. Колегово, Омутнинский район'\n" + "'07.12.1934 [G] - 04.12.1936 [G]': 'д. Колегово, Омутнинский район, Кировский край, СССР'\n" + "'05.12.1936 [G] - __.__.1964 [G]': 'д. Колегово, Омутнинский район, Кировская область, СССР'\n" + + "'__.__.1965 [G] - 11.01.1965 [G]': 'д. Колегово'\n" + "'12.01.1965 [G] - __.__.1978 [G]': 'д. Колегово, Верхнекамский район, Кировская область, СССР'", result); @@ -385,6 +402,106 @@ public void Test_Hierarchy() //gedcomProvider.SaveToStreamExt(new FileStream("d:\\Russia.ged", FileMode.CreateNew), GEDCOMCharacterSet.csUTF8); } + [Test] + public void Test_Chisinau_SeparateTopLevels() + { + var tree = new GDMTree(); + var ussr = tree.CreateLocation(); + ussr.AddLocName("СССР", "FROM 30 DEC 1922 TO 26 DEC 1991"); + + var moldova = tree.CreateLocation(); + moldova.AddLocName("Молдова", "FROM 28 AUG 1991"); + + var moldavianSsr = tree.CreateLocation(); + moldavianSsr.AddLocName("Молдавская ССР", "FROM 2 AUG 1940 TO 27 AUG 1991"); + moldavianSsr.AddLocLink(ussr, "FROM 2 AUG 1940 TO 27 AUG 1991"); + + var carbuna = tree.CreateLocation(); + carbuna.AddLocName("Кишинёв", "FROM 14 OCT 1436"); + carbuna.AddLocLink(moldavianSsr, "FROM 2 AUG 1940 TO 27 AUG 1991"); + carbuna.AddLocLink(moldova, "FROM 28 AUG 1991"); + + var names = carbuna.GetFullNames(tree, ATDEnumeration.fLtS); + var result = string.Join("\n", names.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); + + Assert.AreEqual( + "'14.10.1436 [G] - 01.08.1940 [G]': 'Кишинёв'\n" + + "'02.08.1940 [G] - 27.08.1991 [G]': 'СССР, Молдавская ССР, Кишинёв'\n" + + "'28.08.1991 [G] >': 'Молдова, Кишинёв'" + , result); + } + + [Test] + public void Test_Chisinau_CombinedTopLevel() + { + var tree = new GDMTree(); + var ussr = CreateRussia(tree); + + var moldova = tree.CreateLocation(); + moldova.AddLocName("Молдавская ССР", "FROM 2 AUG 1940 TO 27 AUG 1991"); + moldova.AddLocLink(ussr, "FROM 2 AUG 1940 TO 27 AUG 1991"); + + var carbuna = tree.CreateLocation(); + carbuna.AddLocName("Кишинёв", "FROM 14 OCT 1436"); + carbuna.AddLocLink(moldova, "FROM 1812"); + + var names = carbuna.GetFullNames(tree, ATDEnumeration.fLtS); + var result = string.Join("\n", names.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); + + Assert.AreEqual( + "'14.10.1436 [G] - 01.08.1940 [G]': 'Кишинёв'\n" + + "'02.08.1940 [G] - 27.08.1991 [G]': 'СССР, Молдавская ССР, Кишинёв'\n" + + "'28.08.1991 [G] >': 'Кишинёв'" + , result); + + moldova.AddLocName("Молдова", "FROM 28 AUG 1991"); + + names = carbuna.GetFullNames(tree, ATDEnumeration.fLtS); + result = string.Join("\n", names.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); + + Assert.AreEqual( + "'14.10.1436 [G] - 01.08.1940 [G]': 'Кишинёв'\n" + + "'02.08.1940 [G] - 27.08.1991 [G]': 'СССР, Молдавская ССР, Кишинёв'\n" + + "'28.08.1991 [G] >': 'Молдова, Кишинёв'" + , result); + } + + [Test] + public void Test_VyatkaProvince_MissingLocationName() + { + var tree = new GDMTree(); + + var locRus = CreateRussia(tree); + + var locSibGub = tree.CreateLocation(); + var locKazGub = tree.CreateLocation(); + locKazGub.AddLocName("Казанская губерния", "FROM 12 DEC 1796 TO 27 MAY 1920"); + locKazGub.AddLocLink(locRus, "FROM 12 DEC 1796 TO 27 MAY 1920"); + Assert.True(locKazGub.ValidateLinks()); + Assert.True(locKazGub.ValidateNames()); + + locSibGub.AddLocName("Сибирская губерния", "FROM 18 DEC 1708 TO 19 JAN 1782"); + locSibGub.AddLocLink(locRus, "FROM 18 DEC 1708 TO 19 JAN 1782"); + Assert.True(locSibGub.ValidateLinks()); + Assert.True(locSibGub.ValidateNames()); + + var locVyatGub = tree.CreateLocation(); + locVyatGub.AddLocName("Вятская провинция", "FROM 29 MAY 1719 TO 10 SEP 1780"); + locVyatGub.AddLocLink(locSibGub, "FROM 29 MAY 1719 TO 28 APR 1727"); + locVyatGub.AddLocLink(locKazGub, "FROM 29 APR 1727 TO 10 SEP 1780"); + Assert.True(locVyatGub.ValidateLinks()); + Assert.True(locVyatGub.ValidateNames()); + + var names = locVyatGub.GetFullNames(tree, ATDEnumeration.fLtS); + var result = string.Join("\n", names.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); + + Assert.AreEqual( + "'29.05.1719 [G] - 21.10.1721 [G]': 'Российское царство, Сибирская губерния, Вятская провинция'\n" + + "'22.10.1721 [G] - 28.04.1727 [G]': 'Российская империя, Сибирская губерния, Вятская провинция'\n" + + "'29.04.1727 [G] - 10.09.1780 [G]': 'Вятская провинция'" + , result); + } + [Test] public void Test_DateIntersections() { @@ -419,12 +536,47 @@ public void Test_DateIntersections() Assert.AreEqual("", GDMCustomDate.GetIntersection(GetRange("FROM 1719 TO 1727"), GetRange("FROM 1747 TO 1834")).StringValue); // no intersects } + [TestCase("FROM 1775", "FROM 1940 TO 1991", "FROM 1775 TO 1939", "FROM 1992")] + [TestCase("FROM 1775", "FROM 1940", "FROM 1775 TO 1939", "")] + [TestCase("TO 2001", "FROM 1940 TO 1991", "TO 1939", "FROM 1992 TO 2001")] + [TestCase("TO 2001", "TO 1991", "", "FROM 1992 TO 2001")] + [TestCase("FROM 1937", "TO 1953", "TO 1936", "FROM 1954")] + [TestCase("FROM 1678 TO 1718", "FROM 1678 TO 1719", "", "FROM 1719 TO 1719")] + public void Test_GetDifference(string range1, string range2, string expected1, string expected2) + { + var difference = GDMCustomDate.GetDifference(GetRange(range1), GetRange(range2)); + Assert.AreEqual(2, difference.Count); + Assert.AreEqual(expected1, difference[0].StringValue); + Assert.AreEqual(expected2, difference[1].StringValue); + + difference = GDMCustomDate.GetDifference(GetRange(range2), GetRange(range1)); + Assert.AreEqual(2, difference.Count); + Assert.AreEqual(expected1, difference[0].StringValue); + Assert.AreEqual(expected2, difference[1].StringValue); + } + private static GDMDatePeriod GetRange(string strDateRange) { var result = new GDMDatePeriod(); result.ParseString(strDateRange); return result; } + + private static GDMLocationRecord CreateRussia(GDMTree tree) + { + // J2G Rus transfer: 26 JAN 1918 (Julian), 1 FEB -> 14 FEB 1918 + var locRus = tree.CreateLocation(); + locRus.AddLocName("Россия", "FROM 862 TO 1546"); + locRus.AddLocName("Российское царство", "FROM 1547 TO 21 OCT 1721"); //++ + locRus.AddLocName("Российская империя", "FROM 22 OCT 1721 TO 31 AUG 1917"); //++ + locRus.AddLocName("Российская республика", "FROM 01 SEP 1917 TO 18 JUL 1918"); //++ + locRus.AddLocName("РСФСР", "FROM 19 JUL 1918 TO 29 DEC 1922"); //++ + locRus.AddLocName("СССР", "FROM 30 DEC 1922 TO 26 DEC 1991"); //++ + locRus.AddLocName("РФ", "FROM 27 DEC 1991"); //++ + Assert.True(locRus.ValidateLinks()); + Assert.True(locRus.ValidateNames()); + return locRus; + } } public static class LocExts