Skip to content

Commit d6c04f9

Browse files
Replace unneeded interface usages with concrete types (#3035)
Co-authored-by: codefactor-io <support@codefactor.io>
1 parent ce068c1 commit d6c04f9

31 files changed

Lines changed: 83 additions & 74 deletions

ImperatorToCK3.UnitTests/CK3/ParserExtensionsTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ParserExtensionsTests {
1515
[InlineData(true, true, false, 0, 1)]
1616
public void CorrectModDependentBranchesAreUsed(bool wtwsms, bool tfe, bool vanillaCk3, int expectedValue1,
1717
int expectedValue2) {
18-
var ck3ModFlags = new Dictionary<string, bool> {["wtwsms"] = wtwsms, ["tfe"] = tfe, ["vanilla_ck3"] = vanillaCk3,};
18+
var ck3ModFlags = new OrderedDictionary<string, bool> {["wtwsms"] = wtwsms, ["tfe"] = tfe, ["vanilla_ck3"] = vanillaCk3,};
1919

2020
var blocReader = new BufferedReader(
2121
"""
@@ -63,7 +63,7 @@ public void ExceptionIsThrownWhenUnknownModFlagIsEncounteredInInterpolatedExpres
6363
""");
6464

6565
int? value = null;
66-
Dictionary<string, bool> modFlags = new();
66+
OrderedDictionary<string, bool> modFlags = [];
6767

6868
var parser1 = new Parser();
6969
parser1.RegisterModDependentBloc(modFlags);
@@ -86,7 +86,7 @@ public void VariableConditionResolvesToFalseWhenVariableIsNotDefined() {
8686
""");
8787

8888
int? value = null;
89-
Dictionary<string, bool> modFlags = new();
89+
OrderedDictionary<string, bool> modFlags = new();
9090

9191
var parser1 = new Parser();
9292
parser1.RegisterModDependentBloc(modFlags);
@@ -97,7 +97,7 @@ public void VariableConditionResolvesToFalseWhenVariableIsNotDefined() {
9797

9898
[Fact]
9999
public void ElseIfAfterElseIsIgnored() {
100-
Dictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla_ck3", false},};
100+
OrderedDictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla_ck3", false},};
101101

102102
var blocReader = new BufferedReader(
103103
"""
@@ -123,7 +123,7 @@ public void ElseIfAfterElseIsIgnored() {
123123

124124
[Fact]
125125
public void ElseAfterElseIsIgnored() {
126-
Dictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla_ck3", false},};
126+
OrderedDictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla_ck3", false},};
127127

128128
var blocReader = new BufferedReader(
129129
"""
@@ -149,7 +149,7 @@ public void ElseAfterElseIsIgnored() {
149149

150150
[Fact]
151151
public void ElseIfWithoutPrecedingIfIsIgnored() {
152-
Dictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla_ck3", false},};
152+
OrderedDictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla_ck3", false},};
153153

154154
var blocReader = new BufferedReader(
155155
"""
@@ -171,7 +171,7 @@ public void ElseIfWithoutPrecedingIfIsIgnored() {
171171

172172
[Fact]
173173
public void ElseWithoutPrecedingIfIsIgnored() {
174-
Dictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla_ck3", false},};
174+
OrderedDictionary<string, bool> ck3ModFlags = new() {{"wtwsms", false}, {"tfe", true}, {"vanilla_ck3", false},};
175175

176176
var blocReader = new BufferedReader(
177177
"""

ImperatorToCK3.UnitTests/CK3/Provinces/ProvinceTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using commonItems;
22
using commonItems.Colors;
3+
using commonItems.Collections;
34
using commonItems.Mods;
45
using AwesomeAssertions;
56
using ImperatorToCK3.CK3.Provinces;
@@ -100,7 +101,7 @@ private IReadOnlyCollection<Province> GetCK3ProvincesForIRGovernment(IReadOnlyCo
100101
ck3Provinces.Add(ck3Province);
101102
ck3Province.InitializeFromImperator(
102103
irProvince,
103-
ImmutableHashSet<ImperatorToCK3.Imperator.Provinces.Province>.Empty,
104+
new OrderedSet<ImperatorToCK3.Imperator.Provinces.Province>(),
104105
landedTitles,
105106
cultureMapper,
106107
religionMapper,

ImperatorToCK3.UnitTests/Mappers/HolySiteEffect/HolySiteEffectMapperTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public void MapperReturnsCorrectValues(string imperatorEffect, double imperatorV
1313
}
1414

1515
public static IEnumerable<object?[]> TestData =>
16-
new List<object?[]> {
17-
new object?[] { "wrong_effect", 1, null },
18-
new object?[] { "effect_to_multiply", 2, new KeyValuePair<string, double>("doubled_effect", 4) },
19-
new object?[] { "effect_to_divide", 4, new KeyValuePair<string, double>("divided_effect", 2) },
20-
new object?[] { "effect_to_nullify", 1, new KeyValuePair<string, double>("nullified_effect", 0)}
21-
};
16+
[
17+
["wrong_effect", 1, null],
18+
["effect_to_multiply", 2, new KeyValuePair<string, double>("doubled_effect", 4)],
19+
["effect_to_divide", 4, new KeyValuePair<string, double>("divided_effect", 2)],
20+
["effect_to_nullify", 1, new KeyValuePair<string, double>("nullified_effect", 0)]
21+
];
2222
}

ImperatorToCK3.UnitTests/Mappers/Technology/InnovationBonusTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using commonItems;
22
using ImperatorToCK3.Mappers.Technology;
33
using System;
4+
using System.Collections.Frozen;
45
using System.IO;
56
using Xunit;
67

@@ -37,8 +38,8 @@ public void GetProgressReturnsNullForNoProgress() {
3738
var reader = new BufferedReader("ir = ir_invention\nck3 = ck3_innovation");
3839
var bonus = new InnovationBonus(reader);
3940

40-
Assert.Null(bonus.GetProgress(Array.Empty<string>()));
41-
Assert.Null(bonus.GetProgress(["ir_other_invention"]));
41+
Assert.Null(bonus.GetProgress(Array.Empty<string>().ToFrozenSet()));
42+
Assert.Null(bonus.GetProgress(new[] { "ir_other_invention" }.ToFrozenSet()));
4243
}
4344

4445
[Fact]
@@ -47,9 +48,9 @@ public void EveryMatchingInventionGives25Progress() {
4748
var bonus = new InnovationBonus(reader);
4849

4950
Assert.Equal("ck3_innovation", bonus.CK3InnovationId);
50-
Assert.Equal(new("ck3_innovation", 25), bonus.GetProgress(["inv1"])!.Value);
51-
Assert.Equal(new("ck3_innovation", 50), bonus.GetProgress(["inv1", "inv2"])!.Value);
52-
Assert.Equal(new("ck3_innovation", 75), bonus.GetProgress(["inv1", "inv2", "inv3"])!.Value);
53-
Assert.Equal(new("ck3_innovation", 100), bonus.GetProgress(["inv1", "inv2", "inv3", "inv4"])!.Value);
51+
Assert.Equal(new("ck3_innovation", 25), bonus.GetProgress(new[] { "inv1" }.ToFrozenSet())!.Value);
52+
Assert.Equal(new("ck3_innovation", 50), bonus.GetProgress(new[] { "inv1", "inv2" }.ToFrozenSet())!.Value);
53+
Assert.Equal(new("ck3_innovation", 75), bonus.GetProgress(new[] { "inv1", "inv2", "inv3" }.ToFrozenSet())!.Value);
54+
Assert.Equal(new("ck3_innovation", 100), bonus.GetProgress(new[] { "inv1", "inv2", "inv3", "inv4" }.ToFrozenSet())!.Value);
5455
}
5556
}

ImperatorToCK3.UnitTests/Mappers/Trait/TraitMapperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void UndefinedCK3TraitsAreNotSkipped() {
119119
var ck3ModFS = new ModFilesystem(Path.Combine(config.CK3Path, "game"), new List<Mod>());
120120
var mapper = new TraitMapper("TestFiles/MapperTests/TraitMapper/trait_map_undefined_ck3_trait.txt", ck3ModFS);
121121

122-
var ck3Traits = mapper.GetCK3TraitsForImperatorTraits(new[] { "impTrait" });
122+
var ck3Traits = mapper.GetCK3TraitsForImperatorTraits(["impTrait"]);
123123
ck3Traits.Should().Contain("undefined");
124124
}
125125

ImperatorToCK3.UnitTests/Mappers/UnitType/UnitTypeMapperTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ImperatorToCK3.Mappers.UnitType;
2+
using System.Collections.Frozen;
23
using System.Collections.Generic;
34
using Xunit;
45

@@ -24,7 +25,7 @@ public void GetMenPerCK3UnitTypeReturnsCorrectValues() {
2425
var imperatorMenPerType = new Dictionary<string, int> {
2526
{"clibanarii", 1200}, {"cataphracts", 450}, // both mapped to cavalry
2627
{"archers", 200} // mapped to bowmen
27-
};
28+
}.ToFrozenDictionary();
2829
var ck3MenPerType = mapper.GetMenPerCK3UnitType(imperatorMenPerType);
2930
Assert.Collection(ck3MenPerType,
3031
kvp => {

ImperatorToCK3.UnitTests/Outputter/CoatOfArmsOutputterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public async Task CoaIsOutputtedForCountryWithFlagSet() {
7777
enabledCK3Dlcs: []
7878
);
7979

80-
await CoatOfArmsOutputter.OutputCoas(outputModPath, titles, new List<Dynasty>(), new CoaMapper());
80+
await CoatOfArmsOutputter.OutputCoas(outputModPath, titles, new DynastyCollection(), new CoaMapper());
8181

8282
var actualText = TextTestUtils.NormalizeNewlines(await File.ReadAllTextAsync(outputPath, TestContext.Current.CancellationToken));
8383
var expectedText = TextTestUtils.NormalizeNewlines(
@@ -129,7 +129,7 @@ public async Task CoaIsNotOutputtedForCountryWithoutFlagSet() {
129129
enabledCK3Dlcs: []
130130
);
131131

132-
await CoatOfArmsOutputter.OutputCoas(outputModPath, titles, new List<Dynasty>(), new CoaMapper());
132+
await CoatOfArmsOutputter.OutputCoas(outputModPath, titles, new DynastyCollection(), new CoaMapper());
133133

134134
var actualText = await File.ReadAllTextAsync(outputPath, TestContext.Current.CancellationToken);
135135
Assert.True(string.IsNullOrWhiteSpace(actualText));

ImperatorToCK3/CK3/Characters/Character.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ public bool LinkJailor(Date date) {
769769
}
770770

771771
internal void ImportUnitsAsMenAtArms(
772-
IEnumerable<Unit> countryUnits,
772+
Unit[] countryUnits,
773773
Date date,
774774
UnitTypeMapper unitTypeMapper,
775775
IdObjectCollection<string, MenAtArmsType> menAtArmsTypes,
@@ -806,7 +806,7 @@ CK3LocDB ck3LocDB
806806
History.AddFieldValue(date, "effects", "effect", new StringOfItem(sb.ToString()));
807807
}
808808
internal void ImportUnitsAsSpecialTroops(
809-
IEnumerable<Unit> countryUnits,
809+
Unit[] countryUnits,
810810
Imperator.Characters.CharacterCollection irCharacters,
811811
CountryCollection irCountries,
812812
Date date,

ImperatorToCK3/CK3/Characters/CharacterCollection.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public override void Remove(string key) {
145145
BulkRemove([key]);
146146
}
147147

148-
private void BulkRemove(ICollection<string> keys) {
148+
private void BulkRemove(List<string> keys) {
149149
foreach (var key in keys) {
150150
var characterToRemove = this[key];
151151

@@ -164,7 +164,7 @@ private void BulkRemove(ICollection<string> keys) {
164164
RemoveCharacterReferencesFromHistory(keys);
165165
}
166166

167-
private void RemoveCharacterReferencesFromHistory(ICollection<string> idsToRemove) {
167+
private void RemoveCharacterReferencesFromHistory(List<string> idsToRemove) {
168168
var idsCapturingGroup = "(" + string.Join('|', idsToRemove) + ")";
169169

170170
// Effects like "break_alliance = character:ID" entries should be removed.
@@ -477,7 +477,7 @@ private void SetCharacterCastes(CultureCollection cultures, Date ck3BookmarkDate
477477
return null;
478478
}
479479

480-
static bool HasAnyTrait(IEnumerable<string> traits, HashSet<string> relevantTraits) {
480+
static bool HasAnyTrait(List<string> traits, HashSet<string> relevantTraits) {
481481
foreach (var trait in traits) {
482482
if (relevantTraits.Contains(trait)) {
483483
return true;
@@ -487,10 +487,10 @@ static bool HasAnyTrait(IEnumerable<string> traits, HashSet<string> relevantTrai
487487
return false;
488488
}
489489

490-
static IEnumerable<Character> GetCharactersOrderedByBirthDateIfNeeded(IEnumerable<Character> characters) {
490+
static List<Character> GetCharactersOrderedByBirthDateIfNeeded(CharacterCollection characters) {
491491
using var enumerator = characters.GetEnumerator();
492492
if (!enumerator.MoveNext()) {
493-
return Array.Empty<Character>();
493+
return [];
494494
}
495495

496496
var orderedCharacters = new List<Character> { enumerator.Current };
@@ -621,7 +621,7 @@ internal void PurgeUnneededCharacters(Title.LandedTitles titles, DynastyCollecti
621621
dynasties.FlattenDynastiesWithNoFounders(this, houses, ck3BookmarkDate);
622622
}
623623

624-
private static void DetermineCharactersToPurge(List<Character> charactersToRemove, IEnumerable<Character> charactersToCheck,
624+
private static void DetermineCharactersToPurge(List<Character> charactersToRemove, Character[] charactersToCheck,
625625
HashSet<string> dynastyIdsOfLandedCharacters, HashSet<string> parentIdsCache, Date ck3BookmarkDate)
626626
{
627627
// See who can be removed.
@@ -905,7 +905,7 @@ private void GenerateSuccessorsForCharacter(Character oldCharacter, Dictionary<s
905905
TransferCharacterGoldToTheirLivingSuccessor(oldCharacter, currentCharacter);
906906
}
907907

908-
private static Character? GetOldestLivingMaleChild(IEnumerable<Character> children) {
908+
private static Character? GetOldestLivingMaleChild(IReadOnlyCollection<Character> children) {
909909
Character? oldestLivingMaleChild = null;
910910
foreach (var child in children) {
911911
if (child is {Female: true} || child.DeathDate is not null) {

ImperatorToCK3/CK3/ParserExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ImperatorToCK3.CK3;
1111

1212
public static class ParserExtensions {
13-
private static bool GetConditionValue(BufferedReader reader, IDictionary<string, bool> ck3ModFlags) {
13+
private static bool GetConditionValue(BufferedReader reader, OrderedDictionary<string, bool> ck3ModFlags) {
1414
var conditionLexeme = Parser.GetNextLexeme(reader);
1515
if (CommonRegexes.Variable.IsMatch(conditionLexeme)) {
1616
var value = reader.ResolveVariable(conditionLexeme);
@@ -33,7 +33,7 @@ private static bool GetConditionValue(BufferedReader reader, IDictionary<string,
3333
return ck3ModFlags[conditionLexeme];
3434
}
3535
}
36-
public static void RegisterModDependentBloc(this Parser parser, IDictionary<string, bool> ck3ModFlags) {
36+
public static void RegisterModDependentBloc(this Parser parser, OrderedDictionary<string, bool> ck3ModFlags) {
3737
parser.RegisterKeyword("MOD_DEPENDENT", blocReader => {
3838
// elseMode changes to true when IF condition is false.
3939
// Changes back to false when an ELSE_IF or ELSE block is entered.

0 commit comments

Comments
 (0)