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.

40 lines
2.4 KiB

4 years ago
  1. # Test Utils
  2. This contains test utility functions for float value comparison and creating primitives.
  3. ## Static Methods
  4. | Syntax | Description |
  5. | ------------------------------------------------------------ | ------------------------------------------------------------ |
  6. | `bool AreFloatsEqual(float expected, float actual, float allowedRelativeError)` | Relative epsilon comparison of two float values for equality. `allowedRelativeError` is the relative error to be used in relative epsilon comparison. The relative error is the absolute error divided by the magnitude of the exact value. Returns `true` if the actual value is equivalent to the expected value. |
  7. | `bool AreFloatsEqualAbsoluteError(float expected, float actual, float allowedAbsoluteError)` | Compares two floating point numbers for equality under the given absolute tolerance. `allowedAbsoluteError` is the permitted error tolerance. Returns `true` if the actual value is equivalent to the expected value under the given tolerance. |
  8. | `GameObject CreatePrimitive( type)` | Creates a [GameObject](https://docs.unity3d.com/ScriptReference/GameObject.html) with a primitive [MeshRenderer](https://docs.unity3d.com/ScriptReference/MeshRenderer.html). This is an analogue to the [GameObject.CreatePrimitive](https://docs.unity3d.com/ScriptReference/GameObject.CreatePrimitive.html), but creates a primitive `MeshRenderer` with a fast [Shader](https://docs.unity3d.com/ScriptReference/Shader.html) instead of the default built-in `Shader`, optimized for testing performance. `type` is the [primitive type](https://docs.unity3d.com/ScriptReference/PrimitiveType.html) of the required `GameObject`. Returns a `GameObject` with primitive `MeshRenderer` and [Collider](https://docs.unity3d.com/ScriptReference/Collider.html). |
  9. ## Example
  10. ```c#
  11. [TestFixture]
  12. class UtilsTests
  13. {
  14. [Test]
  15. public void ChechThat_FloatsAreEqual()
  16. {
  17. float expected = 10e-8f;
  18. float actual = 0f;
  19. float allowedRelativeError = 10e-6f;
  20. Assert.That(Utils.AreFloatsEqual(expected, actual, allowedRelativeError), Is.True);
  21. }
  22. [Test]
  23. public void ChechThat_FloatsAreAbsoluteEqual()
  24. {
  25. float expected = 0f;
  26. float actual = 10e-6f;
  27. float error = 10e-5f;
  28. Assert.That(Utils.AreFloatsEqualAbsoluteError(expected, actual, error), Is.True);
  29. }
  30. }
  31. ```