test_physics_material.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**************************************************************************/
  2. /* test_physics_material.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TEST_PHYSICS_MATERIAL_H
  31. #define TEST_PHYSICS_MATERIAL_H
  32. #include "scene/resources/physics_material.h"
  33. #include "tests/test_macros.h"
  34. namespace TestPhysics_material {
  35. TEST_CASE("[Physics_material] Defaults") {
  36. Ref<PhysicsMaterial> physics_material;
  37. physics_material.instantiate();
  38. CHECK(physics_material->get_friction() == 1.);
  39. CHECK(physics_material->is_rough() == false);
  40. CHECK(physics_material->get_bounce() == 0.);
  41. CHECK(physics_material->is_absorbent() == false);
  42. }
  43. TEST_CASE("[Physics_material] Friction") {
  44. Ref<PhysicsMaterial> physics_material;
  45. physics_material.instantiate();
  46. real_t friction = 0.314;
  47. physics_material->set_friction(friction);
  48. CHECK(physics_material->get_friction() == friction);
  49. }
  50. TEST_CASE("[Physics_material] Rough") {
  51. Ref<PhysicsMaterial> physics_material;
  52. physics_material.instantiate();
  53. bool rough = true;
  54. physics_material->set_rough(rough);
  55. CHECK(physics_material->is_rough() == rough);
  56. real_t friction = 0.314;
  57. physics_material->set_friction(friction);
  58. CHECK(physics_material->computed_friction() == -friction);
  59. rough = false;
  60. physics_material->set_rough(rough);
  61. CHECK(physics_material->is_rough() == rough);
  62. CHECK(physics_material->computed_friction() == friction);
  63. }
  64. TEST_CASE("[Physics_material] Bounce") {
  65. Ref<PhysicsMaterial> physics_material;
  66. physics_material.instantiate();
  67. real_t bounce = 0.271;
  68. physics_material->set_bounce(bounce);
  69. CHECK(physics_material->get_bounce() == bounce);
  70. }
  71. TEST_CASE("[Physics_material] Absorbent") {
  72. Ref<PhysicsMaterial> physics_material;
  73. physics_material.instantiate();
  74. bool absorbent = true;
  75. physics_material->set_absorbent(absorbent);
  76. CHECK(physics_material->is_absorbent() == absorbent);
  77. real_t bounce = 0.271;
  78. physics_material->set_bounce(bounce);
  79. CHECK(physics_material->computed_bounce() == -bounce);
  80. absorbent = false;
  81. physics_material->set_absorbent(absorbent);
  82. CHECK(physics_material->is_absorbent() == absorbent);
  83. CHECK(physics_material->computed_bounce() == bounce);
  84. }
  85. } // namespace TestPhysics_material
  86. #endif // TEST_PHYSICS_MATERIAL_H