/// <summary>Ensures that two unified vectors are nearly equal to each other</summary> /// <param name="expected">Expected unified vector</param> /// <param name="actual">Actual unified vector</param> /// <param name="deltaUlps"> /// Allowed deviation in representable floating point values for each of the /// unified vector's fields /// </param> public static void AreAlmostEqual(UniVector expected, UniVector actual, int deltaUlps) { if (!areAlmostEqual(expected, actual, deltaUlps)) { Assert.AreEqual(expected, actual); } }
public void TestGetHashCode() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector equivalentVector = new UniVector(firstTestScalar, secondTestScalar); Assert.AreEqual(testVector.GetHashCode(), equivalentVector.GetHashCode()); }
public void TestConstructor() { UniVector testVector = new UniVector(12.34f, 45.67f); Assert.AreEqual(0.0f, testVector.X.Fraction); Assert.AreEqual(12.34f, testVector.X.Offset); Assert.AreEqual(0.0f, testVector.Y.Fraction); Assert.AreEqual(45.67f, testVector.Y.Offset); }
public void TestEqualsWithDowncast() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector equivalentVector = new UniVector(firstTestScalar, secondTestScalar); UniVector differingVector = new UniVector(thirdTestScalar, fourthTestScalar); Assert.IsTrue(testVector.Equals((object)equivalentVector)); Assert.IsFalse(testVector.Equals((object)differingVector)); }
public void TestConstructor() { UniVector testVector = new UniVector(12.34f, 45.67f); Assert.AreEqual(0.0f, testVector.X.Fraction); Assert.AreEqual(12.34f, testVector.X.Offset); Assert.AreEqual(0.0f, testVector.Y.Fraction); Assert.AreEqual(45.67f, testVector.Y.Offset); }
public void TestInequalityOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector equivalentVector = new UniVector(firstTestScalar, secondTestScalar); UniVector differingVector = new UniVector(thirdTestScalar, fourthTestScalar); Assert.IsFalse(testVector != equivalentVector); Assert.IsTrue(testVector != differingVector); }
public void TestMultiplicationOperatorWithScalarOnLeftSide() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector result = new UniScalar(2.0f, 4.0f) * testVector; Assert.That(result.X.Fraction, Is.EqualTo(2.0f).Within(4).Ulps); Assert.That(result.X.Offset, Is.EqualTo(8.0f).Within(4).Ulps); Assert.That(result.Y.Fraction, Is.EqualTo(6.0f).Within(4).Ulps); Assert.That(result.Y.Offset, Is.EqualTo(16.0f).Within(4).Ulps); }
public void TestAdditionOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector addedVector = new UniVector(thirdTestScalar, fourthTestScalar); UniVector result = testVector + addedVector; Assert.AreEqual(1.1f, result.X.Fraction); Assert.AreEqual(2.2f, result.X.Offset); Assert.AreEqual(3.3f, result.Y.Fraction); Assert.AreEqual(4.4f, result.Y.Offset); }
public void TestMultiplicationOperatorWithScalarInRightSide() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector result = testVector * new UniScalar(4.0f, 2.0f); Assert.That(result.X.Fraction, Is.EqualTo(4.0f).Within(4).Ulps); Assert.That(result.X.Offset, Is.EqualTo(4.0f).Within(4).Ulps); Assert.That(result.Y.Fraction, Is.EqualTo(12.0f).Within(4).Ulps); Assert.That(result.Y.Offset, Is.EqualTo(8.0f).Within(4).Ulps); }
public void TestToOffset() { UniVector testVector = new UniVector( new UniScalar(1.2f, 3.4f), new UniScalar(5.6f, 7.8f) ); Assert.AreEqual( new Vector2(123.4f, 567.8f), testVector.ToOffset(new Vector2(100.0f, 100.0f)) ); }
public void TestSubtractionOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector subtractedVector = new UniVector(thirdTestScalar, fourthTestScalar); UniVector result = testVector - subtractedVector; Assert.AreEqual(0.9f, result.X.Fraction); Assert.AreEqual(1.8f, result.X.Offset); Assert.AreEqual(2.7f, result.Y.Fraction); Assert.AreEqual(3.6f, result.Y.Offset); }
public void TestMultiplicationOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector factorVector = new UniVector(thirdTestScalar, fourthTestScalar); UniVector result = testVector * factorVector; Assert.That(result.X.Fraction, Is.EqualTo(0.1f).Within(4).Ulps); Assert.That(result.X.Offset, Is.EqualTo(0.4f).Within(4).Ulps); Assert.That(result.Y.Fraction, Is.EqualTo(0.9f).Within(4).Ulps); Assert.That(result.Y.Offset, Is.EqualTo(1.6f).Within(4).Ulps); }
public void TestDivisionOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector divisorVector = new UniVector(thirdTestScalar, fourthTestScalar); UniVector result = testVector / divisorVector; Assert.That(result.X.Fraction, Is.EqualTo(10.0f).Within(4).Ulps); Assert.That(result.X.Offset, Is.EqualTo(10.0f).Within(4).Ulps); Assert.That(result.Y.Fraction, Is.EqualTo(10.0f).Within(4).Ulps); Assert.That(result.Y.Offset, Is.EqualTo(10.0f).Within(4).Ulps); }
public void TestSubtractionOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector subtractedVector = new UniVector(thirdTestScalar, fourthTestScalar); UniVector result = testVector - subtractedVector; Assert.AreEqual(0.9f, result.X.Fraction); Assert.AreEqual(1.8f, result.X.Offset); Assert.AreEqual(2.7f, result.Y.Fraction); Assert.AreEqual(3.6f, result.Y.Offset); }
public void TestAlmostEqualVectors() { UniVector testVector = new UniVector( new UniScalar(minusOneFloat, plusOneFloat), new UniScalar(plusOneFloat, minusOneFloat) ); UniVector exactVector = new UniVector( new UniScalar(exactFloat, exactFloat), new UniScalar(exactFloat, exactFloat) ); UniAssertHelper.AreAlmostEqual(testVector, exactVector, 1); }
public void TestToOffset() { UniVector testVector = new UniVector( new UniScalar(1.2f, 3.4f), new UniScalar(5.6f, 7.8f) ); Assert.AreEqual( new Vector2(123.4f, 567.8f), testVector.ToOffset(new Vector2(100.0f, 100.0f)) ); }
public void TestAdditionOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector addedVector = new UniVector(thirdTestScalar, fourthTestScalar); UniVector result = testVector + addedVector; Assert.AreEqual(1.1f, result.X.Fraction); Assert.AreEqual(2.2f, result.X.Offset); Assert.AreEqual(3.3f, result.Y.Fraction); Assert.AreEqual(4.4f, result.Y.Offset); }
public void TestAlmostEqualVectors() { UniVector testVector = new UniVector( new UniScalar(minusOneFloat, plusOneFloat), new UniScalar(plusOneFloat, minusOneFloat) ); UniVector exactVector = new UniVector( new UniScalar(exactFloat, exactFloat), new UniScalar(exactFloat, exactFloat) ); UniAssertHelper.AreAlmostEqual(testVector, exactVector, 1); }
public void TestMaxProperty() { UniVector minVector = new UniVector(firstTestScalar, secondTestScalar); UniVector maxVector = new UniVector(thirdTestScalar, fourthTestScalar); UniRectangle testRectangle = new UniRectangle(UniVector.Zero, minVector); testRectangle.Max = maxVector; Assert.AreEqual(UniVector.Zero, testRectangle.Min); Assert.AreEqual(UniVector.Zero, testRectangle.Location); UniAssertHelper.AreAlmostEqual(maxVector, testRectangle.Max, 4); UniAssertHelper.AreAlmostEqual(maxVector, testRectangle.Size, 4); }
public void TestMinProperty() { UniVector minVector = new UniVector(firstTestScalar, secondTestScalar); UniVector maxVector = new UniVector(thirdTestScalar, fourthTestScalar); UniRectangle testRectangle = new UniRectangle(UniVector.Zero, maxVector); // This doesn't move the rectangle, it resizes it! testRectangle.Min = minVector; Assert.AreEqual(minVector, testRectangle.Min); Assert.AreEqual(minVector, testRectangle.Location); UniAssertHelper.AreAlmostEqual(maxVector, testRectangle.Max, 4); UniAssertHelper.AreAlmostEqual(maxVector - minVector, testRectangle.Size, 4); }
public void TestVectorConstructor() { UniVector location = new UniVector(firstTestScalar, secondTestScalar); UniVector size = new UniVector(thirdTestScalar, fourthTestScalar); UniRectangle testRectangle = new UniRectangle(location, size); Assert.AreEqual(1.0f, testRectangle.Location.X.Fraction); Assert.AreEqual(2.0f, testRectangle.Location.X.Offset); Assert.AreEqual(3.0f, testRectangle.Location.Y.Fraction); Assert.AreEqual(4.0f, testRectangle.Location.Y.Offset); Assert.AreEqual(0.1f, testRectangle.Size.X.Fraction); Assert.AreEqual(0.2f, testRectangle.Size.X.Offset); Assert.AreEqual(0.3f, testRectangle.Size.Y.Fraction); Assert.AreEqual(0.4f, testRectangle.Size.Y.Offset); }
public void TestThrowOnAlmostEqualVectorsWithYDifference() { UniVector testVector = new UniVector( new UniScalar(minusOneFloat, plusOneFloat), new UniScalar(plusTwoFloat, minusTwoFloat) ); UniVector exactVector = new UniVector( new UniScalar(exactFloat, exactFloat), new UniScalar(exactFloat, exactFloat) ); Assert.Throws <AssertionException>( delegate() { UniAssertHelper.AreAlmostEqual(exactVector, testVector, 1); } ); }
public void TestVectorConstructor() { UniVector location = new UniVector(firstTestScalar, secondTestScalar); UniVector size = new UniVector(thirdTestScalar, fourthTestScalar); UniRectangle testRectangle = new UniRectangle(location, size); Assert.AreEqual(1.0f, testRectangle.Location.X.Fraction); Assert.AreEqual(2.0f, testRectangle.Location.X.Offset); Assert.AreEqual(3.0f, testRectangle.Location.Y.Fraction); Assert.AreEqual(4.0f, testRectangle.Location.Y.Offset); Assert.AreEqual(0.1f, testRectangle.Size.X.Fraction); Assert.AreEqual(0.2f, testRectangle.Size.X.Offset); Assert.AreEqual(0.3f, testRectangle.Size.Y.Fraction); Assert.AreEqual(0.4f, testRectangle.Size.Y.Offset); }
public void TestEqualsWithNullReference() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); Assert.IsFalse(testVector.Equals(null)); }
public void TestEqualsWithDifferentType() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); Assert.IsFalse(testVector.Equals(DateTime.MinValue)); }
/// <summary>Ensures that two unified vectors are nearly equal to each other</summary> /// <param name="expected">Expected unified vector</param> /// <param name="actual">Actual unified vector</param> /// <param name="deltaUlps"> /// Allowed deviation in representable floating point values for each of the /// unified vector's fields /// </param> public static void AreAlmostEqual(UniVector expected, UniVector actual, int deltaUlps) { if(!areAlmostEqual(expected, actual, deltaUlps)) { Assert.AreEqual(expected, actual); } }
/// <summary>Determines whether two unified vectors are nearly equal</summary> /// <param name="left">Unified vector to compare on the left side</param> /// <param name="right">Unified vector to compare on the right side</param> /// <param name="deltaUlps"> /// Allowed deviation in representable floating point values for each of the /// unified vector's fields /// </param> /// <returns>True if the provided unified vectors are nearly equal</returns> private static bool areAlmostEqual(UniVector left, UniVector right, int deltaUlps) { return areAlmostEqual(left.X, right.X, deltaUlps) && areAlmostEqual(left.Y, right.Y, deltaUlps); }
public void TestMinProperty() { UniVector minVector = new UniVector(firstTestScalar, secondTestScalar); UniVector maxVector = new UniVector(thirdTestScalar, fourthTestScalar); UniRectangle testRectangle = new UniRectangle(UniVector.Zero, maxVector); // This doesn't move the rectangle, it resizes it! testRectangle.Min = minVector; Assert.AreEqual(minVector, testRectangle.Min); Assert.AreEqual(minVector, testRectangle.Location); UniAssertHelper.AreAlmostEqual(maxVector, testRectangle.Max, 4); UniAssertHelper.AreAlmostEqual(maxVector - minVector, testRectangle.Size, 4); }
public void TestGetHashCode() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector equivalentVector = new UniVector(firstTestScalar, secondTestScalar); Assert.AreEqual(testVector.GetHashCode(), equivalentVector.GetHashCode()); }
/// <summary>Determines whether two unified vectors are nearly equal</summary> /// <param name="left">Unified vector to compare on the left side</param> /// <param name="right">Unified vector to compare on the right side</param> /// <param name="deltaUlps"> /// Allowed deviation in representable floating point values for each of the /// unified vector's fields /// </param> /// <returns>True if the provided unified vectors are nearly equal</returns> private static bool areAlmostEqual(UniVector left, UniVector right, int deltaUlps) { return (areAlmostEqual(left.X, right.X, deltaUlps) && areAlmostEqual(left.Y, right.Y, deltaUlps)); }
/// <summary>Initializes a new rectangle from a location and a size</summary> /// <param name="location">Location of the rectangle's upper left corner</param> /// <param name="size">Size of the area covered by the rectangle</param> public UniRectangle(UniVector location, UniVector size) { this.Location = location; this.Size = size; }
/// <summary>Initializes a new rectangle from a location and a size</summary> /// <param name="location">Location of the rectangle's upper left corner</param> /// <param name="size">Size of the area covered by the rectangle</param> public UniRectangle(UniVector location, UniVector size) { this.Location = location; this.Size = size; }
public void TestMultiplicationOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector factorVector = new UniVector(thirdTestScalar, fourthTestScalar); UniVector result = testVector * factorVector; Assert.That(result.X.Fraction, Is.EqualTo(0.1f).Within(4).Ulps); Assert.That(result.X.Offset, Is.EqualTo(0.4f).Within(4).Ulps); Assert.That(result.Y.Fraction, Is.EqualTo(0.9f).Within(4).Ulps); Assert.That(result.Y.Offset, Is.EqualTo(1.6f).Within(4).Ulps); }
public void TestMultiplicationOperatorWithScalarOnLeftSide() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector result = new UniScalar(2.0f, 4.0f) * testVector; Assert.That(result.X.Fraction, Is.EqualTo(2.0f).Within(4).Ulps); Assert.That(result.X.Offset, Is.EqualTo(8.0f).Within(4).Ulps); Assert.That(result.Y.Fraction, Is.EqualTo(6.0f).Within(4).Ulps); Assert.That(result.Y.Offset, Is.EqualTo(16.0f).Within(4).Ulps); }
public void TestMultiplicationOperatorWithScalarInRightSide() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector result = testVector * new UniScalar(4.0f, 2.0f); Assert.That(result.X.Fraction, Is.EqualTo(4.0f).Within(4).Ulps); Assert.That(result.X.Offset, Is.EqualTo(4.0f).Within(4).Ulps); Assert.That(result.Y.Fraction, Is.EqualTo(12.0f).Within(4).Ulps); Assert.That(result.Y.Offset, Is.EqualTo(8.0f).Within(4).Ulps); }
public void TestDivisionOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector divisorVector = new UniVector(thirdTestScalar, fourthTestScalar); UniVector result = testVector / divisorVector; Assert.That(result.X.Fraction, Is.EqualTo(10.0f).Within(4).Ulps); Assert.That(result.X.Offset, Is.EqualTo(10.0f).Within(4).Ulps); Assert.That(result.Y.Fraction, Is.EqualTo(10.0f).Within(4).Ulps); Assert.That(result.Y.Offset, Is.EqualTo(10.0f).Within(4).Ulps); }
public void TestInequalityOperator() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector equivalentVector = new UniVector(firstTestScalar, secondTestScalar); UniVector differingVector = new UniVector(thirdTestScalar, fourthTestScalar); Assert.IsFalse(testVector != equivalentVector); Assert.IsTrue(testVector != differingVector); }
public void TestThrowOnAlmostEqualVectorsWithXDifference() { UniVector testVector = new UniVector( new UniScalar(minusTwoFloat, plusTwoFloat), new UniScalar(plusOneFloat, minusOneFloat) ); UniVector exactVector = new UniVector( new UniScalar(exactFloat, exactFloat), new UniScalar(exactFloat, exactFloat) ); Assert.Throws<AssertionException>( delegate() { UniAssertHelper.AreAlmostEqual(exactVector, testVector, 1); } ); }
/// <summary>Checks whether another instance is equal to this instance</summary> /// <param name="other">Other instance to compare to this instance</param> /// <returns>True if the other instance is equal to this instance</returns> public bool Equals(UniVector other) { // For a struct, 'other' cannot be null return((this.X == other.X) && (this.Y == other.Y)); }
public void TestMaxProperty() { UniVector minVector = new UniVector(firstTestScalar, secondTestScalar); UniVector maxVector = new UniVector(thirdTestScalar, fourthTestScalar); UniRectangle testRectangle = new UniRectangle(UniVector.Zero, minVector); testRectangle.Max = maxVector; Assert.AreEqual(UniVector.Zero, testRectangle.Min); Assert.AreEqual(UniVector.Zero, testRectangle.Location); UniAssertHelper.AreAlmostEqual(maxVector, testRectangle.Max, 4); UniAssertHelper.AreAlmostEqual(maxVector, testRectangle.Size, 4); }
public void TestEqualsWithDifferentType() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); Assert.IsFalse(testVector.Equals(DateTime.MinValue)); }
public void TestEqualsWithDowncast() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); UniVector equivalentVector = new UniVector(firstTestScalar, secondTestScalar); UniVector differingVector = new UniVector(thirdTestScalar, fourthTestScalar); Assert.IsTrue(testVector.Equals((object)equivalentVector)); Assert.IsFalse(testVector.Equals((object)differingVector)); }
/// <summary>Checks whether another instance is equal to this instance</summary> /// <param name="other">Other instance to compare to this instance</param> /// <returns>True if the other instance is equal to this instance</returns> public bool Equals(UniVector other) { // For a struct, 'other' cannot be null return (this.X == other.X) && (this.Y == other.Y); }
public void TestEqualsWithNullReference() { UniVector testVector = new UniVector(firstTestScalar, secondTestScalar); Assert.IsFalse(testVector.Equals(null)); }