許容値と検査の試験を追加する
このコミットが含まれているのは:
2ファイル変更
+181
検索条件に一致するファイルはありません
@@ -0,0 +1,123 @@
|
||||
namespace ComputeGuard.Tests;
|
||||
|
||||
public sealed class ComputeCheckTests
|
||||
{
|
||||
static readonly double Bound = Math.ScaleB(1d, -20);
|
||||
|
||||
static ComputeTolerance BoundTolerance() => new(8d, 1d, 0);
|
||||
|
||||
[Fact]
|
||||
public void AValueInsideTheToleranceIsAccepted()
|
||||
{
|
||||
var check = new ComputeCheck("spot", Bound / 2d, 0d, BoundTolerance());
|
||||
|
||||
var passes = check.Passes;
|
||||
|
||||
Assert.True(passes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AValueExactlyAtTheToleranceIsAccepted()
|
||||
{
|
||||
var check = new ComputeCheck("spot", Bound, 0d, BoundTolerance());
|
||||
|
||||
var passes = check.Passes;
|
||||
|
||||
Assert.True(passes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AValueJustBeyondTheToleranceIsRejected()
|
||||
{
|
||||
var check = new ComputeCheck("spot", Math.BitIncrement(Bound), 0d, BoundTolerance());
|
||||
|
||||
var passes = check.Passes;
|
||||
|
||||
Assert.False(passes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnErrorBelowTheReferenceIsJudgedLikeOneAbove()
|
||||
{
|
||||
var atBound = new ComputeCheck("spot", -Bound, 0d, BoundTolerance());
|
||||
var beyondBound = new ComputeCheck("spot", -Math.BitIncrement(Bound), 0d, BoundTolerance());
|
||||
|
||||
var accepted = atBound.Passes;
|
||||
var rejected = beyondBound.Passes;
|
||||
|
||||
Assert.True(accepted);
|
||||
Assert.False(rejected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(double.NaN)]
|
||||
[InlineData(double.PositiveInfinity)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
public void ANonFiniteMeasurementIsNeverAccepted(double measured)
|
||||
{
|
||||
var check = new ComputeCheck("spot", measured, 0d, new ComputeTolerance(1d, 1e300, 0));
|
||||
|
||||
var passes = check.Passes;
|
||||
|
||||
Assert.False(passes);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(double.NaN)]
|
||||
[InlineData(double.PositiveInfinity)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
public void ANonFiniteReferenceIsNeverAccepted(double reference)
|
||||
{
|
||||
var check = new ComputeCheck("spot", 0d, reference, new ComputeTolerance(1d, 1e300, 0));
|
||||
|
||||
var passes = check.Passes;
|
||||
|
||||
Assert.False(passes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SignedZerosAreEqual()
|
||||
{
|
||||
var check = new ComputeCheck("zero", -0d, 0d, ComputeTolerance.Exact);
|
||||
|
||||
var passes = check.Passes;
|
||||
|
||||
Assert.True(passes);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0L, true)]
|
||||
[InlineData(1L, false)]
|
||||
[InlineData(-1L, false)]
|
||||
[InlineData(long.MaxValue, false)]
|
||||
public void ACountIsAcceptedOnlyWhenNothingWasCounted(long count, bool expected)
|
||||
{
|
||||
var check = ComputeCheck.Count("nonfinite", count);
|
||||
|
||||
var passes = check.Passes;
|
||||
|
||||
Assert.Equal(expected, passes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ACountKeepsItsNameAndValue()
|
||||
{
|
||||
var check = ComputeCheck.Count("nonfinite", 3L);
|
||||
|
||||
Assert.Equal("nonfinite", check.Name);
|
||||
Assert.Equal(3d, check.Measured);
|
||||
Assert.Equal(0d, check.Reference);
|
||||
Assert.Equal(ComputeTolerance.Exact, check.Tolerance);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void ACountNeedsAName(string? name)
|
||||
{
|
||||
Action create = () => ComputeCheck.Count(name!, 0L);
|
||||
|
||||
Assert.ThrowsAny<ArgumentException>(create);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
namespace ComputeGuard.Tests;
|
||||
|
||||
public sealed class ComputeToleranceTests
|
||||
{
|
||||
[Fact]
|
||||
public void TheToleranceGrowsWithTheUlpsAndTheScale()
|
||||
{
|
||||
var tolerance = new ComputeTolerance(4d, 2d, 0);
|
||||
|
||||
var absolute = tolerance.Absolute;
|
||||
|
||||
Assert.Equal(8d * Math.ScaleB(1d, -23), absolute);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EachFlushedOperationAddsTheSmallestNormalFloat()
|
||||
{
|
||||
var tolerance = new ComputeTolerance(0d, 0d, 3);
|
||||
|
||||
var absolute = tolerance.Absolute;
|
||||
|
||||
Assert.Equal(3d * Math.ScaleB(1d, -126), absolute);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheScaledPartAndTheFlushedPartAreAdded()
|
||||
{
|
||||
var tolerance = new ComputeTolerance(8d, 1d, 2);
|
||||
|
||||
var absolute = tolerance.Absolute;
|
||||
|
||||
Assert.Equal(Math.ScaleB(1d, -20) + 2d * Math.ScaleB(1d, -126), absolute);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheExactToleranceAllowsNothing()
|
||||
{
|
||||
var exact = ComputeTolerance.Exact;
|
||||
|
||||
Assert.Equal(0d, exact.Absolute);
|
||||
Assert.Equal(default, exact);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1d, 1d, 0)]
|
||||
[InlineData(double.NaN, 1d, 0)]
|
||||
[InlineData(double.PositiveInfinity, 1d, 0)]
|
||||
[InlineData(1d, -1d, 0)]
|
||||
[InlineData(1d, double.NaN, 0)]
|
||||
[InlineData(1d, double.PositiveInfinity, 0)]
|
||||
[InlineData(1d, 1d, -1)]
|
||||
public void AToleranceWithoutAFiniteBoundIsRejected(double ulps, double scale, int flushedOperations)
|
||||
{
|
||||
Action create = () => _ = new ComputeTolerance(ulps, scale, flushedOperations);
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(create);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする