12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System;
- using OpenMetaverse;
- using NUnit.Framework;
- using NUnit.Framework.Constraints;
- namespace OpenSim.Tests.Common
- {
- public class QuaternionToleranceConstraint : ANumericalToleranceConstraint
- {
- private Quaternion _baseValue;
- private Quaternion _valueToBeTested;
- public QuaternionToleranceConstraint(Quaternion baseValue, double tolerance) : base(tolerance)
- {
- _baseValue = baseValue;
- }
-
-
-
-
-
-
-
- public override bool Matches(object valueToBeTested)
- {
- if (valueToBeTested == null)
- {
- throw new ArgumentException("Constraint cannot be used upon null values.");
- }
- if (valueToBeTested.GetType() != typeof (Quaternion))
- {
- throw new ArgumentException("Constraint cannot be used upon non quaternion values.");
- }
- _valueToBeTested = (Quaternion)valueToBeTested;
- return (IsWithinDoubleConstraint(_valueToBeTested.X, _baseValue.X) &&
- IsWithinDoubleConstraint(_valueToBeTested.Y, _baseValue.Y) &&
- IsWithinDoubleConstraint(_valueToBeTested.Z, _baseValue.Z) &&
- IsWithinDoubleConstraint(_valueToBeTested.W, _baseValue.W));
- }
- public override void WriteDescriptionTo(MessageWriter writer)
- {
- writer.WriteExpectedValue(
- string.Format("A value {0} within tolerance of plus or minus {1}", _baseValue, _tolerance));
- }
- public override void WriteActualValueTo(MessageWriter writer)
- {
- writer.WriteActualValue(_valueToBeTested);
- }
- }
- }
|