| | | 1 | | //======================================================================= |
| | | 2 | | // Vector3dAssertions.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using FluentAssertions; |
| | | 9 | | using FluentAssertions.Execution; |
| | | 10 | | using FluentAssertions.Numeric; |
| | | 11 | | |
| | | 12 | | namespace FixedMathSharp.Assertions; |
| | | 13 | | |
| | | 14 | | public sealed class Vector3dAssertions : ComparableTypeAssertions<Vector3d, Vector3dAssertions> |
| | | 15 | | { |
| | 36 | 16 | | public Vector3dAssertions(Vector3d value) : base(value, AssertionChain.GetOrCreate()) { } |
| | | 17 | | |
| | 1 | 18 | | protected override string Identifier => "vector3d"; |
| | | 19 | | |
| | | 20 | | public AndConstraint<Vector3dAssertions> BeApproximately( |
| | | 21 | | Vector3d expected, |
| | | 22 | | Fixed64? tolerance = null, |
| | | 23 | | string because = "", |
| | | 24 | | params object[] becauseArgs) |
| | | 25 | | { |
| | 2 | 26 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | 2 | 27 | | Vector3d actual = (Vector3d)Subject; |
| | | 28 | | |
| | 2 | 29 | | CurrentAssertionChain |
| | 2 | 30 | | .ForCondition((actual - expected).Magnitude <= limit) |
| | 2 | 31 | | .BecauseOf(because, becauseArgs) |
| | 2 | 32 | | .FailWith("Expected vector3d to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limit, actu |
| | | 33 | | |
| | 1 | 34 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | public AndConstraint<Vector3dAssertions> NotBeApproximately( |
| | | 38 | | Vector3d expected, |
| | | 39 | | Fixed64? tolerance = null, |
| | | 40 | | string because = "", |
| | | 41 | | params object[] becauseArgs) |
| | | 42 | | { |
| | 2 | 43 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | 2 | 44 | | Vector3d actual = (Vector3d)Subject; |
| | | 45 | | |
| | 2 | 46 | | CurrentAssertionChain |
| | 2 | 47 | | .ForCondition((actual - expected).Magnitude > limit) |
| | 2 | 48 | | .BecauseOf(because, becauseArgs) |
| | 2 | 49 | | .FailWith("Expected vector3d not to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limit, |
| | | 50 | | |
| | 1 | 51 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | public AndConstraint<Vector3dAssertions> HaveComponentApproximately( |
| | | 55 | | Vector3d expected, |
| | | 56 | | Fixed64? tolerance = null, |
| | | 57 | | string because = "", |
| | | 58 | | params object[] becauseArgs) |
| | | 59 | | { |
| | 5 | 60 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | 5 | 61 | | Vector3d actual = (Vector3d)Subject; |
| | | 62 | | |
| | 5 | 63 | | CurrentAssertionChain |
| | 5 | 64 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(actual, expected, limit)) |
| | 5 | 65 | | .BecauseOf(because, becauseArgs) |
| | 5 | 66 | | .FailWith("Expected vector3d components to be approximately {0} +/- {1}{reason}, but found {2}.", expected, |
| | | 67 | | |
| | 1 | 68 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | public AndConstraint<Vector3dAssertions> HaveMagnitudeApproximately( |
| | | 72 | | Fixed64 expected, |
| | | 73 | | Fixed64? tolerance = null, |
| | | 74 | | string because = "", |
| | | 75 | | params object[] becauseArgs) |
| | | 76 | | { |
| | 2 | 77 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | 2 | 78 | | Vector3d actual = (Vector3d)Subject; |
| | | 79 | | |
| | 2 | 80 | | CurrentAssertionChain |
| | 2 | 81 | | .ForCondition(FixedAssertionHelpers.AreApproximatelyEqual(actual.Magnitude, expected, limit)) |
| | 2 | 82 | | .BecauseOf(because, becauseArgs) |
| | 2 | 83 | | .FailWith("Expected vector3d magnitude to be approximately {0} +/- {1}{reason}, but found {2}.", expected, l |
| | | 84 | | |
| | 1 | 85 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | public AndConstraint<Vector3dAssertions> BeNormalized( |
| | | 89 | | Fixed64? tolerance = null, |
| | | 90 | | string because = "", |
| | | 91 | | params object[] becauseArgs) |
| | | 92 | | { |
| | 2 | 93 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | 2 | 94 | | Vector3d actual = (Vector3d)Subject; |
| | | 95 | | |
| | 2 | 96 | | CurrentAssertionChain |
| | 2 | 97 | | .ForCondition(FixedAssertionHelpers.AreApproximatelyEqual(actual.Magnitude, Fixed64.One, limit)) |
| | 2 | 98 | | .BecauseOf(because, becauseArgs) |
| | 2 | 99 | | .FailWith("Expected vector3d to be normalized within +/- {0}{reason}, but found magnitude {1}.", limit, actu |
| | | 100 | | |
| | 1 | 101 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 102 | | } |
| | | 103 | | } |