Skip to content

Commit

Permalink
chore: refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sargeantPig committed Sep 11, 2024
1 parent 38db953 commit a134bf2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 41 deletions.
20 changes: 5 additions & 15 deletions RTWLib_Tests/modifiers/Tests_drMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBaseObj> 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<IBaseObj> dsParse = this.dp.Parse(ds, Creator.DScreator);
DS parsedds = new(dsParse, this.config);
List<IBaseObj> settlements = parsedds.GetItemsByIdent("settlement").DeepCopy();
List<string> missing = DRModifier.GetMissingRegionNames(settlements, parseddr);

DR descr_regions = Instance.InstanceDR(TestHelper.Config, TestHelper.DR);
DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS);
List<IBaseObj> settlements = descr_strat.GetItemsByIdent("settlement").DeepCopy();
List<string> 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);
}

}
42 changes: 16 additions & 26 deletions RTWLib_Tests/modifiers/Tests_stratMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ public class TestsStrat
[TestMethod]
public void CreateSettlement()
{
string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false);
List<IBaseObj> dsParse = this.dp.Parse(ds, Creator.DScreator);
DS parsedds = new(dsParse, this.config);
List<IBaseObj> settlements = parsedds.GetItemsByIdent("settlement").DeepCopy();
DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS);
List<IBaseObj> settlements = descr_strat.GetItemsByIdent("settlement").DeepCopy();
IBaseObj modifiedSettlement = StratModifier.CreateSettlement(settlements[0], "test_name");
string result = modifiedSettlement.Find("region");
Assert.AreEqual("test_name", result);
Expand All @@ -31,10 +29,8 @@ public void CreateSettlement()
[TestMethod]
public void CreateBuilding()
{
string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false);
List<IBaseObj> dsParse = this.dp.Parse(ds, Creator.DScreator);
DS parsedds = new(dsParse, this.config);
List<IBaseObj> settlements = parsedds.GetItemsByIdent("settlement").DeepCopy();
DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS);
List<IBaseObj> 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);
Expand All @@ -43,40 +39,34 @@ public void CreateBuilding()
[TestMethod]
public void AddSettlementToFaction()
{
string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false);
List<IBaseObj> dsParse = this.dp.Parse(ds, Creator.DScreator);
DS parsedds = new(dsParse, this.config);
List<IBaseObj> settlements = parsedds.GetItemsByCriteria("character", "settlement", "faction\tromans_julii,");
DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS);
List<IBaseObj> 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<IBaseObj> 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<IBaseObj> result = descr_strat.GetItemsByCriteria("character", "settlement", "faction\tromans_julii,");
Assert.AreEqual(3, result.Count);
Assert.AreEqual("test_name", result[1].Find("region"));
}

[TestMethod]
public void AddSettlementToFaction2()
{
string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false);
List<IBaseObj> dsParse = this.dp.Parse(ds, Creator.DScreator);
DS parsedds = new(dsParse, this.config);
List<IBaseObj> settlements = parsedds.GetItemsByCriteria("character", "settlement", "faction\tmacedon,");
DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS);
List<IBaseObj> 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<IBaseObj> result = parsedds.GetItemsByCriteria("character", "settlement", "faction\tmacedon,");
int placeAt = BaseWrapper.GetIndexByCriteria(descr_strat.Data, "faction\tmacedon,", "settlement");
descr_strat.InsertAt(placeAt + 1, modifiedSettlement);
List<IBaseObj> result = descr_strat.GetItemsByCriteria("character", "settlement", "faction\tmacedon,");
Assert.AreEqual(5, result.Count);
Assert.AreEqual("test_name", result[1].Find("region"));
}

[TestMethod]
public void CreateUnit()
{
string[] ds = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_strat.txt"), false);
List<IBaseObj> dsParse = this.dp.Parse(ds, Creator.DScreator);
DS parsedds = new(dsParse, this.config);
List<IBaseObj> units = parsedds.GetItemsByIdent("unit").DeepCopy();
DS descr_strat = Instance.InstanceDS(TestHelper.Config, TestHelper.DS);
List<IBaseObj> 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);
Expand Down

0 comments on commit a134bf2

Please sign in to comment.