| | | 1 | | //======================================================================= |
| | | 2 | | // FixedAssertions.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 | | internal static class FixedAssertionHelpers |
| | | 15 | | { |
| | | 16 | | public static Fixed64 ResolveTolerance(Fixed64? tolerance) |
| | | 17 | | { |
| | | 18 | | return tolerance ?? Fixed64.Epsilon; |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | public static bool AreApproximatelyEqual(Fixed64 actual, Fixed64 expected, Fixed64 tolerance) |
| | | 22 | | { |
| | | 23 | | return (actual - expected).Abs() <= tolerance; |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | public static bool AreComponentApproximatelyEqual(Vector2d actual, Vector2d expected, Fixed64 tolerance) |
| | | 27 | | { |
| | | 28 | | return (actual.X - expected.X).Abs() <= tolerance |
| | | 29 | | && (actual.Y - expected.Y).Abs() <= tolerance; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | public static bool AreComponentApproximatelyEqual(Vector3d actual, Vector3d expected, Fixed64 tolerance) |
| | | 33 | | { |
| | | 34 | | return (actual.X - expected.X).Abs() <= tolerance |
| | | 35 | | && (actual.Y - expected.Y).Abs() <= tolerance |
| | | 36 | | && (actual.Z - expected.Z).Abs() <= tolerance; |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | public static bool AreComponentApproximatelyEqual(FixedQuaternion actual, FixedQuaternion expected, Fixed64 toleranc |
| | | 40 | | { |
| | | 41 | | return (actual.X - expected.X).Abs() <= tolerance |
| | | 42 | | && (actual.Y - expected.Y).Abs() <= tolerance |
| | | 43 | | && (actual.Z - expected.Z).Abs() <= tolerance |
| | | 44 | | && (actual.W - expected.W).Abs() <= tolerance; |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | public static bool AreComponentApproximatelyEqual(Fixed3x3 actual, Fixed3x3 expected, Fixed64 tolerance) |
| | | 48 | | { |
| | | 49 | | return (actual.M11 - expected.M11).Abs() <= tolerance |
| | | 50 | | && (actual.M12 - expected.M12).Abs() <= tolerance |
| | | 51 | | && (actual.M13 - expected.M13).Abs() <= tolerance |
| | | 52 | | && (actual.M21 - expected.M21).Abs() <= tolerance |
| | | 53 | | && (actual.M22 - expected.M22).Abs() <= tolerance |
| | | 54 | | && (actual.M23 - expected.M23).Abs() <= tolerance |
| | | 55 | | && (actual.M31 - expected.M31).Abs() <= tolerance |
| | | 56 | | && (actual.M32 - expected.M32).Abs() <= tolerance |
| | | 57 | | && (actual.M33 - expected.M33).Abs() <= tolerance; |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | public static bool AreComponentApproximatelyEqual(Fixed4x4 actual, Fixed4x4 expected, Fixed64 tolerance) |
| | | 61 | | { |
| | | 62 | | return (actual.M11 - expected.M11).Abs() <= tolerance |
| | | 63 | | && (actual.M12 - expected.M12).Abs() <= tolerance |
| | | 64 | | && (actual.M13 - expected.M13).Abs() <= tolerance |
| | | 65 | | && (actual.M14 - expected.M14).Abs() <= tolerance |
| | | 66 | | && (actual.M21 - expected.M21).Abs() <= tolerance |
| | | 67 | | && (actual.M22 - expected.M22).Abs() <= tolerance |
| | | 68 | | && (actual.M23 - expected.M23).Abs() <= tolerance |
| | | 69 | | && (actual.M24 - expected.M24).Abs() <= tolerance |
| | | 70 | | && (actual.M31 - expected.M31).Abs() <= tolerance |
| | | 71 | | && (actual.M32 - expected.M32).Abs() <= tolerance |
| | | 72 | | && (actual.M33 - expected.M33).Abs() <= tolerance |
| | | 73 | | && (actual.M34 - expected.M34).Abs() <= tolerance |
| | | 74 | | && (actual.M41 - expected.M41).Abs() <= tolerance |
| | | 75 | | && (actual.M42 - expected.M42).Abs() <= tolerance |
| | | 76 | | && (actual.M43 - expected.M43).Abs() <= tolerance |
| | | 77 | | && (actual.M44 - expected.M44).Abs() <= tolerance; |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | public static bool RepresentsSameRotation(FixedQuaternion actual, FixedQuaternion expected, Fixed64 tolerance) |
| | | 81 | | { |
| | | 82 | | FixedQuaternion normalizedActual = FixedQuaternion.GetNormalized(actual); |
| | | 83 | | FixedQuaternion normalizedExpected = FixedQuaternion.GetNormalized(expected); |
| | | 84 | | Fixed64 alignment = FixedMath.Abs(FixedQuaternion.Dot(normalizedActual, normalizedExpected)); |
| | | 85 | | return FixedMath.Abs(Fixed64.One - alignment) <= tolerance; |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | public static bool HasUnitAxes(Fixed3x3 matrix, Fixed64 tolerance) |
| | | 89 | | { |
| | | 90 | | return AreApproximatelyEqual(new Vector3d(matrix.M11, matrix.M12, matrix.M13).Magnitude, Fixed64.One, tolerance) |
| | | 91 | | && AreApproximatelyEqual(new Vector3d(matrix.M21, matrix.M22, matrix.M23).Magnitude, Fixed64.One, tolerance) |
| | | 92 | | && AreApproximatelyEqual(new Vector3d(matrix.M31, matrix.M32, matrix.M33).Magnitude, Fixed64.One, tolerance) |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | public static bool HasUnitAxes(Fixed4x4 matrix, Fixed64 tolerance) |
| | | 96 | | { |
| | | 97 | | return AreApproximatelyEqual(new Vector3d(matrix.M11, matrix.M12, matrix.M13).Magnitude, Fixed64.One, tolerance) |
| | | 98 | | && AreApproximatelyEqual(new Vector3d(matrix.M21, matrix.M22, matrix.M23).Magnitude, Fixed64.One, tolerance) |
| | | 99 | | && AreApproximatelyEqual(new Vector3d(matrix.M31, matrix.M32, matrix.M33).Magnitude, Fixed64.One, tolerance) |
| | | 100 | | } |
| | | 101 | | } |
| | | 102 | | |
| | | 103 | | public abstract class FixedStructAssertions<TSubject, TAssertions> |
| | | 104 | | where TAssertions : FixedStructAssertions<TSubject, TAssertions> |
| | | 105 | | { |
| | 77 | 106 | | protected FixedStructAssertions(TSubject value) |
| | | 107 | | { |
| | 77 | 108 | | Subject = value; |
| | 77 | 109 | | CurrentAssertionChain = AssertionChain.GetOrCreate(); |
| | 77 | 110 | | } |
| | | 111 | | |
| | | 112 | | protected TSubject Subject { get; } |
| | | 113 | | |
| | | 114 | | protected AssertionChain CurrentAssertionChain { get; } |
| | | 115 | | |
| | | 116 | | protected abstract string Identifier { get; } |
| | | 117 | | |
| | | 118 | | public AndConstraint<TAssertions> Be(TSubject expected, string because = "", params object[] becauseArgs) |
| | | 119 | | { |
| | 8 | 120 | | CurrentAssertionChain |
| | 8 | 121 | | .ForCondition(Equals(Subject, expected)) |
| | 8 | 122 | | .BecauseOf(because, becauseArgs) |
| | 8 | 123 | | .FailWith("Expected " + Identifier + " to equal {0}{reason}, but found {1}.", expected, Subject); |
| | | 124 | | |
| | 4 | 125 | | return new AndConstraint<TAssertions>((TAssertions)this); |
| | | 126 | | } |
| | | 127 | | |
| | | 128 | | public AndConstraint<TAssertions> NotBe(TSubject unexpected, string because = "", params object[] becauseArgs) |
| | | 129 | | { |
| | 6 | 130 | | CurrentAssertionChain |
| | 6 | 131 | | .ForCondition(!Equals(Subject, unexpected)) |
| | 6 | 132 | | .BecauseOf(because, becauseArgs) |
| | 6 | 133 | | .FailWith("Expected " + Identifier + " not to equal {0}{reason}, but found {1}.", unexpected, Subject); |
| | | 134 | | |
| | 3 | 135 | | return new AndConstraint<TAssertions>((TAssertions)this); |
| | | 136 | | } |
| | | 137 | | } |
| | | 138 | | |
| | | 139 | | public sealed class Fixed64Assertions : ComparableTypeAssertions<Fixed64, Fixed64Assertions> |
| | | 140 | | { |
| | | 141 | | public Fixed64Assertions(Fixed64 value) : base(value, AssertionChain.GetOrCreate()) { } |
| | | 142 | | |
| | | 143 | | protected override string Identifier => "fixed64"; |
| | | 144 | | |
| | | 145 | | public AndConstraint<Fixed64Assertions> BeApproximately( |
| | | 146 | | Fixed64 expected, |
| | | 147 | | Fixed64? tolerance = null, |
| | | 148 | | string because = "", |
| | | 149 | | params object[] becauseArgs) |
| | | 150 | | { |
| | | 151 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 152 | | Fixed64 actual = (Fixed64)Subject; |
| | | 153 | | |
| | | 154 | | CurrentAssertionChain |
| | | 155 | | .ForCondition(FixedAssertionHelpers.AreApproximatelyEqual(actual, expected, limit)) |
| | | 156 | | .BecauseOf(because, becauseArgs) |
| | | 157 | | .FailWith("Expected fixed64 to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limit, actua |
| | | 158 | | |
| | | 159 | | return new AndConstraint<Fixed64Assertions>(this); |
| | | 160 | | } |
| | | 161 | | |
| | | 162 | | public AndConstraint<Fixed64Assertions> NotBeApproximately( |
| | | 163 | | Fixed64 expected, |
| | | 164 | | Fixed64? tolerance = null, |
| | | 165 | | string because = "", |
| | | 166 | | params object[] becauseArgs) |
| | | 167 | | { |
| | | 168 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 169 | | Fixed64 actual = (Fixed64)Subject; |
| | | 170 | | |
| | | 171 | | CurrentAssertionChain |
| | | 172 | | .ForCondition((actual - expected).Abs() > limit) |
| | | 173 | | .BecauseOf(because, becauseArgs) |
| | | 174 | | .FailWith("Expected fixed64 not to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limit, a |
| | | 175 | | |
| | | 176 | | return new AndConstraint<Fixed64Assertions>(this); |
| | | 177 | | } |
| | | 178 | | |
| | | 179 | | public AndConstraint<Fixed64Assertions> HaveRawValue( |
| | | 180 | | long expected, |
| | | 181 | | string because = "", |
| | | 182 | | params object[] becauseArgs) |
| | | 183 | | { |
| | | 184 | | Fixed64 actual = (Fixed64)Subject; |
| | | 185 | | |
| | | 186 | | CurrentAssertionChain |
| | | 187 | | .ForCondition(actual.m_rawValue == expected) |
| | | 188 | | .BecauseOf(because, becauseArgs) |
| | | 189 | | .FailWith("Expected fixed64 to have raw value {0}{reason}, but found {1}.", expected, actual.m_rawValue); |
| | | 190 | | |
| | | 191 | | return new AndConstraint<Fixed64Assertions>(this); |
| | | 192 | | } |
| | | 193 | | } |
| | | 194 | | |
| | | 195 | | public static class Fixed64AssertionsExtensions |
| | | 196 | | { |
| | | 197 | | public static Fixed64Assertions Should(this Fixed64 actualValue) |
| | | 198 | | { |
| | | 199 | | return new Fixed64Assertions(actualValue); |
| | | 200 | | } |
| | | 201 | | } |
| | | 202 | | |
| | | 203 | | public sealed class Vector2dAssertions : ComparableTypeAssertions<Vector2d, Vector2dAssertions> |
| | | 204 | | { |
| | | 205 | | public Vector2dAssertions(Vector2d value) : base(value, AssertionChain.GetOrCreate()) { } |
| | | 206 | | |
| | | 207 | | protected override string Identifier => "vector2d"; |
| | | 208 | | |
| | | 209 | | public AndConstraint<Vector2dAssertions> BeApproximately( |
| | | 210 | | Vector2d expected, |
| | | 211 | | Fixed64? tolerance = null, |
| | | 212 | | string because = "", |
| | | 213 | | params object[] becauseArgs) |
| | | 214 | | { |
| | | 215 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 216 | | Vector2d actual = (Vector2d)Subject; |
| | | 217 | | |
| | | 218 | | CurrentAssertionChain |
| | | 219 | | .ForCondition((actual - expected).Magnitude <= limit) |
| | | 220 | | .BecauseOf(because, becauseArgs) |
| | | 221 | | .FailWith("Expected vector2d to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limit, actu |
| | | 222 | | |
| | | 223 | | return new AndConstraint<Vector2dAssertions>(this); |
| | | 224 | | } |
| | | 225 | | |
| | | 226 | | public AndConstraint<Vector2dAssertions> NotBeApproximately( |
| | | 227 | | Vector2d expected, |
| | | 228 | | Fixed64? tolerance = null, |
| | | 229 | | string because = "", |
| | | 230 | | params object[] becauseArgs) |
| | | 231 | | { |
| | | 232 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 233 | | Vector2d actual = (Vector2d)Subject; |
| | | 234 | | |
| | | 235 | | CurrentAssertionChain |
| | | 236 | | .ForCondition((actual - expected).Magnitude > limit) |
| | | 237 | | .BecauseOf(because, becauseArgs) |
| | | 238 | | .FailWith("Expected vector2d not to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limit, |
| | | 239 | | |
| | | 240 | | return new AndConstraint<Vector2dAssertions>(this); |
| | | 241 | | } |
| | | 242 | | |
| | | 243 | | public AndConstraint<Vector2dAssertions> HaveComponentApproximately( |
| | | 244 | | Vector2d expected, |
| | | 245 | | Fixed64? tolerance = null, |
| | | 246 | | string because = "", |
| | | 247 | | params object[] becauseArgs) |
| | | 248 | | { |
| | | 249 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 250 | | Vector2d actual = (Vector2d)Subject; |
| | | 251 | | |
| | | 252 | | CurrentAssertionChain |
| | | 253 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(actual, expected, limit)) |
| | | 254 | | .BecauseOf(because, becauseArgs) |
| | | 255 | | .FailWith("Expected vector2d components to be approximately {0} +/- {1}{reason}, but found {2}.", expected, |
| | | 256 | | |
| | | 257 | | return new AndConstraint<Vector2dAssertions>(this); |
| | | 258 | | } |
| | | 259 | | |
| | | 260 | | public AndConstraint<Vector2dAssertions> HaveMagnitudeApproximately( |
| | | 261 | | Fixed64 expected, |
| | | 262 | | Fixed64? tolerance = null, |
| | | 263 | | string because = "", |
| | | 264 | | params object[] becauseArgs) |
| | | 265 | | { |
| | | 266 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 267 | | Vector2d actual = (Vector2d)Subject; |
| | | 268 | | |
| | | 269 | | CurrentAssertionChain |
| | | 270 | | .ForCondition(FixedAssertionHelpers.AreApproximatelyEqual(actual.Magnitude, expected, limit)) |
| | | 271 | | .BecauseOf(because, becauseArgs) |
| | | 272 | | .FailWith("Expected vector2d magnitude to be approximately {0} +/- {1}{reason}, but found {2}.", expected, l |
| | | 273 | | |
| | | 274 | | return new AndConstraint<Vector2dAssertions>(this); |
| | | 275 | | } |
| | | 276 | | |
| | | 277 | | public AndConstraint<Vector2dAssertions> BeNormalized( |
| | | 278 | | Fixed64? tolerance = null, |
| | | 279 | | string because = "", |
| | | 280 | | params object[] becauseArgs) |
| | | 281 | | { |
| | | 282 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 283 | | Vector2d actual = (Vector2d)Subject; |
| | | 284 | | |
| | | 285 | | CurrentAssertionChain |
| | | 286 | | .ForCondition(FixedAssertionHelpers.AreApproximatelyEqual(actual.Magnitude, Fixed64.One, limit)) |
| | | 287 | | .BecauseOf(because, becauseArgs) |
| | | 288 | | .FailWith("Expected vector2d to be normalized within +/- {0}{reason}, but found magnitude {1}.", limit, actu |
| | | 289 | | |
| | | 290 | | return new AndConstraint<Vector2dAssertions>(this); |
| | | 291 | | } |
| | | 292 | | } |
| | | 293 | | |
| | | 294 | | public static class Vector2dAssertionsExtensions |
| | | 295 | | { |
| | | 296 | | public static Vector2dAssertions Should(this Vector2d actualValue) |
| | | 297 | | { |
| | | 298 | | return new Vector2dAssertions(actualValue); |
| | | 299 | | } |
| | | 300 | | } |
| | | 301 | | |
| | | 302 | | public sealed class Vector3dAssertions : ComparableTypeAssertions<Vector3d, Vector3dAssertions> |
| | | 303 | | { |
| | | 304 | | public Vector3dAssertions(Vector3d value) : base(value, AssertionChain.GetOrCreate()) { } |
| | | 305 | | |
| | | 306 | | protected override string Identifier => "vector3d"; |
| | | 307 | | |
| | | 308 | | public AndConstraint<Vector3dAssertions> BeApproximately( |
| | | 309 | | Vector3d expected, |
| | | 310 | | Fixed64? tolerance = null, |
| | | 311 | | string because = "", |
| | | 312 | | params object[] becauseArgs) |
| | | 313 | | { |
| | | 314 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 315 | | Vector3d actual = (Vector3d)Subject; |
| | | 316 | | |
| | | 317 | | CurrentAssertionChain |
| | | 318 | | .ForCondition((actual - expected).Magnitude <= limit) |
| | | 319 | | .BecauseOf(because, becauseArgs) |
| | | 320 | | .FailWith("Expected vector3d to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limit, actu |
| | | 321 | | |
| | | 322 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 323 | | } |
| | | 324 | | |
| | | 325 | | public AndConstraint<Vector3dAssertions> NotBeApproximately( |
| | | 326 | | Vector3d expected, |
| | | 327 | | Fixed64? tolerance = null, |
| | | 328 | | string because = "", |
| | | 329 | | params object[] becauseArgs) |
| | | 330 | | { |
| | | 331 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 332 | | Vector3d actual = (Vector3d)Subject; |
| | | 333 | | |
| | | 334 | | CurrentAssertionChain |
| | | 335 | | .ForCondition((actual - expected).Magnitude > limit) |
| | | 336 | | .BecauseOf(because, becauseArgs) |
| | | 337 | | .FailWith("Expected vector3d not to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limit, |
| | | 338 | | |
| | | 339 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 340 | | } |
| | | 341 | | |
| | | 342 | | public AndConstraint<Vector3dAssertions> HaveComponentApproximately( |
| | | 343 | | Vector3d expected, |
| | | 344 | | Fixed64? tolerance = null, |
| | | 345 | | string because = "", |
| | | 346 | | params object[] becauseArgs) |
| | | 347 | | { |
| | | 348 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 349 | | Vector3d actual = (Vector3d)Subject; |
| | | 350 | | |
| | | 351 | | CurrentAssertionChain |
| | | 352 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(actual, expected, limit)) |
| | | 353 | | .BecauseOf(because, becauseArgs) |
| | | 354 | | .FailWith("Expected vector3d components to be approximately {0} +/- {1}{reason}, but found {2}.", expected, |
| | | 355 | | |
| | | 356 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 357 | | } |
| | | 358 | | |
| | | 359 | | public AndConstraint<Vector3dAssertions> HaveMagnitudeApproximately( |
| | | 360 | | Fixed64 expected, |
| | | 361 | | Fixed64? tolerance = null, |
| | | 362 | | string because = "", |
| | | 363 | | params object[] becauseArgs) |
| | | 364 | | { |
| | | 365 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 366 | | Vector3d actual = (Vector3d)Subject; |
| | | 367 | | |
| | | 368 | | CurrentAssertionChain |
| | | 369 | | .ForCondition(FixedAssertionHelpers.AreApproximatelyEqual(actual.Magnitude, expected, limit)) |
| | | 370 | | .BecauseOf(because, becauseArgs) |
| | | 371 | | .FailWith("Expected vector3d magnitude to be approximately {0} +/- {1}{reason}, but found {2}.", expected, l |
| | | 372 | | |
| | | 373 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 374 | | } |
| | | 375 | | |
| | | 376 | | public AndConstraint<Vector3dAssertions> BeNormalized( |
| | | 377 | | Fixed64? tolerance = null, |
| | | 378 | | string because = "", |
| | | 379 | | params object[] becauseArgs) |
| | | 380 | | { |
| | | 381 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 382 | | Vector3d actual = (Vector3d)Subject; |
| | | 383 | | |
| | | 384 | | CurrentAssertionChain |
| | | 385 | | .ForCondition(FixedAssertionHelpers.AreApproximatelyEqual(actual.Magnitude, Fixed64.One, limit)) |
| | | 386 | | .BecauseOf(because, becauseArgs) |
| | | 387 | | .FailWith("Expected vector3d to be normalized within +/- {0}{reason}, but found magnitude {1}.", limit, actu |
| | | 388 | | |
| | | 389 | | return new AndConstraint<Vector3dAssertions>(this); |
| | | 390 | | } |
| | | 391 | | } |
| | | 392 | | |
| | | 393 | | public static class Vector3dAssertionsExtensions |
| | | 394 | | { |
| | | 395 | | public static Vector3dAssertions Should(this Vector3d actualValue) |
| | | 396 | | { |
| | | 397 | | return new Vector3dAssertions(actualValue); |
| | | 398 | | } |
| | | 399 | | } |
| | | 400 | | |
| | | 401 | | public sealed class FixedQuaternionAssertions : FixedStructAssertions<FixedQuaternion, FixedQuaternionAssertions> |
| | | 402 | | { |
| | | 403 | | public FixedQuaternionAssertions(FixedQuaternion value) : base(value) { } |
| | | 404 | | |
| | | 405 | | protected override string Identifier => "fixed quaternion"; |
| | | 406 | | |
| | | 407 | | public AndConstraint<FixedQuaternionAssertions> BeApproximately( |
| | | 408 | | FixedQuaternion expected, |
| | | 409 | | Fixed64? tolerance = null, |
| | | 410 | | string because = "", |
| | | 411 | | params object[] becauseArgs) |
| | | 412 | | { |
| | | 413 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 414 | | |
| | | 415 | | CurrentAssertionChain |
| | | 416 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(Subject, expected, limit)) |
| | | 417 | | .BecauseOf(because, becauseArgs) |
| | | 418 | | .FailWith("Expected fixed quaternion components to be approximately {0} +/- {1}{reason}, but found {2}.", ex |
| | | 419 | | |
| | | 420 | | return new AndConstraint<FixedQuaternionAssertions>(this); |
| | | 421 | | } |
| | | 422 | | |
| | | 423 | | public AndConstraint<FixedQuaternionAssertions> NotBeApproximately( |
| | | 424 | | FixedQuaternion expected, |
| | | 425 | | Fixed64? tolerance = null, |
| | | 426 | | string because = "", |
| | | 427 | | params object[] becauseArgs) |
| | | 428 | | { |
| | | 429 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 430 | | |
| | | 431 | | CurrentAssertionChain |
| | | 432 | | .ForCondition(!FixedAssertionHelpers.AreComponentApproximatelyEqual(Subject, expected, limit)) |
| | | 433 | | .BecauseOf(because, becauseArgs) |
| | | 434 | | .FailWith("Expected fixed quaternion not to be approximately {0} +/- {1}{reason}, but found {2}.", expected, |
| | | 435 | | |
| | | 436 | | return new AndConstraint<FixedQuaternionAssertions>(this); |
| | | 437 | | } |
| | | 438 | | |
| | | 439 | | public AndConstraint<FixedQuaternionAssertions> HaveComponentApproximately( |
| | | 440 | | FixedQuaternion expected, |
| | | 441 | | Fixed64? tolerance = null, |
| | | 442 | | string because = "", |
| | | 443 | | params object[] becauseArgs) |
| | | 444 | | { |
| | | 445 | | return BeApproximately(expected, tolerance, because, becauseArgs); |
| | | 446 | | } |
| | | 447 | | |
| | | 448 | | public AndConstraint<FixedQuaternionAssertions> RepresentSameRotationAs( |
| | | 449 | | FixedQuaternion expected, |
| | | 450 | | Fixed64? tolerance = null, |
| | | 451 | | string because = "", |
| | | 452 | | params object[] becauseArgs) |
| | | 453 | | { |
| | | 454 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 455 | | |
| | | 456 | | CurrentAssertionChain |
| | | 457 | | .ForCondition(FixedAssertionHelpers.RepresentsSameRotation(Subject, expected, limit)) |
| | | 458 | | .BecauseOf(because, becauseArgs) |
| | | 459 | | .FailWith("Expected fixed quaternion to represent the same rotation as {0} +/- {1}{reason}, but found {2}.", |
| | | 460 | | |
| | | 461 | | return new AndConstraint<FixedQuaternionAssertions>(this); |
| | | 462 | | } |
| | | 463 | | |
| | | 464 | | public AndConstraint<FixedQuaternionAssertions> BeIdentity( |
| | | 465 | | string because = "", |
| | | 466 | | params object[] becauseArgs) |
| | | 467 | | { |
| | | 468 | | return Be(FixedQuaternion.Identity, because, becauseArgs); |
| | | 469 | | } |
| | | 470 | | |
| | | 471 | | public AndConstraint<FixedQuaternionAssertions> BeNormalized( |
| | | 472 | | Fixed64? tolerance = null, |
| | | 473 | | string because = "", |
| | | 474 | | params object[] becauseArgs) |
| | | 475 | | { |
| | | 476 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 477 | | Fixed64 magnitude = FixedQuaternion.GetMagnitude(Subject); |
| | | 478 | | |
| | | 479 | | CurrentAssertionChain |
| | | 480 | | .ForCondition(FixedAssertionHelpers.AreApproximatelyEqual(magnitude, Fixed64.One, limit)) |
| | | 481 | | .BecauseOf(because, becauseArgs) |
| | | 482 | | .FailWith("Expected fixed quaternion to be normalized within +/- {0}{reason}, but found magnitude {1}.", lim |
| | | 483 | | |
| | | 484 | | return new AndConstraint<FixedQuaternionAssertions>(this); |
| | | 485 | | } |
| | | 486 | | } |
| | | 487 | | |
| | | 488 | | public static class FixedQuaternionAssertionsExtensions |
| | | 489 | | { |
| | | 490 | | public static FixedQuaternionAssertions Should(this FixedQuaternion actualValue) |
| | | 491 | | { |
| | | 492 | | return new FixedQuaternionAssertions(actualValue); |
| | | 493 | | } |
| | | 494 | | } |
| | | 495 | | |
| | | 496 | | public sealed class Fixed3x3Assertions : FixedStructAssertions<Fixed3x3, Fixed3x3Assertions> |
| | | 497 | | { |
| | | 498 | | public Fixed3x3Assertions(Fixed3x3 value) : base(value) { } |
| | | 499 | | |
| | | 500 | | protected override string Identifier => "fixed3x3 matrix"; |
| | | 501 | | |
| | | 502 | | public AndConstraint<Fixed3x3Assertions> BeApproximately( |
| | | 503 | | Fixed3x3 expected, |
| | | 504 | | Fixed64? tolerance = null, |
| | | 505 | | string because = "", |
| | | 506 | | params object[] becauseArgs) |
| | | 507 | | { |
| | | 508 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 509 | | |
| | | 510 | | CurrentAssertionChain |
| | | 511 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(Subject, expected, limit)) |
| | | 512 | | .BecauseOf(because, becauseArgs) |
| | | 513 | | .FailWith("Expected fixed3x3 matrix to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limi |
| | | 514 | | |
| | | 515 | | return new AndConstraint<Fixed3x3Assertions>(this); |
| | | 516 | | } |
| | | 517 | | |
| | | 518 | | public AndConstraint<Fixed3x3Assertions> NotBeApproximately( |
| | | 519 | | Fixed3x3 expected, |
| | | 520 | | Fixed64? tolerance = null, |
| | | 521 | | string because = "", |
| | | 522 | | params object[] becauseArgs) |
| | | 523 | | { |
| | | 524 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 525 | | |
| | | 526 | | CurrentAssertionChain |
| | | 527 | | .ForCondition(!FixedAssertionHelpers.AreComponentApproximatelyEqual(Subject, expected, limit)) |
| | | 528 | | .BecauseOf(because, becauseArgs) |
| | | 529 | | .FailWith("Expected fixed3x3 matrix not to be approximately {0} +/- {1}{reason}, but found {2}.", expected, |
| | | 530 | | |
| | | 531 | | return new AndConstraint<Fixed3x3Assertions>(this); |
| | | 532 | | } |
| | | 533 | | |
| | | 534 | | public AndConstraint<Fixed3x3Assertions> BeIdentity( |
| | | 535 | | string because = "", |
| | | 536 | | params object[] becauseArgs) |
| | | 537 | | { |
| | | 538 | | return Be(Fixed3x3.Identity, because, becauseArgs); |
| | | 539 | | } |
| | | 540 | | |
| | | 541 | | public AndConstraint<Fixed3x3Assertions> HaveScaleApproximately( |
| | | 542 | | Vector3d expected, |
| | | 543 | | Fixed64? tolerance = null, |
| | | 544 | | string because = "", |
| | | 545 | | params object[] becauseArgs) |
| | | 546 | | { |
| | | 547 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 548 | | Vector3d scale = Fixed3x3.ExtractScale(Subject); |
| | | 549 | | |
| | | 550 | | CurrentAssertionChain |
| | | 551 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(scale, expected, limit)) |
| | | 552 | | .BecauseOf(because, becauseArgs) |
| | | 553 | | .FailWith("Expected fixed3x3 matrix scale to be approximately {0} +/- {1}{reason}, but found {2}.", expected |
| | | 554 | | |
| | | 555 | | return new AndConstraint<Fixed3x3Assertions>(this); |
| | | 556 | | } |
| | | 557 | | |
| | | 558 | | public AndConstraint<Fixed3x3Assertions> HaveNormalizedAxes( |
| | | 559 | | Fixed64? tolerance = null, |
| | | 560 | | string because = "", |
| | | 561 | | params object[] becauseArgs) |
| | | 562 | | { |
| | | 563 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 564 | | |
| | | 565 | | CurrentAssertionChain |
| | | 566 | | .ForCondition(FixedAssertionHelpers.HasUnitAxes(Subject, limit)) |
| | | 567 | | .BecauseOf(because, becauseArgs) |
| | | 568 | | .FailWith("Expected fixed3x3 matrix axes to be normalized within +/- {0}{reason}, but found {1}.", limit, Su |
| | | 569 | | |
| | | 570 | | return new AndConstraint<Fixed3x3Assertions>(this); |
| | | 571 | | } |
| | | 572 | | } |
| | | 573 | | |
| | | 574 | | public static class Fixed3x3AssertionsExtensions |
| | | 575 | | { |
| | | 576 | | public static Fixed3x3Assertions Should(this Fixed3x3 actualValue) |
| | | 577 | | { |
| | | 578 | | return new Fixed3x3Assertions(actualValue); |
| | | 579 | | } |
| | | 580 | | } |
| | | 581 | | |
| | | 582 | | public sealed class Fixed4x4Assertions : FixedStructAssertions<Fixed4x4, Fixed4x4Assertions> |
| | | 583 | | { |
| | | 584 | | public Fixed4x4Assertions(Fixed4x4 value) : base(value) { } |
| | | 585 | | |
| | | 586 | | protected override string Identifier => "fixed4x4 matrix"; |
| | | 587 | | |
| | | 588 | | public AndConstraint<Fixed4x4Assertions> BeApproximately( |
| | | 589 | | Fixed4x4 expected, |
| | | 590 | | Fixed64? tolerance = null, |
| | | 591 | | string because = "", |
| | | 592 | | params object[] becauseArgs) |
| | | 593 | | { |
| | | 594 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 595 | | |
| | | 596 | | CurrentAssertionChain |
| | | 597 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(Subject, expected, limit)) |
| | | 598 | | .BecauseOf(because, becauseArgs) |
| | | 599 | | .FailWith("Expected fixed4x4 matrix to be approximately {0} +/- {1}{reason}, but found {2}.", expected, limi |
| | | 600 | | |
| | | 601 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 602 | | } |
| | | 603 | | |
| | | 604 | | public AndConstraint<Fixed4x4Assertions> NotBeApproximately( |
| | | 605 | | Fixed4x4 expected, |
| | | 606 | | Fixed64? tolerance = null, |
| | | 607 | | string because = "", |
| | | 608 | | params object[] becauseArgs) |
| | | 609 | | { |
| | | 610 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 611 | | |
| | | 612 | | CurrentAssertionChain |
| | | 613 | | .ForCondition(!FixedAssertionHelpers.AreComponentApproximatelyEqual(Subject, expected, limit)) |
| | | 614 | | .BecauseOf(because, becauseArgs) |
| | | 615 | | .FailWith("Expected fixed4x4 matrix not to be approximately {0} +/- {1}{reason}, but found {2}.", expected, |
| | | 616 | | |
| | | 617 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 618 | | } |
| | | 619 | | |
| | | 620 | | public AndConstraint<Fixed4x4Assertions> BeIdentity( |
| | | 621 | | string because = "", |
| | | 622 | | params object[] becauseArgs) |
| | | 623 | | { |
| | | 624 | | return Be(Fixed4x4.Identity, because, becauseArgs); |
| | | 625 | | } |
| | | 626 | | |
| | | 627 | | public AndConstraint<Fixed4x4Assertions> BeAffine( |
| | | 628 | | string because = "", |
| | | 629 | | params object[] becauseArgs) |
| | | 630 | | { |
| | | 631 | | CurrentAssertionChain |
| | | 632 | | .ForCondition(Subject.IsAffine) |
| | | 633 | | .BecauseOf(because, becauseArgs) |
| | | 634 | | .FailWith("Expected fixed4x4 matrix to be affine{reason}, but found {0}.", Subject); |
| | | 635 | | |
| | | 636 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 637 | | } |
| | | 638 | | |
| | | 639 | | public AndConstraint<Fixed4x4Assertions> HaveTranslationApproximately( |
| | | 640 | | Vector3d expected, |
| | | 641 | | Fixed64? tolerance = null, |
| | | 642 | | string because = "", |
| | | 643 | | params object[] becauseArgs) |
| | | 644 | | { |
| | | 645 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 646 | | Vector3d translation = Subject.Translation; |
| | | 647 | | |
| | | 648 | | CurrentAssertionChain |
| | | 649 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(translation, expected, limit)) |
| | | 650 | | .BecauseOf(because, becauseArgs) |
| | | 651 | | .FailWith("Expected fixed4x4 matrix translation to be approximately {0} +/- {1}{reason}, but found {2}.", ex |
| | | 652 | | |
| | | 653 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 654 | | } |
| | | 655 | | |
| | | 656 | | public AndConstraint<Fixed4x4Assertions> HaveScaleApproximately( |
| | | 657 | | Vector3d expected, |
| | | 658 | | Fixed64? tolerance = null, |
| | | 659 | | string because = "", |
| | | 660 | | params object[] becauseArgs) |
| | | 661 | | { |
| | | 662 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 663 | | Vector3d scale = Subject.Scale; |
| | | 664 | | |
| | | 665 | | CurrentAssertionChain |
| | | 666 | | .ForCondition(FixedAssertionHelpers.AreComponentApproximatelyEqual(scale, expected, limit)) |
| | | 667 | | .BecauseOf(because, becauseArgs) |
| | | 668 | | .FailWith("Expected fixed4x4 matrix scale to be approximately {0} +/- {1}{reason}, but found {2}.", expected |
| | | 669 | | |
| | | 670 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 671 | | } |
| | | 672 | | |
| | | 673 | | public AndConstraint<Fixed4x4Assertions> HaveRotationApproximately( |
| | | 674 | | FixedQuaternion expected, |
| | | 675 | | Fixed64? tolerance = null, |
| | | 676 | | string because = "", |
| | | 677 | | params object[] becauseArgs) |
| | | 678 | | { |
| | | 679 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 680 | | FixedQuaternion rotation = Subject.Rotation; |
| | | 681 | | |
| | | 682 | | CurrentAssertionChain |
| | | 683 | | .ForCondition(FixedAssertionHelpers.RepresentsSameRotation(rotation, expected, limit)) |
| | | 684 | | .BecauseOf(because, becauseArgs) |
| | | 685 | | .FailWith("Expected fixed4x4 matrix rotation to be approximately {0} +/- {1}{reason}, but found {2}.", expec |
| | | 686 | | |
| | | 687 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 688 | | } |
| | | 689 | | |
| | | 690 | | public AndConstraint<Fixed4x4Assertions> HaveNormalizedRotationBasis( |
| | | 691 | | Fixed64? tolerance = null, |
| | | 692 | | string because = "", |
| | | 693 | | params object[] becauseArgs) |
| | | 694 | | { |
| | | 695 | | Fixed64 limit = FixedAssertionHelpers.ResolveTolerance(tolerance); |
| | | 696 | | |
| | | 697 | | CurrentAssertionChain |
| | | 698 | | .ForCondition(FixedAssertionHelpers.HasUnitAxes(Subject, limit)) |
| | | 699 | | .BecauseOf(because, becauseArgs) |
| | | 700 | | .FailWith("Expected fixed4x4 matrix rotation basis to be normalized within +/- {0}{reason}, but found {1}.", |
| | | 701 | | |
| | | 702 | | return new AndConstraint<Fixed4x4Assertions>(this); |
| | | 703 | | } |
| | | 704 | | } |
| | | 705 | | |
| | | 706 | | public static class Fixed4x4AssertionsExtensions |
| | | 707 | | { |
| | | 708 | | public static Fixed4x4Assertions Should(this Fixed4x4 actualValue) |
| | | 709 | | { |
| | | 710 | | return new Fixed4x4Assertions(actualValue); |
| | | 711 | | } |
| | | 712 | | } |