SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.8 KiB

4 years ago
  1. # FloatEqualityComparer
  2. Use this class to compare two float values for equality with [NUnit](http://www.nunit.org/) constraints. Use `FloatEqualityComparer.Instance` comparer to have the default error value set to 0.0001f. For any other error, use the [one argument constructor](#constructors) to create a comparer.
  3. ## Static Properties
  4. | Syntax | Description |
  5. | ---------- | ------------------------------------------------------------ |
  6. | `Instance` | A singleton instance of the comparer with a default error value set to 0.0001f. |
  7. ## Constructors
  8. | Syntax | Description |
  9. | ------------------------------------------- | ------------------------------------------------------------ |
  10. | `FloatEqualityComparer(float allowedError)` | Creates an instance of the comparer with a custom error value. |
  11. ## Public methods
  12. | Syntax | Description |
  13. | -------------------------------------------- | ------------------------------------------------------------ |
  14. | `bool Equals(float expected, float actual);` | Compares the `actual` and `expected` float values for equality using `Utils.AreFloatsEqual`. |
  15. ## Example
  16. ```c#
  17. [TestFixture]
  18. public class FloatsTest
  19. {
  20. [Test]
  21. public void VerifyThat_TwoFloatsAreEqual()
  22. {
  23. var comparer = new FloatEqualityComparer(10e-6f);
  24. var actual = -0.00009f;
  25. var expected = 0.00009f;
  26. Assert.That(actual, Is.EqualTo(expected).Using(comparer));
  27. // Default relative error 0.0001f
  28. actual = 10e-8f;
  29. expected = 0f;
  30. Assert.That(actual, Is.EqualTo(expected).Using(FloatEqualityComparer.Instance));
  31. }
  32. }
  33. ```