Skip to content

Commit

Permalink
Merge pull request #36 from Cysharp/feature/RemoveFluentAssertions
Browse files Browse the repository at this point in the history
Remove Fluent Assertions
  • Loading branch information
mayuki authored Jan 16, 2025
2 parents 15739e5 + e938121 commit 0d8aa12
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 186 deletions.
1 change: 0 additions & 1 deletion test/LogicLooper.Test/LogicLooper.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
Expand Down
96 changes: 48 additions & 48 deletions test/LogicLooper.Test/LogicLooperCoroutineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
startFrame = ctx.CurrentFrame;
coroutine = ctx.RunCoroutine(async ctx2 =>
{
ctx2.CurrentFrame.Should().Be(startFrame);
Assert.Equal(startFrame, ctx2.CurrentFrame);

await ctx2.DelayFrame(60);

ctx2.CurrentFrame.Should().Be(startFrame + 60);
Assert.Equal(startFrame + 60, ctx2.CurrentFrame);

await ctx2.DelayNextFrame();

ctx2.CurrentFrame.Should().Be(startFrame + 61);
Assert.Equal(startFrame + 61, ctx2.CurrentFrame);

await ctx2.Delay(TimeSpan.FromMilliseconds(16.66666));

ctx2.CurrentFrame.Should().Be(startFrame + 62);
Assert.Equal(startFrame + 62, ctx2.CurrentFrame);
});
}

Expand All @@ -40,9 +40,9 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
if (coroutine.Exception != null)
throw coroutine.Exception;

coroutine.IsCompleted.Should().BeTrue();
coroutine.IsCompletedSuccessfully.Should().BeTrue();
coroutine.IsFaulted.Should().BeFalse();
Assert.True(coroutine.IsCompleted);
Assert.True(coroutine.IsCompletedSuccessfully);
Assert.False(coroutine.IsFaulted);
}

[Fact]
Expand All @@ -59,19 +59,19 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
startFrame = ctx.CurrentFrame;
coroutine = ctx.RunCoroutine(async ctx2 =>
{
ctx2.CurrentFrame.Should().Be(startFrame);
Assert.Equal(startFrame, ctx2.CurrentFrame);

await ctx2.DelayFrame(60);

ctx2.CurrentFrame.Should().Be(startFrame + 60);
Assert.Equal(startFrame + 60, ctx2.CurrentFrame);

await ctx2.DelayNextFrame();

ctx2.CurrentFrame.Should().Be(startFrame + 61);
Assert.Equal(startFrame + 61, ctx2.CurrentFrame);

await ctx2.Delay(TimeSpan.FromMilliseconds(16.66666));

ctx2.CurrentFrame.Should().Be(startFrame + 62);
Assert.Equal(startFrame + 62, ctx2.CurrentFrame);

return 12345;
});
Expand All @@ -83,11 +83,11 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
if (coroutine.Exception != null)
throw coroutine.Exception;

coroutine.IsCompleted.Should().BeTrue();
coroutine.IsCompletedSuccessfully.Should().BeTrue();
coroutine.IsFaulted.Should().BeFalse();
Assert.True(coroutine.IsCompleted);
Assert.True(coroutine.IsCompletedSuccessfully);
Assert.False(coroutine.IsFaulted);

coroutine.Result.Should().Be(12345);
Assert.Equal(12345, coroutine.Result);
}

[Fact]
Expand All @@ -104,7 +104,7 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
startFrame = ctx.CurrentFrame;
coroutine = ctx.RunCoroutine(async ctx2 =>
{
ctx2.CurrentFrame.Should().Be(startFrame);
Assert.Equal(startFrame, ctx2.CurrentFrame);

await ctx2.DelayFrame(5);

Expand All @@ -115,12 +115,12 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
return !coroutine.IsCompleted;
});

coroutine.IsCompleted.Should().BeTrue();
coroutine.IsCompletedSuccessfully.Should().BeFalse();
coroutine.IsFaulted.Should().BeTrue();
Assert.True(coroutine.IsCompleted);
Assert.False(coroutine.IsCompletedSuccessfully);
Assert.True(coroutine.IsFaulted);

coroutine.Exception.Should().NotBeNull();
coroutine.Exception.Message.Should().Be("ThrownFromCoroutine");
Assert.NotNull(coroutine.Exception);
Assert.Equal("ThrownFromCoroutine", coroutine.Exception.Message);
}

[Fact]
Expand All @@ -137,7 +137,7 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
startFrame = ctx.CurrentFrame;
coroutine = ctx.RunCoroutine(async ctx2 =>
{
ctx2.CurrentFrame.Should().Be(startFrame);
Assert.Equal(startFrame, ctx2.CurrentFrame);

await ctx2.DelayFrame(5);

Expand All @@ -152,12 +152,12 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
return !coroutine.IsCompleted;
});

coroutine.IsCompleted.Should().BeTrue();
coroutine.IsCompletedSuccessfully.Should().BeFalse();
coroutine.IsFaulted.Should().BeTrue();
Assert.True(coroutine.IsCompleted);
Assert.False(coroutine.IsCompletedSuccessfully);
Assert.True(coroutine.IsFaulted);

