using System; using UnitTestSharp; namespace Blacklight.Bezier.UnitTests { public class InputUncertaintyTests : TestFixture { public class UnitRoundoffTests : TestFixture { public void IsHalfTheGapAboveOne() { CheckEqual(InputUncertainty.FloatSpacing(1) / 2, InputUncertainty.UnitRoundoff); } } public class FloatSpacingTests : TestFixture { public void One_IsTheGapToTheNextFloat() { CheckEqual(Math.Pow(2, -23), InputUncertainty.FloatSpacing(1)); } public void NegativeValue_UsesItsMagnitude() { CheckEqual(InputUncertainty.FloatSpacing(1), InputUncertainty.FloatSpacing(-1)); } public void Zero_IsTheSmallestSubnormal() { CheckEqual((double)float.Epsilon, InputUncertainty.FloatSpacing(0)); } public void RoundsToFloatFirst() { CheckEqual(InputUncertainty.FloatSpacing(1), InputUncertainty.FloatSpacing(1 + 1e-10)); } } public class OfTests : TestFixture { public void OnTheCurve_IsZero() { ShellSample sample = ShellSample.FromPosition(2, 2, 10); CheckEqual(0.0, InputUncertainty.Of(sample, new ReferenceResult(0, 2))); } public void StraightBelowTheVertex_IsTheSpacingOfY() { ShellSample sample = ShellSample.FromPosition(0, -2, 10); CheckEqual(Math.Pow(2, -22), InputUncertainty.Of(sample, ReferenceDistance.Solve(sample))); } public void NearTheCurveFarOut_IsFarBelowTheSpacingOfY() { ShellSample sample = SampleSets.AlongNormal(foot: 1000, offset: 1, end: 1e7); double uncertainty = InputUncertainty.Of(sample, ReferenceDistance.Solve(sample)); CheckGreater(InputUncertainty.FloatSpacing(sample.Y) / 100, uncertainty); } } } }