Skip to content

Commit

Permalink
fix dumping measured(tally(0, X && Y)) (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Jun 26, 2023
1 parent 1c937bc commit 04fe66d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Source/Data/Requirement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,23 @@ internal void AppendString(StringBuilder builder, NumberFormat numberFormat,
case RequirementType.Measured:
case RequirementType.MeasuredPercent:
builder.Append("measured(");
AppendRepeatedCondition(builder, numberFormat, addSources, subSources, addHits, andNext, addAddress, resetNextIf);

// if there's no HitTarget and there's an AndNext or OrNext clause, assume we're counting
// complex conditions for a Value clause and wrap it in a "tally(0, ...)"
if (HitCount == 0 && !String.IsNullOrEmpty(andNext))
{
var measuredClause = new StringBuilder();
AppendRepeatedCondition(measuredClause, numberFormat, addSources, subSources, addHits, andNext, addAddress, resetNextIf);

builder.Append("tally(0, ");
builder.Append(RemoveOuterParentheses(measuredClause.ToString()));
builder.Append(')');
}
else
{
AppendRepeatedCondition(builder, numberFormat, addSources, subSources, addHits, andNext, addAddress, resetNextIf);
}

if (measuredIf != null)
{
builder.Append(", when=");
Expand Down
6 changes: 6 additions & 0 deletions Tests/Data/RequirementExTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class RequirementExTests
"repeated(10, byte(0x002345) == 1 && byte(0x003456) == 2 && never(byte(0x001234) < 5 || byte(0x001234) > 8))")]
[TestCase("Z:0xH004567=4_O:0xH001234=1_0xH002345=2.1.",
"once((byte(0x001234) == 1 || byte(0x002345) == 2) && never(byte(0x004567) == 4))")]
[TestCase("N:0xH001234=1_M:0xH002345=2.100.",
"measured(repeated(100, byte(0x001234) == 1 && byte(0x002345) == 2))")]
[TestCase("N:0xH001234=1_M:0xH002345=2",
"measured(tally(0, byte(0x001234) == 1 && byte(0x002345) == 2))")]
[TestCase("O:0xH001234=1_M:0xH002345=2",
"measured(tally(0, byte(0x001234) == 1 || byte(0x002345) == 2))")]
public void TestAppendString(string input, string expected)
{
var achievement = new AchievementBuilder();
Expand Down
6 changes: 6 additions & 0 deletions Tests/RATools.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Regressions\**" />
<EmbeddedResource Remove="Regressions\**" />
<None Remove="Regressions\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="4.17.2" />
<PackageReference Include="nunit" Version="3.13.3" />
Expand Down

0 comments on commit 04fe66d

Please sign in to comment.