87 lines
No EOL
2.3 KiB
C#
87 lines
No EOL
2.3 KiB
C#
using FluentAssertions;
|
|
using Xunit;
|
|
|
|
namespace BucketChain.Test;
|
|
|
|
public sealed class FireTests
|
|
{
|
|
private const double InitialSize = 12.34D;
|
|
private const double GrowRate = 0.85D;
|
|
private const int Times = 17;
|
|
|
|
[Fact]
|
|
public void Construction_Simple()
|
|
{
|
|
var fire = new Fire(InitialSize, default(double));
|
|
|
|
fire.FireSize.Should().Be(InitialSize, "has not grown yet");
|
|
fire.Extinguished.Should().BeFalse("size > 0");
|
|
}
|
|
|
|
[Fact]
|
|
public void BurnHigher()
|
|
{
|
|
var fire = new Fire(InitialSize, GrowRate);
|
|
fire.BurnHigher();
|
|
|
|
fire.FireSize.Should().Be(InitialSize + GrowRate, "grow happened once");
|
|
fire.Extinguished.Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void BurnHigher_Multiple()
|
|
{
|
|
var fire = new Fire(InitialSize, GrowRate);
|
|
for (var i = 0; i < Times; i++)
|
|
{
|
|
fire.BurnHigher();
|
|
}
|
|
|
|
fire.FireSize.Should().BeApproximately(InitialSize + GrowRate * Times,
|
|
2E-14, $"grow happened {Times} times");
|
|
fire.Extinguished.Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void GetHitByWater_Simple()
|
|
{
|
|
var fire = new Fire(InitialSize, default);
|
|
|
|
fire.GetHitByWater(InitialSize - 1);
|
|
fire.FireSize.Should().Be(1);
|
|
fire.Extinguished.Should().BeFalse("not yet extinguished");
|
|
|
|
fire.GetHitByWater(1D);
|
|
fire.Extinguished.Should().BeTrue("now extinguished");
|
|
}
|
|
|
|
[Fact]
|
|
public void GetHitByWater_Complex()
|
|
{
|
|
var fire = new Fire(InitialSize, GrowRate);
|
|
|
|
fire.GetHitByWater(InitialSize - 1);
|
|
fire.Extinguished.Should().BeFalse("not yet extinguished");
|
|
|
|
fire.BurnHigher();
|
|
|
|
fire.GetHitByWater(1D);
|
|
fire.Extinguished.Should().BeFalse("not yet extinguished, because it grew");
|
|
|
|
fire.GetHitByWater(1D);
|
|
fire.Extinguished.Should().BeTrue("now extinguished");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(10, "🔥 10")]
|
|
[InlineData(1.23, "🔥 1")]
|
|
[InlineData(1.83, "🔥 2")]
|
|
[InlineData(0, "🔥 0")]
|
|
public void StringRepresentation(double size, string expected)
|
|
{
|
|
var fire = new Fire(size, default(double));
|
|
|
|
fire.ToString()
|
|
.Should().Be(expected);
|
|
}
|
|
} |