| | | 1 | | //======================================================================= |
| | | 2 | | // Fixed4x4Assertions.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 Fixed4x4Assertions : FixedStructAssertions<Fixed4x4, Fixed4x4Assertions> |
| | | 15 | | { |
| | 74 | 16 | | public Fixed4x4Assertions(Fixed4x4 value) : base(value) { } |
| | | 17 | | |
| | 4 | 18 | | protected override string Identifier => "fixed4x4 matrix"; |
| | | 19 | | |
| | | 20 | | public AndConstraint<Fixed4x4Assertions> BeApproximately( |
| | | 21 | | Fixed4x4 expected, |
| | | 22 | | Fixed64? tolerance = null, |
| | | 23 | | string because = "", |
| | | 24 | | params object[] becauseArgs) |
| | | 25 | | { |
| | 18 | 26 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 27 | | |
| | 18 | 28 | | CurrentAssertionChain |
| | 18 | 29 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(Subject, expected, limit)) |
| | 18 | 30 | | .BecauseOf(because, becauseArgs) |
| | 18 | 31 | | .FailWith("Expected fixed4x4 matrix to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limi |
| | | 32 | | |
| | 1 | 33 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | public AndConstraint<Fixed4x4Assertions> NotBeApproximately( |
| | | 37 | | Fixed4x4 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 fixed4x4 matrix not to be approximately {0} +/- {1}{reason}, but found {2}.", expected, |
| | | 48 | | |
| | 1 | 49 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | public AndConstraint<Fixed4x4Assertions> BeIdentity( |
| | | 53 | | string because = "", |
| | | 54 | | params object[] becauseArgs) |
| | | 55 | | { |
| | 2 | 56 | | return Be(Fixed4x4.Identity, because, becauseArgs); |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | public AndConstraint<Fixed4x4Assertions> BeAffine( |
| | | 60 | | string because = "", |
| | | 61 | | params object[] becauseArgs) |
| | | 62 | | { |
| | 2 | 63 | | CurrentAssertionChain |
| | 2 | 64 | | .ForCondition(Subject.IsAffine) |
| | 2 | 65 | | .BecauseOf(because, becauseArgs) |
| | 2 | 66 | | .FailWith("Expected fixed4x4 matrix to be affine{reason}, but found {0}.", Subject); |
| | | 67 | | |
| | 1 | 68 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | public AndConstraint<Fixed4x4Assertions> HaveTranslationApproximately( |
| | | 72 | | Vector3d expected, |
| | | 73 | | Fixed64? tolerance = null, |
| | | 74 | | string because = "", |
| | | 75 | | params object[] becauseArgs) |
| | | 76 | | { |
| | 2 | 77 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | 2 | 78 | | Vector3d translation = Subject.Translation; |
| | | 79 | | |
| | 2 | 80 | | CurrentAssertionChain |
| | 2 | 81 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(translation, expected, limit)) |
| | 2 | 82 | | .BecauseOf(because, becauseArgs) |
| | 2 | 83 | | .FailWith("Expected fixed4x4 matrix translation to be approximately {0} +/- {1}{reason}, but found {2}.", ex |
| | | 84 | | |
| | 1 | 85 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | public AndConstraint<Fixed4x4Assertions> HaveScaleApproximately( |
| | | 89 | | Vector3d expected, |
| | | 90 | | Fixed64? tolerance = null, |
| | | 91 | | string because = "", |
| | | 92 | | params object[] becauseArgs) |
| | | 93 | | { |
| | 3 | 94 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | 3 | 95 | | Vector3d scale = Fixed4x4.ExtractScaleMagnitudes(Subject); |
| | | 96 | | |
| | 3 | 97 | | CurrentAssertionChain |
| | 3 | 98 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(scale, expected, limit)) |
| | 3 | 99 | | .BecauseOf(because, becauseArgs) |
| | 3 | 100 | | .FailWith("Expected fixed4x4 matrix scale magnitudes to be approximately {0} +/- {1}{reason}, but found {2}. |
| | | 101 | | |
| | 2 | 102 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 103 | | } |
| | | 104 | | |
| | | 105 | | public AndConstraint<Fixed4x4Assertions> HaveRotationApproximately( |
| | | 106 | | FixedQuaternion expected, |
| | | 107 | | Fixed64? tolerance = null, |
| | | 108 | | string because = "", |
| | | 109 | | params object[] becauseArgs) |
| | | 110 | | { |
| | 2 | 111 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | 2 | 112 | | FixedQuaternion rotation = Subject.Rotation; |
| | | 113 | | |
| | 2 | 114 | | CurrentAssertionChain |
| | 2 | 115 | | .ForCondition(FixedAssertionHelpers.RepresentsSameRotation(rotation, expected, limit)) |
| | 2 | 116 | | .BecauseOf(because, becauseArgs) |
| | 2 | 117 | | .FailWith("Expected fixed4x4 matrix rotation to be approximately {0} +/- {1}{reason}, but found {2}.", expec |
| | | 118 | | |
| | 1 | 119 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 120 | | } |
| | | 121 | | |
| | | 122 | | public AndConstraint<Fixed4x4Assertions> HaveNormalizedRotationBasis( |
| | | 123 | | Fixed64? tolerance = null, |
| | | 124 | | string because = "", |
| | | 125 | | params object[] becauseArgs) |
| | | 126 | | { |
| | 4 | 127 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 128 | | |
| | 4 | 129 | | CurrentAssertionChain |
| | 4 | 130 | | .ForCondition(FixedAssertionHelpers.HasUnitAxes(Subject, limit)) |
| | 4 | 131 | | .BecauseOf(because, becauseArgs) |
| | 4 | 132 | | .FailWith("Expected fixed4x4 matrix rotation basis to be normalized within +/- {0}{reason}, but found {1}.", |
| | | 133 | | |
| | 1 | 134 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 135 | | } |
| | | 136 | | } |