Class QuaternionEqualityComparer
Use this utility to compare two Quaternion objects for equality with NUnit assertion constraints. Use the static instance QuaternionEqualityComparer.Instance to have the default calculation error value set to 0.00001f. For any other custom error value, use the one argument constructor.
Implements
Inherited Members
Namespace: UnityEngine.TestTools.Utils
Assembly: UnityEngine.TestRunner.dll
Syntax
public class QuaternionEqualityComparer : IEqualityComparer<Quaternion>
Constructors
QuaternionEqualityComparer(float)
Creates an instance of the comparer with a custom allowed error value.
Declaration
public QuaternionEqualityComparer(float allowedError)
Parameters
Type | Name | Description |
---|---|---|
float | allowedError | Describes the custom allowed error value |
Properties
Instance
A comparer instance with the default error value 0.00001f.
Declaration
public static QuaternionEqualityComparer Instance { get; }
Property Value
Type | Description |
---|---|
QuaternionEqualityComparer |
Methods
Equals(Quaternion, Quaternion)
Compares the actual and expected Quaternion objects for equality using the Dot method.
Declaration
public bool Equals(Quaternion expected, Quaternion actual)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | expected | Expected Quaternion value used for comparison |
Quaternion | actual | Actual Quaternion value to test |
Returns
Type | Description |
---|---|
bool | True if the quaternion are equals, false otherwise. |
Examples
The following example shows how to verify if two Quaternion are equals
[TestFixture]
public class QuaternionTest
{
[Test]
public void VerifyThat_TwoQuaternionsAreEqual()
{
var actual = new Quaternion(10f, 0f, 0f, 0f);
var expected = new Quaternion(1f, 10f, 0f, 0f);
var comparer = new QuaternionEqualityComparer(10e-6f);
Assert.That(actual, Is.EqualTo(expected).Using(comparer));
//Using default error 0.00001f
actual = new Quaternion(10f, 0f, 0.1f, 0f);
expected = new Quaternion(1f, 10f, 0.1f, 0f);
Assert.That(actual, Is.EqualTo(expected).Using(QuaternionEqualityComparer.Instance));
}
}
GetHashCode(Quaternion)
Serves as the default hash function.
Declaration
public int GetHashCode(Quaternion quaternion)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | quaternion | A not null Quaternion |
Returns
Type | Description |
---|---|
int | Returns 0 |