coroutine.Exception.Should().NotBeNull();
coroutine.Exception.Message.Should().Be("ThrownFromCoroutine");
Assert.NotNull(coroutine.Exception);
Assert.Equal("ThrownFromCoroutine", coroutine.Exception.Message);
}


Expand Down Expand Up @@ -189,11 +189,11 @@ public async Task CoroutineLooperAlwaysSameAsParentAction()
{
for (var k = 0; k < coroutineLoopCount; k++)
{
ctx2.Looper.Should().Be(looper);
Assert.Equal(looper, ctx2.Looper);

await ctx2.DelayFrame(1);

ctx2.Looper.Should().Be(looper);
Assert.Equal(looper, ctx2.Looper);

Interlocked.Increment(ref count);
}
Expand All @@ -215,7 +215,7 @@ public async Task CoroutineLooperAlwaysSameAsParentAction()

await Task.WhenAll(tasks);

count.Should().Be(loopsCount * coroutineCountPerLoop * coroutineLoopCount);
Assert.Equal(loopsCount * coroutineCountPerLoop * coroutineLoopCount, count);
}

[Fact]
Expand All @@ -232,15 +232,15 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
startFrame = ctx.CurrentFrame;
coroutine = ctx.RunCoroutine(async ctx2 =>
{
ctx2.CurrentFrame.Should().Be(startFrame);
Assert.Equal(startFrame, ctx2.CurrentFrame);

await ctx2.DelayNextFrame();

ctx2.CurrentFrame.Should().Be(startFrame + 1);
Assert.Equal(startFrame + 1, ctx2.CurrentFrame);

await ctx2.DelayNextFrame();

ctx2.CurrentFrame.Should().Be(startFrame + 2);
Assert.Equal(startFrame + 2, ctx2.CurrentFrame);
});
}

Expand All @@ -250,9 +250,9 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
if (coroutine.Exception != null)
throw coroutine.Exception;

coroutine.IsCompleted.Should().BeTrue();
coroutine.IsCompletedSuccessfully.Should().BeTrue();
coroutine.IsFaulted.Should().BeFalse();
Assert.True(coroutine.IsCompleted);
Assert.True(coroutine.IsCompletedSuccessfully);
Assert.False(coroutine.IsFaulted);
}

[Fact]
Expand All @@ -269,15 +269,15 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
startFrame = ctx.CurrentFrame;
coroutine = ctx.RunCoroutine(async ctx2 =>
{
ctx2.CurrentFrame.Should().Be(startFrame);
Assert.Equal(startFrame, ctx2.CurrentFrame);

await ctx2.DelayFrame(30);

ctx2.CurrentFrame.Should().Be(startFrame + 30);
Assert.Equal(startFrame + 30, ctx2.CurrentFrame);

await ctx2.DelayFrame(30);

ctx2.CurrentFrame.Should().Be(startFrame + 30 + 30);
Assert.Equal(startFrame + 30 + 30, ctx2.CurrentFrame);
});
}

Expand All @@ -287,9 +287,9 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
if (coroutine.Exception != null)
throw coroutine.Exception;

coroutine.IsCompleted.Should().BeTrue();
coroutine.IsCompletedSuccessfully.Should().BeTrue();
coroutine.IsFaulted.Should().BeFalse();
Assert.True(coroutine.IsCompleted);
Assert.True(coroutine.IsCompletedSuccessfully);
Assert.False(coroutine.IsFaulted);
}

[Fact]
Expand All @@ -306,15 +306,15 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
startFrame = ctx.CurrentFrame;
coroutine = ctx.RunCoroutine(async ctx2 =>
{
ctx2.CurrentFrame.Should().Be(startFrame);
Assert.Equal(startFrame, ctx2.CurrentFrame);

await ctx2.Delay(TimeSpan.FromMilliseconds(16.66666));

ctx2.CurrentFrame.Should().Be(startFrame + 1);
Assert.Equal(startFrame + 1, ctx2.CurrentFrame);

await ctx2.Delay(TimeSpan.FromMilliseconds(33.33333));

ctx2.CurrentFrame.Should().Be(startFrame + 1 + 2);
Assert.Equal(startFrame + 1 + 2, ctx2.CurrentFrame);
});
}

Expand All @@ -324,8 +324,8 @@ await looper.RegisterActionAsync((in LogicLooperActionContext ctx) =>
if (coroutine.Exception != null)
throw coroutine.Exception;

coroutine.IsCompleted.Should().BeTrue();
coroutine.IsCompletedSuccessfully.Should().BeTrue();
coroutine.IsFaulted.Should().BeFalse();
Assert.True(coroutine.IsCompleted);
Assert.True(coroutine.IsCompletedSuccessfully);
Assert.False(coroutine.IsFaulted);
}
}
20 changes: 10 additions & 10 deletions test/LogicLooper.Test/LogicLooperPoolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ public class LogicLooperPoolTest
public void Create()
{
using var pool = new LogicLooperPool(60, 4, RoundRobinLogicLooperPoolBalancer.Instance);
pool.Loopers.Should().HaveCount(4);
pool.Loopers[0].TargetFrameRate.Should().BeInRange(60, 60.1);
Assert.Equal(4, pool.Loopers.Count());
Assert.InRange(pool.Loopers[0].TargetFrameRate, 60, 60.1);
}

