diff --git a/RTWLib_Tests/modifiers/Tests_drMod.cs b/RTWLib_Tests/modifiers/Tests_drMod.cs index a1215d8..91c12a6 100644 --- a/RTWLib_Tests/modifiers/Tests_drMod.cs +++ b/RTWLib_Tests/modifiers/Tests_drMod.cs @@ -2,34 +2,24 @@ namespace RTWLib_Tests.Modifiers; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; -using RTWLibPlus.data; using RTWLibPlus.dataWrappers; using RTWLibPlus.helpers; using RTWLibPlus.interfaces; -using RTWLibPlus.parsers; using RTWLibPlus.parsers.objects; using RTWLibPlus.Modifiers; [TestClass] public class TestsDR { - private readonly DepthParse dp = new(); - private readonly TWConfig config = TWConfig.LoadConfig(@"resources/remaster.json"); - [TestMethod] public void GetMissingRegions() { - string[] dr = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_regions.txt"), false); - List smfParse = this.dp.Parse(dr, Creator.DRcreator, '\t'); - DR parseddr = new(smfParse, this.config); - string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false); - List dsParse = this.dp.Parse(ds, Creator.DScreator); - DS parsedds = new(dsParse, this.config); - List settlements = parsedds.GetItemsByIdent("settlement").DeepCopy(); - List missing = DRModifier.GetMissingRegionNames(settlements, parseddr); - + DR descr_regions = Instance.InstanceDR(TestHelper.Config, TestHelper.DR); + DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS); + List settlements = descr_strat.GetItemsByIdent("settlement").DeepCopy(); + List missing = DRModifier.GetMissingRegionNames(settlements, descr_regions); int result = settlements.Count + missing.Count; - Assert.AreEqual(parseddr.Regions.Count, result); + Assert.AreEqual(descr_regions.Regions.Count, result); } } diff --git a/RTWLib_Tests/modifiers/Tests_stratMod.cs b/RTWLib_Tests/modifiers/Tests_stratMod.cs index cad9a77..94a8ea0 100644 --- a/RTWLib_Tests/modifiers/Tests_stratMod.cs +++ b/RTWLib_Tests/modifiers/Tests_stratMod.cs @@ -19,10 +19,8 @@ public class TestsStrat [TestMethod] public void CreateSettlement() { - string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false); - List dsParse = this.dp.Parse(ds, Creator.DScreator); - DS parsedds = new(dsParse, this.config); - List settlements = parsedds.GetItemsByIdent("settlement").DeepCopy(); + DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS); + List settlements = descr_strat.GetItemsByIdent("settlement").DeepCopy(); IBaseObj modifiedSettlement = StratModifier.CreateSettlement(settlements[0], "test_name"); string result = modifiedSettlement.Find("region"); Assert.AreEqual("test_name", result); @@ -31,10 +29,8 @@ public void CreateSettlement() [TestMethod] public void CreateBuilding() { - string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false); - List dsParse = this.dp.Parse(ds, Creator.DScreator); - DS parsedds = new(dsParse, this.config); - List settlements = parsedds.GetItemsByIdent("settlement").DeepCopy(); + DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS); + List settlements = descr_strat.GetItemsByIdent("settlement").DeepCopy(); IBaseObj modifiedBuilding = StratModifier.CreateBuilding(settlements[0].GetObject("building"), "test_name"); string result = modifiedBuilding.Find("type"); Assert.AreEqual("test_name", result); @@ -43,14 +39,12 @@ public void CreateBuilding() [TestMethod] public void AddSettlementToFaction() { - string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false); - List dsParse = this.dp.Parse(ds, Creator.DScreator); - DS parsedds = new(dsParse, this.config); - List settlements = parsedds.GetItemsByCriteria("character", "settlement", "faction\tromans_julii,"); + DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS); + List settlements = descr_strat.GetItemsByCriteria("character", "settlement", "faction\tromans_julii,"); IBaseObj modifiedSettlement = StratModifier.CreateSettlement(settlements[0], "test_name"); - int placeAt = BaseWrapper.GetIndexByCriteria(parsedds.Data, "faction\tromans_julii,", "settlement"); - parsedds.InsertAt(placeAt + 1, modifiedSettlement); - List result = parsedds.GetItemsByCriteria("character", "settlement", "faction\tromans_julii,"); + int placeAt = BaseWrapper.GetIndexByCriteria(descr_strat.Data, "faction\tromans_julii,", "settlement"); + descr_strat.InsertAt(placeAt + 1, modifiedSettlement); + List result = descr_strat.GetItemsByCriteria("character", "settlement", "faction\tromans_julii,"); Assert.AreEqual(3, result.Count); Assert.AreEqual("test_name", result[1].Find("region")); } @@ -58,14 +52,12 @@ public void AddSettlementToFaction() [TestMethod] public void AddSettlementToFaction2() { - string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false); - List dsParse = this.dp.Parse(ds, Creator.DScreator); - DS parsedds = new(dsParse, this.config); - List settlements = parsedds.GetItemsByCriteria("character", "settlement", "faction\tmacedon,"); + DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS); + List settlements = descr_strat.GetItemsByCriteria("character", "settlement", "faction\tmacedon,"); IBaseObj modifiedSettlement = StratModifier.CreateSettlement(settlements[0], "test_name"); - int placeAt = BaseWrapper.GetIndexByCriteria(parsedds.Data, "faction\tmacedon,", "settlement"); - parsedds.InsertAt(placeAt + 1, modifiedSettlement); - List result = parsedds.GetItemsByCriteria("character", "settlement", "faction\tmacedon,"); + int placeAt = BaseWrapper.GetIndexByCriteria(descr_strat.Data, "faction\tmacedon,", "settlement"); + descr_strat.InsertAt(placeAt + 1, modifiedSettlement); + List result = descr_strat.GetItemsByCriteria("character", "settlement", "faction\tmacedon,"); Assert.AreEqual(5, result.Count); Assert.AreEqual("test_name", result[1].Find("region")); } @@ -73,10 +65,8 @@ public void AddSettlementToFaction2() [TestMethod] public void CreateUnit() { - string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false); - List dsParse = this.dp.Parse(ds, Creator.DScreator); - DS parsedds = new(dsParse, this.config); - List units = parsedds.GetItemsByIdent("unit").DeepCopy(); + DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS); + List units = descr_strat.GetItemsByIdent("unit").DeepCopy(); IBaseObj result = StratModifier.CreateUnit(units[0], "town watch"); Assert.AreEqual("unit", result.Ident); Assert.AreEqual("unit\t\t\ttown", result.Tag);