| | | 1 | | //======================================================================= |
| | | 2 | | // FixedQuaternionAssertions.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 FixedQuaternionAssertions : FixedStructAssertions<FixedQuaternion, FixedQuaternionAssertions> |
| | | 15 | | { |
| | 38 | 16 | | public FixedQuaternionAssertions(FixedQuaternion value) : base(value) { } |
| | | 17 | | |
| | 6 | 18 | | protected override string Identifier => "fixed quaternion"; |
| | | 19 | | |
| | | 20 | | public AndConstraint<FixedQuaternionAssertions> BeApproximately( |
| | | 21 | | FixedQuaternion expected, |
| | | 22 | | Fixed64? tolerance = null, |
| | | 23 | | string because = "", |
| | | 24 | | params object[] becauseArgs) |
| | | 25 | | { |
| | 7 | 26 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 27 | | |
| | 7 | 28 | | CurrentAssertionChain |
| | 7 | 29 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(Subject, expected, limit)) |
| | 7 | 30 | | .BecauseOf(because, becauseArgs) |
| | 7 | 31 | | .FailWith("Expected fixed quaternion components to be approximately {0} +/- {1}{reason}, but found {2}.", ex |
| | | 32 | | |
| | 2 | 33 | | return new AndConstraint<FixedQuaternionAssertions>(this); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | public AndConstraint<FixedQuaternionAssertions> NotBeApproximately( |
| | | 37 | | FixedQuaternion expected, |
| | | 38 | | Fixed64? tolerance = null, |
| | | 39 | | string because = "", |
| | | 40 | | params object[] becauseArgs) |
| | | 41 | | { |
| | 2 | 42 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 43 | | |
| | 2 | 44 | | CurrentAssertionChain |
| | 2 | 45 | | .ForCondition(!FixedAssertionHelpers.AreComponentApproximatelyEqual(Subject, expected, limit)) |
| | 2 | 46 | | .BecauseOf(because, becauseArgs) |
| | 2 | 47 | | .FailWith("Expected fixed quaternion not to be approximately {0} +/- {1}{reason}, but found {2}.", expected, |
| | | 48 | | |
| | 1 | 49 | | return new AndConstraint<FixedQuaternionAssertions>(this); |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | public AndConstraint<FixedQuaternionAssertions> HaveComponentApproximately( |
| | | 53 | | FixedQuaternion expected, |
| | | 54 | | Fixed64? tolerance = null, |
| | | 55 | | string because = "", |
| | | 56 | | params object[] becauseArgs) |
| | | 57 | | { |
| | 1 | 58 | | return BeApproximately(expected, tolerance, because, becauseArgs); |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public AndConstraint<FixedQuaternionAssertions> RepresentSameRotationAs( |
| | | 62 | | FixedQuaternion expected, |
| | | 63 | | Fixed64? tolerance = null, |
| | | 64 | | string because = "", |
| | | 65 | | params object[] becauseArgs) |
| | | 66 | | { |
| | 2 | 67 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 68 | | |
| | 2 | 69 | | CurrentAssertionChain |
| | 2 | 70 | | .ForCondition(FixedAssertionHelpers.RepresentsSameRotation(Subject, expected, limit)) |
| | 2 | 71 | | .BecauseOf(because, becauseArgs) |
| | 2 | 72 | | .FailWith("Expected fixed quaternion to represent the same rotation as {0} +/- {1}{reason}, but found {2}.", |
| | | 73 | | |
| | 1 | 74 | | return new AndConstraint<FixedQuaternionAssertions>(this); |
| | | 75 | | } |
| | | 76 | | |
| | | 77 | | public AndConstraint<FixedQuaternionAssertions> BeIdentity( |
| | | 78 | | string because = "", |
| | | 79 | | params object[] becauseArgs) |
| | | 80 | | { |
| | 2 | 81 | | return Be(FixedQuaternion.Identity, because, becauseArgs); |
| | | 82 | | } |
| | | 83 | | |
| | | 84 | | public AndConstraint<FixedQuaternionAssertions> BeNormalized( |
| | | 85 | | Fixed64? tolerance = null, |
| | | 86 | | string because = "", |
| | | 87 | | params object[] becauseArgs) |
| | | 88 | | { |
| | 2 | 89 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | 2 | 90 | | Fixed64 magnitude = FixedQuaternion.GetMagnitude(Subject); |
| | | 91 | | |
| | 2 | 92 | | CurrentAssertionChain |
| | 2 | 93 | | .ForCondition(FixedAssertionHelpers.AreApproximatelyEqual(magnitude, Fixed64.One, limit)) |
| | 2 | 94 | | .BecauseOf(because, becauseArgs) |
| | 2 | 95 | | .FailWith("Expected fixed quaternion to be normalized within +/- {0}{reason}, but found magnitude {1}.", lim |
| | | 96 | | |
| | 1 | 97 | | return new AndConstraint<FixedQuaternionAssertions>(this); |
| | | 98 | | } |
| | | 99 | | } |