[Fact]
public void Create_TimeSpan()
{
using var pool = new LogicLooperPool(TimeSpan.FromMilliseconds(16.666), 4, RoundRobinLogicLooperPoolBalancer.Instance);
pool.Loopers.Should().HaveCount(4);
pool.Loopers[0].TargetFrameRate.Should().BeInRange(60, 60.1);
Assert.Equal(4, pool.Loopers.Count());
Assert.InRange(pool.Loopers[0].TargetFrameRate, 60, 60.1);
}

[Fact]
Expand All @@ -41,18 +41,18 @@ public void RegisterActionAsync()

Thread.Sleep(1000);

executedCount.Should().Be(actionCount * loopCount);
Assert.Equal(actionCount * loopCount, executedCount);
}

[Fact]
public void GetLooper()
{
using var pool = new LogicLooperPool(60, 4, new FakeSequentialLogicLooperPoolBalancer());
pool.GetLooper().Should().Be(pool.Loopers[0]);
pool.GetLooper().Should().Be(pool.Loopers[1]);
pool.GetLooper().Should().Be(pool.Loopers[2]);
pool.GetLooper().Should().Be(pool.Loopers[3]);
pool.GetLooper().Should().Be(pool.Loopers[0]);
Assert.Equal(pool.Loopers[0], pool.GetLooper());
Assert.Equal(pool.Loopers[1], pool.GetLooper());
Assert.Equal(pool.Loopers[2], pool.GetLooper());
Assert.Equal(pool.Loopers[3], pool.GetLooper());
Assert.Equal(pool.Loopers[0], pool.GetLooper());
}

class FakeSequentialLogicLooperPoolBalancer : ILogicLooperPoolBalancer
Expand Down
28 changes: 14 additions & 14 deletions test/LogicLooper.Test/LogicLooperSynchronizationContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public async Task Post()
count++;
}, null);

count.Should().Be(0);
Assert.Equal(0, count);
looper.Tick();
count.Should().Be(3);
Assert.Equal(3, count);
looper.Tick();
count.Should().Be(3);
Assert.Equal(3, count);
syncContext.Post(_ =>
{
count++;
}, null);
looper.Tick();
count.Should().Be(4);
Assert.Equal(4, count);
}

[Fact]
Expand All @@ -55,15 +55,15 @@ public async Task LooperIntegration()
});

looper.Tick();
result.Should().BeEquivalentTo(new[] { "1" });
Assert.Equal(new[] { "1" }, result);

await Task.Delay(500).ConfigureAwait(false);

looper.Tick(); // Run continuation
looper.Tick(); // Wait for complete action
result.Should().BeEquivalentTo(new[] { "1", "2" });
Assert.Equal(new[] { "1", "2" }, result);

task.IsCompleted.Should().BeTrue();
Assert.True(task.IsCompleted);
}

[Fact]
Expand All @@ -74,10 +74,10 @@ public async Task DequeueLoopAction_NotRegisteredWhenNonAsync()
SynchronizationContext.SetSynchronizationContext(syncContext); // This context is used when advancing frame within the Tick method. Use `ConfigureAwait(false)` in the following codes.
var t = looper.RegisterActionAsync((in LogicLooperActionContext ctx) => false);

looper.ApproximatelyRunningActions.Should().Be(1);
Assert.Equal(1, looper.ApproximatelyRunningActions);
looper.Tick();
looper.ApproximatelyRunningActions.Should().Be(0);
t.IsCompleted.Should().BeTrue();
Assert.Equal(0, looper.ApproximatelyRunningActions);
Assert.True(t.IsCompleted);
}

[Fact]
Expand All @@ -92,14 +92,14 @@ public async Task DequeueLoopAction_RegisteredWhenHasAsyncAction()
return false;
});

looper.ApproximatelyRunningActions.Should().Be(1); // User-Action
Assert.Equal(1, looper.ApproximatelyRunningActions); // User-Action
looper.Tick();
await Task.Delay(100).ConfigureAwait(false);
looper.ApproximatelyRunningActions.Should().Be(2); // User-Action + DequeLoopAction
Assert.Equal(2, looper.ApproximatelyRunningActions); // User-Action + DequeLoopAction
looper.Tick(); // Run continuation
looper.Tick(); // Wait for complete action
t.IsCompleted.Should().BeTrue();
looper.ApproximatelyRunningActions.Should().Be(1); // DequeueLoopAction
Assert.True(t.IsCompleted);
Assert.Equal(1, looper.ApproximatelyRunningActions); // DequeueLoopAction
}

}
Loading

0 comments on commit 0d8aa12

Please sign in to comment.